Skip to content
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

fix: Ignore path item components in paths #1734

Merged
merged 3 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export default function transformPathsObject(pathsObject: PathsObject, ctx: Glob
/* type */ oapiRef(pathItemObject.$ref),
);
addJSDocComment(pathItemObject, property);
type.push(property);
} else {
const pathItemType = transformPathItemObject(pathItemObject, {
path: createRef(["paths", url]),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
openapi: 3.1.0

info:
title: Path Items
version: 1.0.0
license:
name: MIT
url: https://opensource.org/licenses/MIT

servers:
- url: https://my-example-server

paths:
/users:
$ref: '#/components/pathItems/users'

security:
- bearerAuth: []

components:
pathItems:
users:
post:
summary: Create user
operationId: createUser

requestBody:
description: The user to create
content:
application/json:
schema:
type: object
properties:
name:
type: string

responses:
200:
description: The user was created successfully
content:
application/json:
schema:
type: object
properties:
id:
type: string
name:
type: string
400:
description: Bad request

securitySchemes:
bearerAuth:
type: http
scheme: bearer
bearerFormat: JWT
81 changes: 81 additions & 0 deletions packages/openapi-typescript/test/yaml.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,87 @@ export interface operations {
};
};
};
}`);
});

test("not ignore path item components in paths", async () => {
const result = await execa(cmd, ["./test/fixtures/path-item-components.yaml"], {
cwd,
});
expect(result.stdout).toBe(`/**
* This file was auto-generated by openapi-typescript.
* Do not make direct changes to the file.
*/

export interface paths {
"/users": components["pathItems"]["users"];
}
export type webhooks = Record<string, never>;
export interface components {
schemas: never;
responses: never;
parameters: never;
requestBodies: never;
headers: never;
pathItems: {
users: {
parameters: {
query?: never;
header?: never;
path?: never;
cookie?: never;
};
get?: never;
put?: never;
/** Create user */
post: operations["createUser"];
delete?: never;
options?: never;
head?: never;
patch?: never;
trace?: never;
};
};
}
export type $defs = Record<string, never>;
export interface operations {
createUser: {
parameters: {
query?: never;
header?: never;
path?: never;
cookie?: never;
};
/** @description The user to create */
requestBody?: {
content: {
"application/json": {
name?: string;
};
};
};
responses: {
/** @description The user was created successfully */
200: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": {
id?: string;
name?: string;
};
};
};
/** @description Bad request */
400: {
headers: {
[name: string]: unknown;
};
content?: never;
};
};
};
}`);
});
});