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

Scrub extension properties in OpenAPI document during serialization #56688

Merged
merged 1 commit into from
Jul 9, 2024

Conversation

captainsafia
Copy link
Member

Closes #56541.

The bug reported above occurs because x-schema-id metadata is scrubbed from the in-memory model before serialization which causes the comparison to fail between the same schema with and without an ID scrubbed. To fix this, we change the implementation to avoid scrubbing data from the in-memory model and instead rely on scrubbing at the serialization layer so the in-memory model is always consistent.

Changes in this PR consist of:

  • A new IOpenApiAny implementation that implements a no-op Write method to support representing values that don't serialize themselves to disk.
  • An implement of OpenApiJsonWriter that implements a custom WritePropertyName to avoid serializing keys associated with in-memory attributes (x-schema-id and x-aspnetcore-id) from the outgoing document.

In the long-term, I'd hope that this implementation will be further simplified by the new APIs that I am proposing in Microsoft.OpenApi to support a truly in-memory metadata collection in the OpenAPI object model (see microsoft/OpenAPI.NET#1719). This should allow us to use the metadata collection for book-keeping without having to worry about omitting them from serialization ourselves.

@captainsafia captainsafia added area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates feature-openapi area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc labels Jul 9, 2024
@captainsafia captainsafia requested a review from a team as a code owner July 9, 2024 15:17
// }

// Both list types should point to the same reference ID
Assert.Equal("ArrayOfTodo", requestBodySchema.Reference.Id);
Copy link
Member

Choose a reason for hiding this comment

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

To test my understanding, this would have been ArrayOfTodo2 in the buggy case?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep!

@captainsafia captainsafia merged commit 53f01dc into main Jul 9, 2024
26 checks passed
@captainsafia captainsafia deleted the safia/stable-schema-refs branch July 9, 2024 18:58
@dotnet-policy-service dotnet-policy-service bot added this to the 9.0-preview7 milestone Jul 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates feature-openapi
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Schema get duplicated for every request in open-api
2 participants