Skip to content

Commit c9cc9ab

Browse files
Copilotbaywet
andauthored
Apply remaining changes
Co-authored-by: baywet <7905502+baywet@users.noreply.github.com>
1 parent 7c4c6bf commit c9cc9ab

10 files changed

Lines changed: 74 additions & 17 deletions

File tree

packages/openapi/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export {
3535
ExtensionKey,
3636
ExternalDocs,
3737
License,
38+
TagMetadata,
3839
TagMetadataWithName,
3940
} from "./types.js";
4041

packages/openapi/src/types.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,19 +66,16 @@ export interface ExternalDocs {
6666
}
6767

6868
/**
69-
* Metadata for a tag including the tag name. Used with the array form of `@tagMetadata`.
69+
* Metadata for a tag.
7070
*/
71-
export interface TagMetadataWithName {
72-
/** The name of the tag. */
73-
name: string;
74-
71+
export interface TagMetadata {
7572
/** A description of the tag. */
7673
description?: string;
7774

7875
/** External documentation for the tag. */
7976
externalDocs?: ExternalDocs;
8077

81-
/** The name of a parent tag (only supported in OpenAPI 3.2). */
78+
/** The name of a parent tag (only supported natively in OpenAPI 3.2; emitted as `x-oai-parent` for 3.0 and 3.1). */
8279
parent?: string;
8380

8481
/** A short summary of the tag, used for display purposes. Only supported natively in OpenAPI 3.2. For 3.0 and 3.1, this will be emitted as `x-oai-summary`. */
@@ -90,3 +87,11 @@ export interface TagMetadataWithName {
9087
/** Additional extension data. Keys must start with `x-`. */
9188
[extensionKey: string]: unknown;
9289
}
90+
91+
/**
92+
* Metadata for a tag including the tag name. Used with the array form of `@tagMetadata`.
93+
*/
94+
export interface TagMetadataWithName extends TagMetadata {
95+
/** The name of the tag. */
96+
name: string;
97+
}

packages/openapi3/src/cli/actions/convert/transforms/transform-tags.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ export function transformTags(tags: OpenAPI3Tag[]): TypeSpecTagMetadata[] {
88
const summary: string | undefined =
99
tag32.summary ?? (tag["x-oai-summary"] as string | undefined);
1010
const kind: string | undefined = tag32.kind ?? (tag["x-oai-kind"] as string | undefined);
11-
// parent is only supported natively in OpenAPI 3.2
12-
const parent: string | undefined = tag32.parent;
11+
const parent: string | undefined = tag32.parent ?? (tag["x-oai-parent"] as string | undefined);
1312

1413
return {
1514
name: tag.name,

packages/openapi3/src/openapi.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1829,12 +1829,12 @@ function createOAPIEmitter(
18291829
for (const tag of metadataList ?? []) {
18301830
const { name, ...rest } = tag;
18311831
const tagData: OpenAPI3Tag = { name, ...rest };
1832-
// For OpenAPI 3.0 and 3.1, drop the 'parent' field (only supported in 3.2)
1833-
if (specVersion !== "3.2.0" && rest.parent) {
1834-
delete (tagData as { parent?: string }).parent;
1835-
}
1836-
// For OpenAPI 3.0 and 3.1, convert 'summary' and 'kind' to x-oai- prefixed extensions
1832+
// For OpenAPI 3.0 and 3.1, convert 'parent', 'summary', and 'kind' to x-oai- prefixed extensions
18371833
if (specVersion !== "3.2.0") {
1834+
if (tag.parent) {
1835+
(tagData as unknown as Record<string, unknown>)["x-oai-parent"] = tag.parent;
1836+
delete (tagData as { parent?: string }).parent;
1837+
}
18381838
if (tag.summary) {
18391839
(tagData as unknown as Record<string, unknown>)["x-oai-summary"] = tag.summary;
18401840
delete (tagData as { summary?: string }).summary;

packages/openapi3/test/tagmetadata.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ describe("tag metadata with parent field", () => {
240240
]);
241241
});
242242

243-
it("OpenAPI 3.1 should drop parent field", async () => {
243+
it("OpenAPI 3.1 should emit parent field as x-oai-parent", async () => {
244244
const res = await OpenAPISpecHelpers["3.1.0"].openApiFor(
245245
`
246246
@service
@@ -256,6 +256,7 @@ describe("tag metadata with parent field", () => {
256256
{
257257
name: "ChildTag",
258258
description: "Child tag",
259+
"x-oai-parent": "ParentTag",
259260
},
260261
{
261262
name: "ParentTag",
@@ -264,7 +265,7 @@ describe("tag metadata with parent field", () => {
264265
]);
265266
});
266267

267-
it("OpenAPI 3.0 should drop parent field", async () => {
268+
it("OpenAPI 3.0 should emit parent field as x-oai-parent", async () => {
268269
const res = await OpenAPISpecHelpers["3.0.0"].openApiFor(
269270
`
270271
@service
@@ -280,6 +281,7 @@ describe("tag metadata with parent field", () => {
280281
{
281282
name: "ChildTag",
282283
description: "Child tag",
284+
"x-oai-parent": "ParentTag",
283285
},
284286
{
285287
name: "ParentTag",

packages/openapi3/test/tsp-openapi3/convert-openapi3-doc.test.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,7 @@ describe("convertOpenAPI3Document tag metadata", () => {
988988
);
989989
});
990990

991-
it("converts OpenAPI 3.0/3.1 tags with x-oai- extensions for summary and kind", async () => {
991+
it("converts OpenAPI 3.0/3.1 tags with x-oai- extensions for summary, kind, and parent", async () => {
992992
for (const version of ["3.0.0", "3.1.0"] as const) {
993993
const tsp = await convertOpenAPI3Document({
994994
info: {
@@ -1004,6 +1004,11 @@ describe("convertOpenAPI3Document tag metadata", () => {
10041004
"x-oai-summary": "Tag summary",
10051005
"x-oai-kind": "OperationGroup",
10061006
},
1007+
{
1008+
name: "child-tag",
1009+
description: "A child tag",
1010+
"x-oai-parent": "simple-tag",
1011+
},
10071012
],
10081013
});
10091014

@@ -1020,7 +1025,10 @@ describe("convertOpenAPI3Document tag metadata", () => {
10201025
10211026
@service(#{ title: "(title)" })
10221027
@info(#{ version: "0.0.0" })
1023-
@tagMetadata(#[#{ name: "simple-tag", description: "A simple tag", summary: "Tag summary", kind: "OperationGroup" }])
1028+
@tagMetadata(#[
1029+
#{ name: "simple-tag", description: "A simple tag", summary: "Tag summary", kind: "OperationGroup" },
1030+
#{ name: "child-tag", description: "A child tag", parent: "simple-tag" },
1031+
])
10241032
namespace title;
10251033
`,
10261034
{ printWidth: 100, tabWidth: 2 },

vitest.config.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* Default Config For all TypeSpec projects using vitest.
3+
*/
4+
export declare const defaultTypeSpecVitestConfig: import("vite").UserConfig;
5+
declare const _default: Record<string, any>;
6+
export default _default;
7+
//# sourceMappingURL=vitest.config.d.ts.map

vitest.config.d.ts.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vitest.config.js

Lines changed: 33 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vitest.config.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)