Skip to content
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
13 changes: 13 additions & 0 deletions __mocks__/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,19 @@ paths:
description: "Created"
"500":
description: "Fatal error"
/patch-test-parameter-with-body-ref:
patch:
operationId: "patchTestParameterWithBodyReference"
parameters:
- name: body
in: body
schema:
$ref: "#/definitions/NewModel"
responses:
"201":
description: "Created"
"500":
description: "Fatal error"

/test-parameter-with-dash/{path-param}:
get:
Expand Down
13 changes: 13 additions & 0 deletions __mocks__/openapi_v3/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,19 @@ paths:
description: "Created"
500:
description: "Fatal error"
/patch-test-parameter-with-body-ref:
patch:
operationId: "patchTestParameterWithBodyReference"
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/NewModel"
responses:
201:
description: "Created"
500:
description: "Fatal error"
/test-parameter-with-dash/{path-param}:
get:
operationId: "testParameterWithDash"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,8 @@ import {
testParameterWithBodyReferenceDefaultDecoder,
PutTestParameterWithBodyReferenceT,
putTestParameterWithBodyReferenceDefaultDecoder,
PatchTestParameterWithBodyReferenceT,
patchTestParameterWithBodyReferenceDefaultDecoder,
TestParameterWithDashT,
testParameterWithDashDefaultDecoder,
TestParameterWithDashAnUnderscoreT,
Expand Down Expand Up @@ -975,6 +977,7 @@ export type ApiOperation = TypeofApiCall<TestAuthBearerT> &
TypeofApiCall<TestParameterWithReferenceT> &
TypeofApiCall<TestParameterWithBodyReferenceT> &
TypeofApiCall<PutTestParameterWithBodyReferenceT> &
TypeofApiCall<PatchTestParameterWithBodyReferenceT> &
TypeofApiCall<TestParameterWithDashT> &
TypeofApiCall<TestParameterWithDashAnUnderscoreT> &
TypeofApiCall<TestWithTwoParamsT> &
Expand All @@ -998,6 +1001,7 @@ export type ParamKeys = keyof (TypeofApiParams<TestAuthBearerT> &
TypeofApiParams<TestParameterWithReferenceT> &
TypeofApiParams<TestParameterWithBodyReferenceT> &
TypeofApiParams<PutTestParameterWithBodyReferenceT> &
TypeofApiParams<PatchTestParameterWithBodyReferenceT> &
TypeofApiParams<TestParameterWithDashT> &
TypeofApiParams<TestParameterWithDashAnUnderscoreT> &
TypeofApiParams<TestWithTwoParamsT> &
Expand Down Expand Up @@ -1043,6 +1047,7 @@ export type WithDefaultsT<
| TestParameterWithReferenceT
| TestParameterWithBodyReferenceT
| PutTestParameterWithBodyReferenceT
| PatchTestParameterWithBodyReferenceT
| TestParameterWithDashT
| TestParameterWithDashAnUnderscoreT
| TestWithTwoParamsT
Expand Down Expand Up @@ -1092,6 +1097,10 @@ export type Client<
PutTestParameterWithBodyReferenceT
>;

readonly patchTestParameterWithBodyReference: TypeofApiCall<
PatchTestParameterWithBodyReferenceT
>;

readonly testParameterWithDash: TypeofApiCall<TestParameterWithDashT>;

readonly testParameterWithDashAnUnderscore: TypeofApiCall<
Expand Down Expand Up @@ -1193,6 +1202,13 @@ export type Client<
>
>;

readonly patchTestParameterWithBodyReference: TypeofApiCall<
ReplaceRequestParams<
PatchTestParameterWithBodyReferenceT,
Omit<RequestParams<PatchTestParameterWithBodyReferenceT>, K>
>
>;

readonly testParameterWithDash: TypeofApiCall<
ReplaceRequestParams<
TestParameterWithDashT,
Expand Down Expand Up @@ -1554,6 +1570,35 @@ export function createClient<K extends ParamKeys>({
options
);

const patchTestParameterWithBodyReferenceT: ReplaceRequestParams<
PatchTestParameterWithBodyReferenceT,
RequestParams<PatchTestParameterWithBodyReferenceT>
> = {
method: \\"patch\\",

headers: ({ [\\"customToken\\"]: customToken }) => ({
\\"custom-token\\": customToken,

\\"Content-Type\\": \\"application/json\\"
}),
response_decoder: patchTestParameterWithBodyReferenceDefaultDecoder(),
url: ({}) => \`\${basePath}/patch-test-parameter-with-body-ref\`,

body: ({ [\\"body\\"]: body }) =>
body?.constructor?.name === \\"Readable\\" ||
body?.constructor?.name === \\"ReadableStream\\"
? (body as ReadableStream)
: body?.constructor?.name === \\"Buffer\\"
? (body as Buffer)
: JSON.stringify(body),

query: () => withoutUndefinedValues({})
};
const patchTestParameterWithBodyReference: TypeofApiCall<PatchTestParameterWithBodyReferenceT> = createFetchRequestForApi(
patchTestParameterWithBodyReferenceT,
options
);

const testParameterWithDashT: ReplaceRequestParams<
TestParameterWithDashT,
RequestParams<TestParameterWithDashT>
Expand Down Expand Up @@ -1829,6 +1874,9 @@ export function createClient<K extends ParamKeys>({
putTestParameterWithBodyReference: (withDefaults || identity)(
putTestParameterWithBodyReference
),
patchTestParameterWithBodyReference: (withDefaults || identity)(
patchTestParameterWithBodyReference
),
testParameterWithDash: (withDefaults || identity)(testParameterWithDash),
testParameterWithDashAnUnderscore: (withDefaults || identity)(
testParameterWithDashAnUnderscore
Expand Down Expand Up @@ -2921,6 +2969,8 @@ import {
testParameterWithBodyReferenceDefaultDecoder,
PutTestParameterWithBodyReferenceT,
putTestParameterWithBodyReferenceDefaultDecoder,
PatchTestParameterWithBodyReferenceT,
patchTestParameterWithBodyReferenceDefaultDecoder,
TestParameterWithDashT,
testParameterWithDashDefaultDecoder,
TestParameterWithDashAnUnderscoreT,
Expand Down Expand Up @@ -2964,6 +3014,7 @@ export type ApiOperation = TypeofApiCall<TestAuthBearerT> &
TypeofApiCall<TestParameterWithReferenceT> &
TypeofApiCall<TestParameterWithBodyReferenceT> &
TypeofApiCall<PutTestParameterWithBodyReferenceT> &
TypeofApiCall<PatchTestParameterWithBodyReferenceT> &
TypeofApiCall<TestParameterWithDashT> &
TypeofApiCall<TestParameterWithDashAnUnderscoreT> &
TypeofApiCall<TestWithTwoParamsT> &
Expand All @@ -2988,6 +3039,7 @@ export type ParamKeys = keyof (TypeofApiParams<TestAuthBearerT> &
TypeofApiParams<TestParameterWithReferenceT> &
TypeofApiParams<TestParameterWithBodyReferenceT> &
TypeofApiParams<PutTestParameterWithBodyReferenceT> &
TypeofApiParams<PatchTestParameterWithBodyReferenceT> &
TypeofApiParams<TestParameterWithDashT> &
TypeofApiParams<TestParameterWithDashAnUnderscoreT> &
TypeofApiParams<TestWithTwoParamsT> &
Expand Down Expand Up @@ -3034,6 +3086,7 @@ export type WithDefaultsT<
| TestParameterWithReferenceT
| TestParameterWithBodyReferenceT
| PutTestParameterWithBodyReferenceT
| PatchTestParameterWithBodyReferenceT
| TestParameterWithDashT
| TestParameterWithDashAnUnderscoreT
| TestWithTwoParamsT
Expand Down Expand Up @@ -3085,6 +3138,10 @@ export type Client<
PutTestParameterWithBodyReferenceT
>;

readonly patchTestParameterWithBodyReference: TypeofApiCall<
PatchTestParameterWithBodyReferenceT
>;

readonly testParameterWithDash: TypeofApiCall<TestParameterWithDashT>;

readonly testParameterWithDashAnUnderscore: TypeofApiCall<
Expand Down Expand Up @@ -3193,6 +3250,13 @@ export type Client<
>
>;

readonly patchTestParameterWithBodyReference: TypeofApiCall<
ReplaceRequestParams<
PatchTestParameterWithBodyReferenceT,
Omit<RequestParams<PatchTestParameterWithBodyReferenceT>, K>
>
>;

readonly testParameterWithDash: TypeofApiCall<
ReplaceRequestParams<
TestParameterWithDashT,
Expand Down Expand Up @@ -3584,6 +3648,35 @@ export function createClient<K extends ParamKeys>({
options
);

const patchTestParameterWithBodyReferenceT: ReplaceRequestParams<
PatchTestParameterWithBodyReferenceT,
RequestParams<PatchTestParameterWithBodyReferenceT>
> = {
method: \\"patch\\",

headers: ({ [\\"customToken\\"]: customToken }) => ({
\\"custom-token\\": customToken,

\\"Content-Type\\": \\"application/json\\"
}),
response_decoder: patchTestParameterWithBodyReferenceDefaultDecoder(),
url: ({}) => \`\${basePath}/patch-test-parameter-with-body-ref\`,

body: ({ [\\"body\\"]: body }) =>
body?.constructor?.name === \\"Readable\\" ||
body?.constructor?.name === \\"ReadableStream\\"
? (body as ReadableStream)
: body?.constructor?.name === \\"Buffer\\"
? (body as Buffer)
: JSON.stringify(body),

query: () => withoutUndefinedValues({})
};
const patchTestParameterWithBodyReference: TypeofApiCall<PatchTestParameterWithBodyReferenceT> = createFetchRequestForApi(
patchTestParameterWithBodyReferenceT,
options
);

const testParameterWithDashT: ReplaceRequestParams<
TestParameterWithDashT,
RequestParams<TestParameterWithDashT>
Expand Down Expand Up @@ -3860,6 +3953,9 @@ export function createClient<K extends ParamKeys>({
putTestParameterWithBodyReference: (withDefaults || identity)(
putTestParameterWithBodyReference
),
patchTestParameterWithBodyReference: (withDefaults || identity)(
patchTestParameterWithBodyReference
),
testParameterWithDash: (withDefaults || identity)(testParameterWithDash),
testParameterWithDashAnUnderscore: (withDefaults || identity)(
testParameterWithDashAnUnderscore
Expand Down
26 changes: 26 additions & 0 deletions src/commands/gen-api-models/__tests__/parse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,32 @@ describe.each`
);
});

it("should parse a patch operation with body as ref", () => {
const parsed = getParser(spec).parseOperation(
//@ts-ignore
spec,
"/patch-test-parameter-with-body-ref",
[],
"undefined",
"undefined"
)("patch");

expect(parsed).toEqual(
expect.objectContaining({
method: "patch",
path: "/patch-test-parameter-with-body-ref",
consumes: "application/json",
parameters: expect.arrayContaining([
{
name: "body?",
in: "body",
type: "NewModel | ReadableStream<Uint8Array> | Buffer"
}
])
})
);
});

it("should parse an operation with header parameters", () => {
const parsed = getParser(spec).parseOperation(
//@ts-ignore
Expand Down
4 changes: 2 additions & 2 deletions src/commands/gen-api-models/parse.v3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ export const parseOperation = (
]
: [undefined, false];
const bodyParam: ReadonlyArray<IParameterInfo> =
["post", "put"].includes(method) && bodySchema
["patch", "post", "put"].includes(method) && bodySchema
? // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
"multipart/form-data" in operation?.requestBody?.content
Expand Down Expand Up @@ -398,7 +398,7 @@ export const parseOperation = (
];

const contentTypeHeaders =
(method === "post" || method === "put") &&
(method === "patch" || method === "post" || method === "put") &&
Object.keys([...operationParams, ...bodyParam]).length > 0
? ["Content-Type"]
: [];
Expand Down
2 changes: 1 addition & 1 deletion src/commands/gen-api-models/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export interface IGenerateApiOptions {
/**
* Supported http methods
*/
export type SupportedMethod = "get" | "post" | "put" | "delete";
export type SupportedMethod = "get" | "patch" | "post" | "put" | "delete";

export type SupportedAuthScheme = "bearer" | "digest" | "none";

Expand Down
Loading