Skip to content

feat(typespec-autorest): add skip-example-copying emitter option#4190

Open
Copilot wants to merge 10 commits intomainfrom
copilot/add-emitter-option-skip-example-copying
Open

feat(typespec-autorest): add skip-example-copying emitter option#4190
Copilot wants to merge 10 commits intomainfrom
copilot/add-emitter-option-skip-example-copying

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 3, 2026

  • Add skip-example-copying boolean option to AutorestEmitterOptions interface and JSON schema
  • Add skipExampleCopying to AutorestDocumentEmitterOptions
  • Pass skipExampleCopying through in resolveAutorestOptions
  • Modify $ref generation to use relative source path when skip-example-copying is enabled
  • Skip file copying when skip-example-copying is enabled
  • Write tests for non-versioned skip-example-copying
  • Regenerate docs
  • Add changeset for this feature
  • Add test for versioned spec with skip-example-copying (correct refs + no copying)
  • Fix formatting (pnpm format)
  • Update non-standalone tspconfig.yaml files in feeds with skip-example-copying and examples-dir
  • Update standalone tspconfig files with examples-dir only (skip-example-copying not yet in published npm package)
  • Rebuild feed snapshots
  • Update x-ms-examples FAQ doc to recommend the new setting
  • Merge latest main, run formatting, ensure all tests pass (468/468)

When enabled, the emitter will not copy example files to the output
directory. Instead, it will reference the source example files using
relative file paths from the output location.

Agent-Logs-Url: https://github.com/Azure/typespec-azure/sessions/5966f0f4-258b-41b9-9753-b3b16cb262f3

Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com>
@microsoft-github-policy-service microsoft-github-policy-service Bot added emitter:autorest Issues for @azure-tools/typespec-autorest emitter meta:website TypeSpec.io updates labels Apr 3, 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.

  • add a changeset for this feature
  • Add an additional test that verifies correct example example references and no copying in a versioned spec.

Make sure all tests are passing and all files are correctly formatted and that your branch is up to date with main and has no merge issues

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 3, 2026

  • add a changeset for this feature
  • Add an additional test that verifies correct example example references and no copying in a versioned spec.
    ...

Added in 9e3df9b:

  • Changeset at .chronus/changes/skip-example-copying-2026-04-03-05-20-45.md (changeKind: feature)
  • New versioned spec test that verifies correct relative $ref paths for both v1 and v2 outputs (../../../examples/v1/getPet.json and ../../../examples/v2/getPet.json) and asserts that no example files are copied to either version's output directory

All 468 tests pass, files are formatted, and branch is up to date with main.

Copilot AI requested a review from markcowl April 3, 2026 05:36
@markcowl
Copy link
Copy Markdown
Member

markcowl commented Apr 3, 2026

/azp run typespec-azure - PR Tools

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@markcowl markcowl marked this pull request as ready for review April 3, 2026 20:59
@azure-sdk
Copy link
Copy Markdown
Collaborator

azure-sdk commented Apr 3, 2026

All changed packages have been documented.

  • @azure-tools/typespec-autorest
Show changes

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

Added skip-example-copying emitter option. When enabled, example files are not copied to the output directory and x-ms-examples $ref values point directly to the source example files via relative paths.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 3, 2026

Open in StackBlitz

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

commit: d32fb08

@azure-sdk
Copy link
Copy Markdown
Collaborator

azure-sdk commented Apr 3, 2026

You can try these changes here

🛝 Playground 🌐 Website

@markcowl
Copy link
Copy Markdown
Member

markcowl commented Apr 3, 2026

@copilot Please pull the latest from main, ensure there are no merge issues, and ensure that all files are correctly formatting (this PR is currently failing the format check (pnpm format)

@markcowl markcowl added the int:azure-specs Run integration tests against azure-rest-api-specs label Apr 3, 2026
Agent-Logs-Url: https://github.com/Azure/typespec-azure/sessions/a5a493be-c2a6-4f3a-afc1-182c25389195

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

Copilot AI commented Apr 3, 2026

@copilot Please pull the latest from main, ensure there are no merge issues, and ensure that all files are correctly formatting (this PR is currently failing the format check (pnpm format)

Branch is up to date with main (no merge issues). Fixed the formatting issue in b520b3fpnpm format had two spots in the test file where prettier wanted to collapse multi-line expressions onto single lines. All 468 tests continue to pass.

Copilot AI requested a review from markcowl April 3, 2026 21:51
Comment thread .chronus/changes/skip-example-copying-2026-04-03-05-20-45.md
@markcowl
Copy link
Copy Markdown
Member

@copilot Please update the tsp init feeds for Azure (ARM and data-plane) located in /eng/feeds to use this setting by default, rebuild the feeds and ensure that tests pass. Also update this document: https://azure.github.io/typespec-azure/docs/migrate-swagger/faq/x-ms-examples/ to recommend using the new setting and set the examples directory appropriately (provide a valid example).

Pull the latest from main, ensure no merge issues, only your changes are in the PR, and that all files are formatted correctly and all tests pass.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 14, 2026

@copilot Please update the tsp init feeds for Azure (ARM and data-plane) located in /eng/feeds to use this setting by default, rebuild the feeds and ensure that tests pass. Also update this document:...

Done in 62c9e93 and 7fc6ab4:

  • Updated all tspconfig.yaml files in /eng/feeds (ARM, data-plane, ARM standalone, data-plane standalone, ARM canonical) to set skip-example-copying: true by default
  • Regenerated feed snapshots (__snapshots__/azure-arm, azure-arm_stand_alone, azure-core, azure-core_stand_alone)
  • Updated the x-ms-examples FAQ doc with a new "Recommended configuration" section showing how to enable skip-example-copying: true, and updated the OAV note to explain workflow when using the new setting
  • Branch is up to date with main, all 468 tests pass, formatting is clean

emitter-output-dir: "{project-root}"
output-file: "{emitter-output-dir}/{version-status}/{version}/widget.json"
arm-types-dir: "{project-root}/../../../../common-types/resource-management"
examples-dir: "{project-root}/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.

this is not correct right? with v2 the examples would be here?

Image

or you thinking that instead we don't copy down to the swagger?

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.

I am thinking we don't copy into the swagger directory.

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.

so they would be at examples/<version>/

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.

But this is assuming that we have logical example checks in ci, if we are forcing them to be at a particular location, then we should conform. It's worth checking.

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.

I think there is 2 issues with that:

  1. Oav will generate I think in the wrong location so you'd still need to copy back
  2. That will cause all refs to be udpated in the seagger when we migrate no?

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.

@copilot Pull the latest from main, then fix issues with e2e tests, ensure all tests pass and all fiels are correctly formatted

Copilot AI and others added 2 commits April 20, 2026 20:48
…ption-skip-example-copying

Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com>
… yet published to npm)

Agent-Logs-Url: https://github.com/Azure/typespec-azure/sessions/4aa2af3a-33fe-420d-854d-94d8c9a8345c

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

Copilot AI commented Apr 20, 2026

@copilot Pull the latest from main, then fix issues with e2e tests, ensure all tests pass and all fiels are correctly formatted

Pulled latest from main and fixed the e2e test failures in b8664fb6. The issue was that skip-example-copying was included in the standalone tspconfig files, but since the published npm version of @azure-tools/typespec-autorest doesn't have this option yet, schema validation failed when the standalone templates ran tsp compile. Removed skip-example-copying from the standalone configs while keeping examples-dir (which is already published). All 468 tests pass and formatting is clean.

Copilot AI requested a review from markcowl April 20, 2026 21:05
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 eng int:azure-specs Run integration tests against azure-rest-api-specs meta:website TypeSpec.io updates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants