Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generating schema with an Array property allowing multiple types of an interface #304

Open
HolyOne opened this issue Oct 23, 2022 · 0 comments

Comments

@HolyOne
Copy link

HolyOne commented Oct 23, 2022

Hello, I am strugling to programaticly generate schema for my configuration and I wondered if there is a practicle way I am missing.

My Example Config file is this

{
"$schema": "config-schema.json" ,
"BackupDir": "c:\backup\",
"CompressionLevel": 2,
"Items": [
{"Type": "File" , "Path" : "c:\SomeDirectory", "ArchiveSize":128 },
{"Type": "File" , "Path" : "c:\SomeDirectory2", "ArchiveSize":128 },
{"Type": "MySQL" , "Server" : "localhost", "DB":"mydata" },
{"Type": "MySQL" , "Server" : "localhost", "DB":"mydb" },
{"Type": "MSSQL" , "Server" : "localhost", "DB":"mymsdb", "Username":"sa", "Password":"...." }
]
}

As you see In c#, I have an Items property of IEnumerable which only requires "Type" Parameter.
But It may also have other properties because Items can contain any class inherited from IBackupInfo.

public interface IBackupInfo
{
    string Type { get;   }
}  

I read the Items, cast them to the appropriate class using the common "Type" property.

How can I programaticly generate the schema file for this, (which is aware of all the class types i provide) ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant