-
Notifications
You must be signed in to change notification settings - Fork 353
feat(openapi3): Add paging link decorator import from x-ms-list-*-link extensions #9627
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
4 commits
Select commit
Hold shift + click to select a range
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
...onus/changes/copilot-add-import-support-prevlink-decorator-2026-1-6-17-55-25.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 importing paging link decorators (@prevLink, @nextLink, @firstLink, @lastLink) based on x-ms-list-*-link OpenAPI extensions | ||
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
214 changes: 214 additions & 0 deletions
214
packages/openapi3/test/tsp-openapi3/paging-links.test.ts
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,214 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import { expectDecorators } from "./utils/expect.js"; | ||
| import { renderTypeSpecForOpenAPI3, tspForOpenAPI3 } from "./utils/tsp-for-openapi3.js"; | ||
|
|
||
| describe("converts paging link extensions", () => { | ||
| it("handles x-ms-list-prev-link extension", async () => { | ||
| const serviceNamespace = await tspForOpenAPI3({ | ||
| schemas: { | ||
| WidgetList: { | ||
| type: "object", | ||
| required: ["value", "prevLink"], | ||
| properties: { | ||
| value: { | ||
| type: "array", | ||
| items: { | ||
| type: "string", | ||
| }, | ||
| }, | ||
| prevLink: { | ||
| type: "string", | ||
| "x-ms-list-prev-link": true, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| const widgetList = serviceNamespace.models.get("WidgetList"); | ||
| expect(widgetList).toBeDefined(); | ||
|
|
||
| const prevLinkProp = widgetList?.properties.get("prevLink"); | ||
| expect(prevLinkProp).toBeDefined(); | ||
|
|
||
| // Should have both @extension and @prevLink decorators | ||
| // Note: TypeSpec compiler may reorder decorators during parsing | ||
| expectDecorators(prevLinkProp!.decorators, [ | ||
| { name: "prevLink", args: [] }, | ||
| { name: "extension", args: ["x-ms-list-prev-link", true] }, | ||
| ]); | ||
| }); | ||
|
|
||
| it("handles x-ms-list-next-link extension", async () => { | ||
| const serviceNamespace = await tspForOpenAPI3({ | ||
| schemas: { | ||
| WidgetList: { | ||
| type: "object", | ||
| required: ["value", "nextLink"], | ||
| properties: { | ||
| value: { | ||
| type: "array", | ||
| items: { | ||
| type: "string", | ||
| }, | ||
| }, | ||
| nextLink: { | ||
| type: "string", | ||
| "x-ms-list-next-link": true, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| const widgetList = serviceNamespace.models.get("WidgetList"); | ||
| expect(widgetList).toBeDefined(); | ||
|
|
||
| const nextLinkProp = widgetList?.properties.get("nextLink"); | ||
| expect(nextLinkProp).toBeDefined(); | ||
|
|
||
| // Should have both @extension and @nextLink decorators | ||
| // Note: TypeSpec compiler may reorder decorators during parsing | ||
| expectDecorators(nextLinkProp!.decorators, [ | ||
| { name: "nextLink", args: [] }, | ||
| { name: "extension", args: ["x-ms-list-next-link", true] }, | ||
| ]); | ||
| }); | ||
|
|
||
| it("handles x-ms-list-first-link extension", async () => { | ||
| const serviceNamespace = await tspForOpenAPI3({ | ||
| schemas: { | ||
| WidgetList: { | ||
| type: "object", | ||
| required: ["value", "firstLink"], | ||
| properties: { | ||
| value: { | ||
| type: "array", | ||
| items: { | ||
| type: "string", | ||
| }, | ||
| }, | ||
| firstLink: { | ||
| type: "string", | ||
| "x-ms-list-first-link": true, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| const widgetList = serviceNamespace.models.get("WidgetList"); | ||
| expect(widgetList).toBeDefined(); | ||
|
|
||
| const firstLinkProp = widgetList?.properties.get("firstLink"); | ||
| expect(firstLinkProp).toBeDefined(); | ||
|
|
||
| // Should have both @extension and @firstLink decorators | ||
| // Note: TypeSpec compiler may reorder decorators during parsing | ||
| expectDecorators(firstLinkProp!.decorators, [ | ||
| { name: "firstLink", args: [] }, | ||
| { name: "extension", args: ["x-ms-list-first-link", true] }, | ||
| ]); | ||
| }); | ||
|
|
||
| it("handles x-ms-list-last-link extension", async () => { | ||
| const serviceNamespace = await tspForOpenAPI3({ | ||
| schemas: { | ||
| WidgetList: { | ||
| type: "object", | ||
| required: ["value", "lastLink"], | ||
| properties: { | ||
| value: { | ||
| type: "array", | ||
| items: { | ||
| type: "string", | ||
| }, | ||
| }, | ||
| lastLink: { | ||
| type: "string", | ||
| "x-ms-list-last-link": true, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| const widgetList = serviceNamespace.models.get("WidgetList"); | ||
| expect(widgetList).toBeDefined(); | ||
|
|
||
| const lastLinkProp = widgetList?.properties.get("lastLink"); | ||
| expect(lastLinkProp).toBeDefined(); | ||
|
|
||
| // Should have both @extension and @lastLink decorators | ||
| // Note: TypeSpec compiler may reorder decorators during parsing | ||
| expectDecorators(lastLinkProp!.decorators, [ | ||
| { name: "lastLink", args: [] }, | ||
| { name: "extension", args: ["x-ms-list-last-link", true] }, | ||
| ]); | ||
| }); | ||
|
|
||
| it("only adds link decorator when extension value is true", async () => { | ||
| const serviceNamespace = await tspForOpenAPI3({ | ||
| schemas: { | ||
| WidgetList: { | ||
| type: "object", | ||
| required: ["value", "prevLink"], | ||
| properties: { | ||
| value: { | ||
| type: "array", | ||
| items: { | ||
| type: "string", | ||
| }, | ||
| }, | ||
| prevLink: { | ||
| type: "string", | ||
| "x-ms-list-prev-link": false, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| const widgetList = serviceNamespace.models.get("WidgetList"); | ||
| expect(widgetList).toBeDefined(); | ||
|
|
||
| const prevLinkProp = widgetList?.properties.get("prevLink"); | ||
| expect(prevLinkProp).toBeDefined(); | ||
|
|
||
| // Should only have @extension decorator, not @prevLink | ||
| expectDecorators(prevLinkProp!.decorators, [ | ||
| { name: "extension", args: ["x-ms-list-prev-link", false] }, | ||
| ]); | ||
| }); | ||
|
|
||
| it("renders TypeSpec with correct imports for prevLink", async () => { | ||
| const tsp = await renderTypeSpecForOpenAPI3({ | ||
| schemas: { | ||
| WidgetList: { | ||
| type: "object", | ||
| required: ["value", "prevLink"], | ||
| properties: { | ||
| value: { | ||
| type: "array", | ||
| items: { | ||
| type: "string", | ||
| }, | ||
| }, | ||
| prevLink: { | ||
| type: "string", | ||
| "x-ms-list-prev-link": true, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| // Should import @typespec/openapi | ||
| expect(tsp).toContain('import "@typespec/openapi";'); | ||
| // Should have using OpenAPI | ||
| expect(tsp).toContain("using OpenAPI;"); | ||
| // Should have both decorators | ||
| expect(tsp).toContain('@extension("x-ms-list-prev-link", true)'); | ||
| expect(tsp).toContain("@prevLink"); | ||
| }); | ||
| }); |
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.