Swashbuckle.AspNetCore icon indicating copy to clipboard operation
Swashbuckle.AspNetCore copied to clipboard

Identify long-term strategy for JSON schema generation

Open captainsafia opened this issue 2 years ago • 1 comments

In .NET 7, we added support for a new Microsoft.AspNetCore.OpenApi package that is designed to work with minimal API applications and provide constructs that allow users to directly modify the OpenApiOperation associated with their endpoints.

At the moment, the package integrates into Swashbuckle using an ad-hoc merge and replace strategy wherein:

  • If an OpenApiOperation exists in the endpoint metadata, it is used instead of using the one generated by SwaggerGenerator and
  • Swashbuckle's schema generator is leveraged to generate the OpenApiSchema since Microsoft.AspNetCore.OpenApi doesn't support full reflection schema generation to put

In the future, it would be great to unify this ad-hoc strategy, especially now that OpenAPI v3.1's OpenAPI schema exactly matches JSON schema (ref).

Some possibilities include:

  • Implementing schema generation support lower in the stack at the Microsoft.OpenApi layer (see https://github.com/microsoft/OpenAPI.NET/issues/836)
  • Leverage an established JSON schema generation library (like json-everything) to standardize on schema generation throughout the stack
  • Leverage System.Text.Json's new TypeInfoResolver API (ref) to standardize on schema generation

With the long-term goal of:

  • Removing the merge and replace strategy/hack in Swashbuckle
  • Allowing users to modify schemas in their WithOpenApi invocations on route handler endpoints

cc: @domaindrivendev @darrelmiller

captainsafia avatar Oct 20 '22 22:10 captainsafia

This issue is stale because it has been open for 60 days with no activity. It will be automatically closed in 14 days if no further updates are made.

github-actions[bot] avatar Apr 15 '24 02:04 github-actions[bot]