-
Notifications
You must be signed in to change notification settings - Fork 57
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
NJsonSchema generates discriminator syntax which is not AsyncAPI compatible #117
Comments
More frustrations with the different schema formats 😞 @RicoSuter it seems like we might need to have a specific format for AsyncAPI Thanks for your help. |
Yeah, I noticed the null issues too, where the generated schema has a lot of null values with the AsyncAPI UI doesn't like. Maybe the best solution to this is to create a fork of NJsonSchema specifically for AsyncAPI? That is unless @RicoSuter thinks these customisations should be in NJsonSchema itself. That way you can take advantage of development in that project and curate how that merges into the AsyncApi variant? Either that or NJsonSchema's serialiser would need to be completely customisable (if it isn't already, my knowledge is limited here.) I think this project (Saunter) has huge potential, I'm a big fan of Swashbuckle and an AsyncAPI equivalent is something which I think is hugely valuable. Let's see what Rico says I guess. |
Can someone clarify what the correct null handling should be? Is it the same as with OpenAPI or JSON Schema or again completely different? I'm fine adding the AsyncAPI enum, had to do this for OpenAPI/Swagger as well because it's not just a simple rename of a property but the schema generator needs to generate "completely different" schemas... |
Thanks for replying @RicoSuter :) In this case the issue is how to support polymorphism.
For representing nullables. properties:
foo:
type: [string, 'null'] For references to other schema: properties:
foo:
oneOf:
- type: 'null'
- '$ref': '#/components/schemas/foo' Once AysncAPI supports later versions of JsonSchema, we can use properties:
foo:
type: [ object, 'null' ]
'$ref': '#/components/schemas/foo' It seems like the discriminator issue alone is enough to force us to implement a different |
So we would add AsyncApi2 (and later AsyncApi3) or just AsyncApi as new SchemaType? |
That seems like the most appropriate option :) Alternative might be to have NJsonSchema allow custom SchemaTypes somehow? Would you like me to work on this and submit a PR to NJsonSchema? |
problem is that njs needs specific code based on the schema anyway, no? Here for example a different inheritance generation.. another option is that you inherit from JsonSchemaGenerator and tweak the behavior with overrides.. that would be nicer in general (ie get rid of the schematype) |
According to the spec, AsyncAPI should have a discriminator as a string,
https://www.asyncapi.com/docs/specifications/v2.1.0#schemaObject
However, NJsonSchema generates an object instead with a propertyName and mappings fields, which is valid according to the OpenAPI spec
https://github.com/RicoSuter/NJsonSchema/blob/288eb13e931562264ed9ddd12a83741c67a1ddc4/src/NJsonSchema/OpenApiDiscriminator.cs
https://swagger.io/specification/#discriminator-object
This means that Saunter generates invalid AsyncAPI code.
If you call
iPetSchema.ToJson()
one line145
in the following file, you'll see the generated JSON and how it doesn't match the requirements:https://github.com/tehmantra/saunter/blob/main/test/Saunter.Tests/Generation/SchemaGeneration/SchemaGenerationTests.cs
I've reverted to 0.4.0 for now as it's the last version of Saunter with working discriminator support.
I can't see an obvious way to adjust the generated schema in NJsonSchema, maybe this is something @RicoSuter can help with?
Let me know if there's any more information I can provide.
The text was updated successfully, but these errors were encountered: