Skip to content

Emit intrinsic @TypeSpec.example for model properties in autorest (OpenAPI2)#4393

Open
Copilot wants to merge 5 commits intomainfrom
copilot/fix-example-not-working-on-model-property
Open

Emit intrinsic @TypeSpec.example for model properties in autorest (OpenAPI2)#4393
Copilot wants to merge 5 commits intomainfrom
copilot/fix-example-not-working-on-model-property

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 7, 2026

@example on model properties was being dropped by the autorest (Swagger 2.0) emitter, causing schema-level example metadata loss during conversion. OpenAPI3 already preserved this, so OpenAPI2 behavior was inconsistent.

  • Emitter behavior update

    • In typespec-autorest OpenAPI2 emission, property-level intrinsic examples are now applied when present.
    • applyIntrinsicDecorators(...) now reads intrinsic TypeSpec examples and writes example on property schemas.
  • Type surface alignment

    • Extended OpenAPI2Schema to include example?: unknown so emitted property examples are modeled in the document types.
  • Regression coverage

    • Added a focused model test asserting that @TypeSpec.example(...) on a property emits definitions.<Model>.properties.<prop>.example.
model Test {
  @TypeSpec.example("core.windows.net")
  abcd: string;
}

Expected emitted schema fragment:

"abcd": {
  "type": "string",
  "example": "core.windows.net"
}

@microsoft-github-policy-service microsoft-github-policy-service Bot added the emitter:autorest Issues for @azure-tools/typespec-autorest emitter label May 7, 2026
Copilot AI changed the title [WIP] Fix @example not working on model property Emit intrinsic @TypeSpec.example for model properties in autorest (OpenAPI2) May 7, 2026
Copilot AI requested a review from timotheeguerin May 7, 2026 14:57
@timotheeguerin
Copy link
Copy Markdown
Member

@copilot add changelog

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 7, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@azure-tools/typespec-autorest@4393

commit: 5ac0162

Agent-Logs-Url: https://github.com/Azure/typespec-azure/sessions/94acf26e-2990-4756-b804-ad6866bddcb0

Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 7, 2026

@copilot add changelog

Added the changelog entry in .chronus/changes/fix-autorest-property-example-2026-05-07-15-04-16.md in commit 7142e34.

@timotheeguerin
Copy link
Copy Markdown
Member

@copilot run formatter

Agent-Logs-Url: https://github.com/Azure/typespec-azure/sessions/e6374227-21d0-4c22-9898-63224d996ac5

Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 7, 2026

@copilot run formatter

Ran formatter and pushed the formatting update in commit f3d3e2d.

@timotheeguerin timotheeguerin marked this pull request as ready for review May 7, 2026 18:01
@azure-sdk
Copy link
Copy Markdown
Collaborator

All changed packages have been documented.

  • @azure-tools/typespec-autorest
Show changes

@azure-tools/typespec-autorest - fix ✏️

Emit intrinsic @TypeSpec.example(...) on model properties in the autorest OpenAPI2 emitter so property example values are preserved in generated definitions.

Comment thread packages/typespec-autorest/test/models.test.ts Outdated
Agent-Logs-Url: https://github.com/Azure/typespec-azure/sessions/a6349b38-dccf-4bbf-8155-c2bfa915ff99

Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
@azure-sdk
Copy link
Copy Markdown
Collaborator

You can try these changes here

🛝 Playground 🌐 Website

Copilot AI requested a review from timotheeguerin May 7, 2026 18:13
@markcowl markcowl added the int:azure-specs Run integration tests against azure-rest-api-specs label May 7, 2026
Copy link
Copy Markdown
Member

@markcowl markcowl left a comment

Choose a reason for hiding this comment

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

Looks good. Want to see the impact on azure-specs (if any) , so added the label.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

emitter:autorest Issues for @azure-tools/typespec-autorest emitter int:azure-specs Run integration tests against azure-rest-api-specs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@example doesn't work on model property

4 participants