Skip to content

Preserve all XML comment schema examples - #67894

Open
pradeep-ramola wants to merge 11 commits into
dotnet:mainfrom
pradeep-ramola:fix-openapi-xml-schema-examples
Open

pradeep-ramola wants to merge 11 commits into
dotnet:mainfrom
pradeep-ramola:fix-openapi-xml-schema-examples

Conversation

@pradeep-ramola

@pradeep-ramola pradeep-ramola commented Jul 19, 2026 •

Copy link
Copy Markdown

Related to #65181.

Summary

Current main already uses the OpenAPI schema Examples collection, 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

  • Merged current main and resolved the source, nullable assertion, and generated snapshot conflicts.
  • Retained the reviewer-requested conversion of every type/property example instead of FirstOrDefault.
  • Added ordered, two-example assertions for types and properties, including XML documentation supplied by a referenced class library.
  • Refreshed the source-generator snapshots, including seven added upstream since this PR was opened.
  • Removed stale integration snapshot edits. Existing single-example documents match current main across OpenAPI 3.0, 3.1, and 3.2.

Parameter, response, and schema-reference example handling is unchanged.

Validation

Using the repository-pinned .NET SDK and runtime:

  • Source-generator build: passed with zero warnings and errors.
  • Complete source-generator test suite: 25 passed.
  • Complete OpenAPI test suite: 1,034 passed, 5 skipped.
  • The OpenAPI suite includes 189 document integration tests across versions 3.0, 3.1, and 3.2; all passed.
  • 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.

@pradeep-ramola
pradeep-ramola requested a review from a team as a code owner July 19, 2026 05:44
@pradeep-ramola

Copy link
Copy Markdown
Author

@dotnet-policy-service agree

"booleanType": {
"type": "boolean",
"example": true
"examples": [

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Created this issue. Sending copilot after it locally. microsoft/OpenAPI.NET#2969

@pradeep-ramola
pradeep-ramola force-pushed the fix-openapi-xml-schema-examples branch from 7c32a4f to f850b7c Compare July 20, 2026 07:33
@Youssef1313

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 2 pipeline(s).
3 pipeline(s) were filtered out due to trigger conditions.

@Youssef1313

Copy link
Copy Markdown
Member

@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.

@pradeep-ramola

Copy link
Copy Markdown
Author

@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.

@Youssef1313

Copy link
Copy Markdown
Member

@pradeep-ramola A new version of Microsoft.OpenApi was released. So I think this can start moving forward.

@Youssef1313 Youssef1313 added the area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc label Sep 2, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Looks like this PR hasn't been active for some time and the codebase could have been changed in the meantime.
To make sure no conflicting changes have occurred, please rerun validation before merging. You can do this by leaving an /azp run comment here (requires commit rights), or by simply closing and reopening.

@dotnet-policy-service dotnet-policy-service Bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Sep 26, 2026
@pradeep-ramola pradeep-ramola changed the title Use schema examples for XML comment examples Preserve all XML comment schema examples Nov 30, 2026
@pradeep-ramola

Copy link
Copy Markdown
Author

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.

This branch has not been deployed

No deployments
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 pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants