Scrub extension properties in OpenAPI document during serialization #56688
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
IOpenApiAny
implementation that implements a no-opWrite
method to support representing values that don't serialize themselves to disk.OpenApiJsonWriter
that implements a customWritePropertyName
to avoid serializing keys associated with in-memory attributes (x-schema-id
andx-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.