Open darrelmiller opened 2 years ago
@JamesNK and I talked schema generation today and he shared some helpful insights on this domain. Notes from the discussion below:
JsonSerializerOptions.PropertyNamingPolicy
to indicate whether property keys should be camel-cased or pascal-cased or insert-whatever-modification-here. The generator will need to be able to introspect these settings and respect them when generating property keys in the OpenAPI schema.Todo
type that would typically serialized as an object can be overridden to serialize to just a string. The generator will need to respect these overrides.We also discussed some features that might be helpful for the work that James is doing around gRPC + REST APIs + OpenAPI, particularly being able to provide global overrides for how different JSON schema types (primitives, objects, arrays, etc.) should have their serializations configured.
Let me know if I missed anything key, @JamesNK...
In the context of OpenAPI, schemas exist outside the scope of a particular operation. The same Type/Schema can be used in different operations. As we reason through this, we should consider that the schema generation will need to happen independent of the operation model.
Another key thing here is schemas aren't isolated. Schemas are reused and they reference each other. OpenApiSchema SchemaGenerator.Generate(Type type)
isn't sufficient.
For this to work I imagine:
System.Type
instances an operation will use (in and out).Dictionary<Type, OpenApiSchema>
.components.schemas
a standard place?) and then goes through the operations and adds references to the schemas in components.schemas
based on the type.Our plans to support OpenAPI 3.1 currently involve changing our OpenAPISchema object to use a third-party JSONSchema library. We should not do this work until we have added OpenAPI 3.1 support or we will have to do the work twice.
Hello, I am at the stage of selecting the technology to work with OpenAPI standard required for my task. I need functionality to generate schemas. If possible, please advise how long this issue will be on hold?
I think we can close this issue out given support. for generating schemas from type definitions has been added in System.Text.Json.
@magarich228 There is a new API in .NET 9 to support this (JsonSchemaExporter
). Alternatively, you can take a look at the Microsoft.AspNetCore.OpenApi
package v9 to see if that meets your needs. It supports generating OpenAPI documents for API implementations.
Can we create a mechanism to generate Schemas from C# classes?
https://github.com/dotnet/aspnetcore/issues/41246