feat(typespec-autorest): add skip-example-copying emitter option and examples-dir version interpolation#4190
feat(typespec-autorest): add skip-example-copying emitter option and examples-dir version interpolation#4190Copilot wants to merge 13 commits into
skip-example-copying emitter option and examples-dir version interpolation#4190Conversation
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>
markcowl
left a comment
There was a problem hiding this comment.
- 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
Agent-Logs-Url: https://github.com/Azure/typespec-azure/sessions/774e6722-332b-4c31-acf6-e8363ef4a705 Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com>
Added in 9e3df9b:
All 468 tests pass, files are formatted, and branch is up to date with main. |
|
/azp run typespec-azure - PR Tools |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
All changed packages have been documented.
Show changes
|
commit: |
|
You can try these changes here
|
|
@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) |
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>
Branch is up to date with main (no merge issues). Fixed the formatting issue in |
Agent-Logs-Url: https://github.com/Azure/typespec-azure/sessions/0e356775-70e8-49d6-92a6-ec924dcbba65 Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com>
|
… snapshots Agent-Logs-Url: https://github.com/Azure/typespec-azure/sessions/6bb7e57d-bb20-4569-9e32-5ca3f5245044 Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com>
| 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" |
There was a problem hiding this comment.
I am thinking we don't copy into the swagger directory.
There was a problem hiding this comment.
so they would be at examples/<version>/
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
I think there is 2 issues with that:
- Oav will generate I think in the wrong location so you'd still need to copy back
- That will cause all refs to be udpated in the seagger when we migrate no?
…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>
Pulled latest from main and fixed the e2e test failures in |
There was a problem hiding this comment.
@copliot There is a slight change of plan for this PR. instead of examples remaining in the source typespec examples folder, they will be in the examples folder under the versioned output folder.
So, examples-dir would be {emitter-output-dir}/{version-status}/{version}/examples for examples associated with a particular version.
Update thetests to validate that versioned examples are properly picked up and x-ms-examples references are added to the appropriate operation in each version, and have the correct relative path.
Then make any adjustments to the implementation to make these tests pass.
When finished, ensure that all tests pass, all samples rebuild cleanly, all files are correclty formatted. Pull the latest from main and ensure that only changes associated with this PR are in the PR diff.
…ption-skip-example-copying Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com>
…s-dir for versioned output folder structure Agent-Logs-Url: https://github.com/Azure/typespec-azure/sessions/521b6462-0e02-4b6d-b8e7-fd79cb7f3c39 Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com>
... Implemented in
|
skip-example-copying emitter optionskip-example-copying emitter option and examples-dir version interpolation
markcowl
left a comment
There was a problem hiding this comment.
Pull the latest from main , make the suggested changes, add the suggested tests and ensure that all tests pass. Ensure that all files are formatted correctly and the PR diff contains only changes associated with this PR
| options: | ||
| "@azure-tools/typespec-autorest": | ||
| output-file: "data-plane/{service-name}/{version-status}/{version}/openapi.json" | ||
| examples-dir: "{project-root}/examples" |
There was a problem hiding this comment.
Regenerated snapshots in ff2350d — they're identical to the previous commit since the feed tspconfig sources haven't changed.
| JSON.stringify({ operationId: "Pets_get", title: "Get a pet v2" }), | ||
| ); | ||
|
|
||
| const [{ outputs }, diagnostics] = await tester.compileAndDiagnose( |
There was a problem hiding this comment.
need to add tests where
- interpolated configuration
{emitter-output-dir}/{version-status}/{version}/examplesis used for example dir and- examples are added in directories for two different versions and the emitted x-ms-examples for the associated operations have correct relative path to the appropriate example
- examples are added in sub-directories of the versioned directory and still picked up and used correctly in x-ms-examples
There was a problem hiding this comment.
Added both tests in ff2350d:
-
Multi-version interpolated examples-dir: Test with
{emitter-output-dir}/{version-status}/{version}/examplesconfig, v1 and v2 each with different examples (v1: getPet + listPets, v2: getPet + deletePet). Verifies each version's operations get correct$ref: "examples/..."relative paths, and v2-only operation (delete) only appears in v2 output. -
Sub-directory examples: Examples placed in
examples/pets/getPet.jsonandexamples/pets/listPets.jsonunder the versioned output folder. Verifies sub-directory structure is preserved in$refpaths (examples/pets/getPet.json).
All 477 tests pass.
… tests Agent-Logs-Url: https://github.com/Azure/typespec-azure/sessions/21993efe-44da-4d7b-a3b7-cda318fd09b1 Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com>
Done in |

skip-example-copyingboolean option toAutorestEmitterOptionsinterface and JSON schemaskipExampleCopyingtoAutorestDocumentEmitterOptionsskipExampleCopyingthrough inresolveAutorestOptions$refgeneration to use relative source path when skip-example-copying is enabledskip-example-copyingandexamples-direxamples-dironly (skip-example-copying not yet in published npm package){version-status}and{version}interpolation inexamples-dir