corvus-dotnet / Corvus.JsonSchema

Support for Json Schema validation and entity generation
Apache License 2.0
121 stars 9 forks source link

Using AsyncAPI as source? #498

Open challe opened 3 days ago

challe commented 3 days ago

We're moving from specifying our schemas in individual JSON files to storing multiple schemas inside a yaml file following the AsyncAPI specification.

But I would still like to use Corvus.JsonSchema to generate the models (since nothing comes even close to being as awesome 😄).

Is there a good way of doing this? My initial idea was to parse the yaml file to extract a schema, convert it to JSON, and then pass it to Corvus.JsonSchema.

Any other ideas?

Of course it would be awesome to be able to just pass an asyncapi spec file as input and it would generate the models for me but I guess that's not built in as of now.

Edit: I managed to hack something together by using yq:

yq -o=json .components.schemas.my_schema < asyncapi.yaml > my_schema.json && dotnet tool run generatejsonschematypes -- my_schema.json 
mwadams commented 3 days ago

That is exactly what I was going to suggest as a "quick workaround".

mwadams commented 3 days ago

However, YAML support in the generator would be good.

And then support for direct generation from https://www.asyncapi.com/docs/reference/specification/v3.0.0.

As with OpenAPI, we'd want to do a walk through the whole doc to gather the inline and referenced schema, rather than making you do it.

mwadams commented 3 days ago

Although this is not directly relevant to your case (as we would already have loaded and parsed the document before getting to the schema!) I've opened #499 to provide YAML support.

mwadams commented 3 days ago

I will leave this open to track supporting AsyncAPI documents directly.