-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Provide API to allow JSON converters/types to describe their associated JSON schema #105769
Comments
Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis |
@captainsafia, as in we need to address this in .NET 9? |
Ah, should've been clearer about this. Not a blocker for .NET 9, but definitely would be good to slot in for .NET 10. |
There is no |
The problem with the proposed API is JSON schemas exist in the context of a document. For example, schemas in a document reference each other via These things happen beyond the scope of an individual
I think customization must happen before the document is generated and work at the Using Swashbuckle's contract resolver, I can instruct it what the schema output for a type should be at the The |
The current implementation does not support |
Yes, what $ref and $def are needed. They're the idiomatic way to organize schemas in JSON. Without those features, a large amount of work is required to make good output from the type. As evidence of this, see everything that ASP.NET Core needs to do to post-process the output of the mapper to make it usable. The mapper should be the one doing the work to place schemas in definitions and reference them. Some post-processing in ASP.NET Core will still be required to modify the JSON schema syntax to be compatible with OpenAPI, but it will be much less, and simpler, than what is currently done. As soon as you start adding support for these features, you realize that an API to customize schemas individually doesn't work. |
For context, the reason why such an API wasn't added in .NET 9 is due to the lack of a built-in
|
I try to generate a Json schema for some types, which contain simple value objects generated with Vogen. This makes me run into the issue described here. It would be great to have an interface for describing my schema. For the simple use-case it might be sufficient to override Another issue related to this is, that {
"type": "object",
"properties": {
"propertyWithCustomConverter": true
}
} I think this violates the JsonSchema specification, which states
I'd prefer to receive an Does it make sense to raise an issue for that? Or is it too late anyway, with .Net 9 just being released? |
|
The value of "properties" is an object in your example. It's just that the schemas of individual properties can boolean per the spec. |
Ah. True. Sorry, I didn't get that. Besides that, I'm not sure if it is a very helpful property description. |
@Peter-B- if you think the spec needs to be clarified, please feel free to open an issue in the JSON Schema spec repo. |
The current implementation of the
JsonSchemaExporter
generates schemas for types based on its on semantics. There's currently not strategy for types/converters to advertise their associated JSON schemas.This gap has presented a blocker for a couple of scenarios in ASP.NET Core's OpenAPI support around JSON schema.
true
schema.While both System.Text.Json and ASP.NET Core expose APIs for modifying schemas at different layers of the stack, both approaches are reactive and allow mutating the schema that is generated instead of proactively dictating the schema that should be set.
Solutions that have been discussed in the past includ exposing a new
IJsonSchemaResolver
interface for type owners to implement:Or alternatively including a new virtual method on the JsonConverter to define associated schemas:
cc: @JamesNK @eiriktsarpalis
The text was updated successfully, but these errors were encountered: