-
Notifications
You must be signed in to change notification settings - Fork 338
feat(openapi3): Add @list decorator when x-ms-list extension is true #9609
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ed51ead
Initial plan
Copilot c020fb2
feat(openapi3): add support for x-ms-list extension
Copilot ebdb54b
chore: add changeset for x-ms-list extension support
Copilot 0f0c386
docs: adds missing quotes for the decorator
baywet 5e6c6f1
Merge branch 'main' into copilot/add-list-decorator-support
baywet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
.chronus/changes/copilot-add-list-decorator-support-2026-1-6-17-18-23.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| changeKind: feature | ||
| packages: | ||
| - "@typespec/openapi3" | ||
| --- | ||
|
|
||
| importer - Add support for x-ms-list extension to add @list decorator to operations | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import { OpenAPI3Response } from "../../src/types.js"; | ||
| import { renderTypeSpecForOpenAPI3, validateTsp } from "./utils/tsp-for-openapi3.js"; | ||
|
|
||
| const response: OpenAPI3Response = { | ||
| description: "test response", | ||
| content: { | ||
| "application/json": { | ||
| schema: { | ||
| type: "array", | ||
| items: { | ||
| type: "object", | ||
| properties: { | ||
| id: { type: "string" }, | ||
| name: { type: "string" }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| describe("x-ms-list extension", () => { | ||
| it("adds @list decorator when x-ms-list is true", async () => { | ||
| const tsp = await renderTypeSpecForOpenAPI3({ | ||
| paths: { | ||
| "/widgets": { | ||
| get: { | ||
| operationId: "Widgets_list", | ||
| "x-ms-list": true, | ||
| parameters: [], | ||
| responses: { | ||
| "200": response, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| expect(tsp).toContain("@list"); | ||
| expect(tsp).toContain('@extension("x-ms-list", true)'); | ||
|
|
||
| // Note: We don't validate the TypeSpec here because the generated code | ||
| // may not be semantically correct without proper pagination properties. | ||
| // The x-ms-list extension just indicates intent to mark the operation as a list operation. | ||
| }); | ||
|
|
||
| it("does not add @list decorator when x-ms-list is false", async () => { | ||
| const tsp = await renderTypeSpecForOpenAPI3({ | ||
| paths: { | ||
| "/widgets": { | ||
| get: { | ||
| operationId: "Widgets_list", | ||
| "x-ms-list": false, | ||
| parameters: [], | ||
| responses: { | ||
| "200": response, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| expect(tsp).not.toContain("@list"); | ||
| expect(tsp).toContain('@extension("x-ms-list", false)'); | ||
|
|
||
| await validateTsp(tsp); | ||
| }); | ||
|
|
||
| it("does not add @list decorator when x-ms-list is not present", async () => { | ||
| const tsp = await renderTypeSpecForOpenAPI3({ | ||
| paths: { | ||
| "/widgets": { | ||
| get: { | ||
| operationId: "Widgets_list", | ||
| parameters: [], | ||
| responses: { | ||
| "200": response, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| expect(tsp).not.toContain("@list"); | ||
| expect(tsp).not.toContain("x-ms-list"); | ||
|
|
||
| await validateTsp(tsp); | ||
| }); | ||
|
|
||
| it("handles x-ms-list in complete example with other decorators", async () => { | ||
| const tsp = await renderTypeSpecForOpenAPI3({ | ||
| paths: { | ||
| "/widgets": { | ||
| get: { | ||
| operationId: "Widgets_list", | ||
| description: "List widgets", | ||
| summary: "List all widgets", | ||
| "x-ms-list": true, | ||
| parameters: [], | ||
| responses: { | ||
| "200": { | ||
| description: "The request has succeeded.", | ||
| content: { | ||
| "application/json": { | ||
| schema: { | ||
| type: "array", | ||
| items: { | ||
| $ref: "#/components/schemas/Widget", | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| tags: ["Widgets"], | ||
| }, | ||
| }, | ||
| }, | ||
| schemas: { | ||
| Widget: { | ||
| type: "object", | ||
| required: ["id", "name"], | ||
| properties: { | ||
| id: { type: "string" }, | ||
| name: { type: "string" }, | ||
| }, | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| // Check that all expected decorators are present | ||
| expect(tsp).toContain("@list"); | ||
| expect(tsp).toContain('@extension("x-ms-list", true)'); | ||
| expect(tsp).toContain('@summary("List all widgets")'); | ||
| expect(tsp).toContain('@tag("Widgets")'); | ||
| expect(tsp).toContain("List widgets"); | ||
|
|
||
| // Note: We don't validate the TypeSpec here because the generated code | ||
| // may not be semantically correct without proper pagination properties. | ||
| // The x-ms-list extension just indicates intent to mark the operation as a list operation. | ||
| }); | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.