Skip to content
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

Add support for CreateSchemaReferenceId option #56753

Merged
merged 3 commits into from
Jul 13, 2024
Merged

Conversation

captainsafia
Copy link
Member

Closes #56305.

This PR adds support for a CreateSchemaReferenceId property in the OpenApiOptions to support customizing how reference IDs are generated for schemas assocaited with a given type. Because of the behavior of the reference ID implementation, this function also serves as a mechanism for being able to determine whther or not a schema should be inline or referenced:

  • Providing a CreateSchemaReferenceId delegate that returns nullfor a given type will mean that schemas associated with that type are always inline
  • Providing a CreateSchemaReferenceId delegate that returns a value for a given type will mean that schemas assocaited with that type will always be referenced

Changes in this PR include:

  • Adding CreateSchemaReferenceId property to options object and CreateDefaultSchemaReferenceId static to provide users with access to the default implementation
  • Updates to invoke CreateSchemaReferenceId from options in all codepaths where it is currently relevant
  • New tests to cover reference ID behavior for scenarios we care about

@captainsafia captainsafia requested a review from a team as a code owner July 11, 2024 23:49
@dotnet-issue-labeler dotnet-issue-labeler bot added the area-web-frameworks *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels label Jul 11, 2024
Co-authored-by: Martin Costello <martin@martincostello.com>
schema.ApplyPrimitiveTypesAndFormats(context);
schema.ApplySchemaReferenceId(context);
schema.ApplyPolymorphismOptions(context);
var createSchemaReferenceId = optionsMonitor.Get(documentName).CreateSchemaReferenceId;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use _openApiOptions?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_openApiOptions is an instance field so we can't use it in the initializer for _confguration. I could switch to standard constructors instead of primary constructors and initialize everything there but.... 😅 🤪

@captainsafia captainsafia merged commit 90a622d into main Jul 13, 2024
26 checks passed
@captainsafia captainsafia deleted the safia/schema-id-func branch July 13, 2024 05:12
@dotnet-policy-service dotnet-policy-service bot added this to the 9.0-preview7 milestone Jul 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-web-frameworks *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support options for setting callback used to generated reference IDs in OpenAPI
4 participants