[feature]: JsonSchema.Net.Generation for openapi schema generation?
Is your feature request related to a problem? Please describe.
Currently, the schema generation is limited to what is implemented,
Issues like https://github.com/buehler/dotnet-operator-sdk/issues/741, https://github.com/buehler/dotnet-operator-sdk/issues/396, https://github.com/buehler/dotnet-operator-sdk/issues/351 could possibly benefit from this
Describe the solution you would like
It would be nice to team up with a schema generator library and outsource those capabilities to generate the OpenApiV3 spec.
JsonSchema.Net offers JsonSchema with customizable keywords and validation on JsonNodes. JsonSchema.Net.Generation can generate schemas from C# classes with reflection (for use in KubeOps.Cli?)
Additional Context
No response
Hey @SGStino
That's a good idea! As long as there are possibilities to add the special "x-kubernetes" attributes, we should be good to go. According to the docs of Kubernetes, they use openapi v3 and as such, we could use a lib for that.
The library supports adding custom vocabulary, so the x-kubernetes should be implemented as those.
I'll see if I can bash something together as reference so you can see how to fit it in the operator?
That would be amazing! Thank you :-)
https://github.com/SGStino/JsonSchemaTest
If you have any real-life examples of entities we can test against? Just to see what comes out, then we can figure out if anything works different or not at all.
Hey @SGStino Thanks :-)
Sadly - no. Since I made this SDK, I've only written one operator (weird, I know).
But maybe other contributors can provide some real world examples.
New stuff that might change the approach:
Maps .NET types to JSON schema objects using contract metadata from JsonTypeInfo instances.
https://learn.microsoft.com/en-us/dotnet/api/system.text.json.schema.jsonschemaexporter?view=net-9.0
@buehler @SGStino
That might explain the demise of swashbuckle in dotnet 9. No more reflection, only source generated JsonTypeInfo instances. although i don't immediatly see how the x-kubernetes- ... things might fit into the type info.
Depending on how extendable the generator is in it's early days it could be easier to use json-everything. As it should in theory come up with the same schema, but with the extensibility for the x-... attrubtes?s
The JSON Schema Exporter stuff is consumed by https://github.com/microsoft/OpenAPI.NET and https://www.nuget.org/packages/Microsoft.AspNetCore.OpenApi to do the full picture. My belief so far is there are ample extension points to do the whole stack.
For instance, ASP.NET allows schema modification by various attributes and stuff. And schema document transformation, etc. So you can pretty much make it look how you want.
The ASP.NET Core version of the usage build schema off of the API Explorer API, which exports Action/Type information, etc. Basically tying a few different libraries together.