Skip to content

Commit d054a87

Browse files
phk422kerwanp
authored andcommitted
fix: Ignore path item components in paths (openapi-ts#1734)
* fix: Ignore path item components in paths * lint code * lint code
1 parent e3d799f commit d054a87

File tree

3 files changed

+138
-0
lines changed

3 files changed

+138
-0
lines changed

packages/openapi-typescript/src/transform/paths-object.ts

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export default function transformPathsObject(pathsObject: PathsObject, ctx: Glob
3535
/* type */ oapiRef(pathItemObject.$ref),
3636
);
3737
addJSDocComment(pathItemObject, property);
38+
type.push(property);
3839
} else {
3940
const pathItemType = transformPathItemObject(pathItemObject, {
4041
path: createRef(["paths", url]),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
openapi: 3.1.0
2+
3+
info:
4+
title: Path Items
5+
version: 1.0.0
6+
license:
7+
name: MIT
8+
url: https://opensource.org/licenses/MIT
9+
10+
servers:
11+
- url: https://my-example-server
12+
13+
paths:
14+
/users:
15+
$ref: '#/components/pathItems/users'
16+
17+
security:
18+
- bearerAuth: []
19+
20+
components:
21+
pathItems:
22+
users:
23+
post:
24+
summary: Create user
25+
operationId: createUser
26+
27+
requestBody:
28+
description: The user to create
29+
content:
30+
application/json:
31+
schema:
32+
type: object
33+
properties:
34+
name:
35+
type: string
36+
37+
responses:
38+
200:
39+
description: The user was created successfully
40+
content:
41+
application/json:
42+
schema:
43+
type: object
44+
properties:
45+
id:
46+
type: string
47+
name:
48+
type: string
49+
400:
50+
description: Bad request
51+
52+
securitySchemes:
53+
bearerAuth:
54+
type: http
55+
scheme: bearer
56+
bearerFormat: JWT

packages/openapi-typescript/test/yaml.test.ts

+81
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,87 @@ export interface operations {
8383
};
8484
};
8585
};
86+
}`);
87+
});
88+
89+
test("not ignore path item components in paths", async () => {
90+
const result = await execa(cmd, ["./test/fixtures/path-item-components.yaml"], {
91+
cwd,
92+
});
93+
expect(result.stdout).toBe(`/**
94+
* This file was auto-generated by openapi-typescript.
95+
* Do not make direct changes to the file.
96+
*/
97+
98+
export interface paths {
99+
"/users": components["pathItems"]["users"];
100+
}
101+
export type webhooks = Record<string, never>;
102+
export interface components {
103+
schemas: never;
104+
responses: never;
105+
parameters: never;
106+
requestBodies: never;
107+
headers: never;
108+
pathItems: {
109+
users: {
110+
parameters: {
111+
query?: never;
112+
header?: never;
113+
path?: never;
114+
cookie?: never;
115+
};
116+
get?: never;
117+
put?: never;
118+
/** Create user */
119+
post: operations["createUser"];
120+
delete?: never;
121+
options?: never;
122+
head?: never;
123+
patch?: never;
124+
trace?: never;
125+
};
126+
};
127+
}
128+
export type $defs = Record<string, never>;
129+
export interface operations {
130+
createUser: {
131+
parameters: {
132+
query?: never;
133+
header?: never;
134+
path?: never;
135+
cookie?: never;
136+
};
137+
/** @description The user to create */
138+
requestBody?: {
139+
content: {
140+
"application/json": {
141+
name?: string;
142+
};
143+
};
144+
};
145+
responses: {
146+
/** @description The user was created successfully */
147+
200: {
148+
headers: {
149+
[name: string]: unknown;
150+
};
151+
content: {
152+
"application/json": {
153+
id?: string;
154+
name?: string;
155+
};
156+
};
157+
};
158+
/** @description Bad request */
159+
400: {
160+
headers: {
161+
[name: string]: unknown;
162+
};
163+
content?: never;
164+
};
165+
};
166+
};
86167
}`);
87168
});
88169
});

0 commit comments

Comments
 (0)