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
How to serialize generated schemas into JSON Schemas #149
Comments
Changing the class MyClass
{
public MyClass(string myString)
{
MyString = myString;
}
// changed to public setter
public string MyString { get; set; }
} Output: {
"type": "object",
"properties": {
"MyString": {
"type": "string"
}
}
} I'd still expect it to have the So now I kinda assume that this is about the limitations of |
It took me a bit to see it, but the generator uses read/write properties only. This matches current support of serialization. To get the For an example of this, you can see the tests. [erases example of exactly what you just commented] I designed it this way because the intent is that you'd generate the schemas from models that were intended as DTOs. Generally DTOs are read/write, not immutable. DTOs are then mapped to domain objects, which may or may not be immutable depending on your specific application requirements. You're right on track with serializer support. |
I'm still working out how this should work, so I'm open to suggestions. Currently the attributes only work on properties, not class definitions, so I can't put a Still, as mentioned in the docs, this is designed to be a starting point for creating schemas. It's not intended as a direct-to-production solution. The JSON Schema team (of which I'm a part) has had many discussions on the viability of this, and we're not sufficiently confident in anyone's ability to generate a schema that is 100% ready for production use. |
Environment
JsonSchema.Net 1.10.7
,JsonSchema.Net.Generation 1.8.0
I've read through the docs, and I couldn't find an example on how to serialize the generated
JsonSchema
object into a JSON Schema string. Looking at the test I saw that usingJsonSerializer.Serialize()
seemed to be the way to go about it. But the resulting JSON isn't a schema at all. Maybe I'm missing something, or that using attributes is mandatory, but reading the docs I thought that it would actually make a schema with properties for me without using attributes (the docs do say "maybe", not sure what that then means).Example:
output:
I was expecting to get something like:
Is there a way to actually output a serialized JSON Schema from the
JsonSchema
class or am I missing something here?The text was updated successfully, but these errors were encountered: