Repository navigation
Preserve all XML comment schema examples - #67894
pradeep-ramola wants to merge 11 commits into
Conversation
|
| "booleanType": { | ||
| "type": "boolean", | ||
| "example": true | ||
| "examples": [ |
There was a problem hiding this comment.
@baywet I tried to look quickly at Microsoft.OpenApi usage of Examples, and in serialization I found it's happening only in WriteJsonSchemaKeywords (>= 3.1). But it's getting emitted in 3.0 here. Is there some code path I'm not seeing?
I can investigate myself if you don't have quick/immediate answer.
There was a problem hiding this comment.
Thanks for the review. I addressed the two FirstOrDefault() comments in the latest push: schema XML examples now populate schema.Examples from all parsed XML examples instead of only using the first one.
For the OpenAPI 3.0 snapshot question, I’ll leave that one to @baywet since it is about the Microsoft.OpenApi serialization behavior. Happy to update the snapshots/code if the expected 3.0 output should differ.
There was a problem hiding this comment.
Here are a couple of elements of response for what the behaviour should be:
- version 2.X and 3.X only example (singular) existed, it's raw JSON that MUST validate the associated schema
- version 3.1+ examples (plural) was "imported from" JSON schema 2020-12, and it deprecates the singular field. The definition is here, it's an array and items in there should validate against the associated schema.
Now, in terms of serialization behaviour:
- examples (plural) MUST serialize as x-jsonschema-examples for OpenAPI 3.0 and 2.0. As examples (no extension) for 3.1+
- example (singular) MUST serialize as is across any version.
If that's not the current behaviour from Microsoft.OpenAPI, it needs to be fixed, go ahead and open an issue + PR.
Let me know if you have any additional comments or questions.
There was a problem hiding this comment.
@pradeep-ramola Would you like to do the investigation on Microsoft.OpenApi side? If not, let me know and I'll take care of it.
There was a problem hiding this comment.
Created this issue. Sending copilot after it locally. microsoft/OpenAPI.NET#2969
7c32a4f to
f850b7c
Compare
|
/azp run |
|
Azure Pipelines: Successfully started running 2 pipeline(s). 3 pipeline(s) were filtered out due to trigger conditions. |
|
@pradeep-ramola The CI is failing here because there are test failures. I recommend waiting until a new version of Microsoft.OpenApi is released with some improvements that were done, get the new version flowing to the repo. Then you can merge latest main to your branch, run the tests locally, and update the snapshot tests to match the behavior so that the tests pass. |
Thanks for the clarification. I’ll wait until the Microsoft.OpenApi fix is released and flows into aspnetcore, then merge latest main into my branch, run the OpenAPI tests locally, and update the snapshots to match the new behavior. |
|
@pradeep-ramola A new version of Microsoft.OpenApi was released. So I think this can start moving forward. |
|
Looks like this PR hasn't been active for some time and the codebase could have been changed in the meantime. |
|
Updated in 91196ef and eb83e15 after merging current main. The remaining change preserves every XML schema example rather than selecting the first. Tests now check both example order and count for type/property comments, including documentation from a referenced class library. I refreshed the generated snapshots and removed the stale integration snapshot edits. Local validation with the pinned SDK/runtime: all 25 source-generator tests pass; the complete OpenAPI suite has 1,034 passing tests and 5 skips. This includes all 189 document integration cases across OpenAPI 3.0, 3.1, and 3.2. Tests used the managed-only flags documented in the PR description; the full repository suite was not run. |
Related to #65181.
Summary
Current main already uses the OpenAPI schema
Examplescollection, but XML comment schema transformers still select only the first<example>tag. This follow-up preserves all examples on schema types and inline schema properties.Review Follow-Up
FirstOrDefault.Parameter, response, and schema-reference example handling is unchanged.
Validation
Using the repository-pinned .NET SDK and runtime:
git diff --check origin/main: passed.The managed tests were run with
-p:BuildNodeJS=false -p:UseIisNativeAssets=false. Unrelated JavaScript and IIS native builds, and the full ASP.NET Core repository suite, were not run.AI Assistance
Prepared with OpenAI Codex assistance, including implementation, snapshot review, and local test execution.