From c8511e0d84dd408407bf764fb0bae4938b70dacb Mon Sep 17 00:00:00 2001 From: Lubos Date: Mon, 25 Nov 2024 16:58:27 +0800 Subject: [PATCH] fix: experimental parser exports reusable request bodies --- .changeset/poor-parrots-study.md | 5 + packages/openapi-ts/src/ir/context.ts | 6 + packages/openapi-ts/src/ir/ir.d.ts | 10 +- packages/openapi-ts/src/ir/operation.ts | 14 +- packages/openapi-ts/src/ir/parser.ts | 6 + .../src/openApi/3.0.x/parser/index.ts | 187 +++++++----------- .../src/openApi/3.0.x/parser/operation.ts | 47 +++-- .../src/openApi/3.0.x/parser/parameter.ts | 15 +- .../src/openApi/3.0.x/parser/requestBody.ts | 66 +++++++ .../src/openApi/3.1.x/parser/index.ts | 187 +++++++----------- .../src/openApi/3.1.x/parser/operation.ts | 26 +-- .../src/openApi/3.1.x/parser/parameter.ts | 15 +- .../src/openApi/3.1.x/parser/requestBody.ts | 66 +++++++ .../src/plugins/@hey-api/typescript/plugin.ts | 9 + packages/openapi-ts/src/utils/ref.ts | 2 +- packages/openapi-ts/test/3.0.x.test.ts | 7 + packages/openapi-ts/test/3.1.x.test.ts | 7 + .../3.0.x/components-request-bodies/index.ts | 2 + .../components-request-bodies/types.gen.ts | 23 +++ .../plugins/@hey-api/sdk/default/types.gen.ts | 8 +- .../asClass/types.gen.ts | 8 +- .../axios/types.gen.ts | 8 +- .../fetch/types.gen.ts | 8 +- .../react-query/asClass/types.gen.ts | 8 +- .../@tanstack/react-query/axios/types.gen.ts | 8 +- .../@tanstack/react-query/fetch/types.gen.ts | 8 +- .../solid-query/asClass/types.gen.ts | 8 +- .../@tanstack/solid-query/axios/types.gen.ts | 8 +- .../@tanstack/solid-query/fetch/types.gen.ts | 8 +- .../svelte-query/asClass/types.gen.ts | 8 +- .../@tanstack/svelte-query/axios/types.gen.ts | 8 +- .../@tanstack/svelte-query/fetch/types.gen.ts | 8 +- .../@tanstack/vue-query/asClass/types.gen.ts | 8 +- .../@tanstack/vue-query/axios/types.gen.ts | 8 +- .../@tanstack/vue-query/fetch/types.gen.ts | 8 +- .../plugins/fastify/default/types.gen.ts | 8 +- .../3.1.x/components-request-bodies/index.ts | 2 + .../components-request-bodies/types.gen.ts | 23 +++ .../plugins/@hey-api/sdk/default/types.gen.ts | 14 +- .../asClass/types.gen.ts | 14 +- .../axios/types.gen.ts | 14 +- .../fetch/types.gen.ts | 14 +- .../react-query/asClass/types.gen.ts | 14 +- .../@tanstack/react-query/axios/types.gen.ts | 14 +- .../@tanstack/react-query/fetch/types.gen.ts | 14 +- .../solid-query/asClass/types.gen.ts | 14 +- .../@tanstack/solid-query/axios/types.gen.ts | 14 +- .../@tanstack/solid-query/fetch/types.gen.ts | 14 +- .../svelte-query/asClass/types.gen.ts | 14 +- .../@tanstack/svelte-query/axios/types.gen.ts | 14 +- .../@tanstack/svelte-query/fetch/types.gen.ts | 14 +- .../@tanstack/vue-query/asClass/types.gen.ts | 14 +- .../@tanstack/vue-query/axios/types.gen.ts | 14 +- .../@tanstack/vue-query/fetch/types.gen.ts | 14 +- .../plugins/fastify/default/types.gen.ts | 14 +- packages/openapi-ts/test/sample.cjs | 6 +- .../spec/3.0.x/components-request-bodies.json | 41 ++++ .../spec/3.1.x/components-request-bodies.json | 41 ++++ 58 files changed, 849 insertions(+), 338 deletions(-) create mode 100644 .changeset/poor-parrots-study.md create mode 100644 packages/openapi-ts/src/openApi/3.0.x/parser/requestBody.ts create mode 100644 packages/openapi-ts/src/openApi/3.1.x/parser/requestBody.ts create mode 100644 packages/openapi-ts/test/__snapshots__/3.0.x/components-request-bodies/index.ts create mode 100644 packages/openapi-ts/test/__snapshots__/3.0.x/components-request-bodies/types.gen.ts create mode 100644 packages/openapi-ts/test/__snapshots__/3.1.x/components-request-bodies/index.ts create mode 100644 packages/openapi-ts/test/__snapshots__/3.1.x/components-request-bodies/types.gen.ts create mode 100644 packages/openapi-ts/test/spec/3.0.x/components-request-bodies.json create mode 100644 packages/openapi-ts/test/spec/3.1.x/components-request-bodies.json diff --git a/.changeset/poor-parrots-study.md b/.changeset/poor-parrots-study.md new file mode 100644 index 000000000..c1391242d --- /dev/null +++ b/.changeset/poor-parrots-study.md @@ -0,0 +1,5 @@ +--- +'@hey-api/openapi-ts': patch +--- + +fix: experimental parser exports reusable request bodies diff --git a/packages/openapi-ts/src/ir/context.ts b/packages/openapi-ts/src/ir/context.ts index 07c2152d6..a9def193e 100644 --- a/packages/openapi-ts/src/ir/context.ts +++ b/packages/openapi-ts/src/ir/context.ts @@ -9,6 +9,7 @@ import type { IROperationObject, IRParameterObject, IRPathItemObject, + IRRequestBodyObject, IRSchemaObject, } from './ir'; @@ -44,6 +45,11 @@ interface Events { name: string; parameter: IRParameterObject; }) => void; + requestBody: (args: { + $ref: string; + name: string; + requestBody: IRRequestBodyObject; + }) => void; schema: (args: { $ref: string; name: string; diff --git a/packages/openapi-ts/src/ir/ir.d.ts b/packages/openapi-ts/src/ir/ir.d.ts index f1bfaf60c..1e3f8e2bd 100644 --- a/packages/openapi-ts/src/ir/ir.d.ts +++ b/packages/openapi-ts/src/ir/ir.d.ts @@ -8,6 +8,7 @@ export interface IR { interface IRComponentsObject { parameters?: Record; + requestBodies?: Record; schemas?: Record; } @@ -61,7 +62,8 @@ export interface IRParametersObject { query?: Record; } -export interface IRParameterObject { +export interface IRParameterObject + extends Pick { /** * Determines whether the parameter value SHOULD allow reserved characters, as defined by RFC3986 `:/?#[]@!$&'()*+,;=` to be included without percent-encoding. The default value is `false`. This property SHALL be ignored if the request body media type is not `application/x-www-form-urlencoded` or `multipart/form-data`. If a value is explicitly defined, then the value of `contentType` (implicit or explicit) SHALL be ignored. */ @@ -95,6 +97,12 @@ export interface IRParameterObject { | 'spaceDelimited'; } +export interface IRRequestBodyObject + extends Pick { + required?: boolean; + schema: IRSchemaObject; +} + export interface IRResponsesObject { /** * Any {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#http-status-codes HTTP status code} can be used as the property name, but only one property per code, to describe the expected response for that HTTP status code. This field MUST be enclosed in quotation marks (for example, "200") for compatibility between JSON and YAML. To define a range of response codes, this field MAY contain the uppercase wildcard character `X`. For example, `2XX` represents all response codes between `[200-299]`. Only the following range definitions are allowed: `1XX`, `2XX`, `3XX`, `4XX`, and `5XX`. If a response is defined using an explicit code, the explicit code definition takes precedence over the range definition for that code. diff --git a/packages/openapi-ts/src/ir/operation.ts b/packages/openapi-ts/src/ir/operation.ts index 849dc51fe..ea08f553c 100644 --- a/packages/openapi-ts/src/ir/operation.ts +++ b/packages/openapi-ts/src/ir/operation.ts @@ -1,5 +1,10 @@ import type { IRContext } from './context'; -import type { IROperationObject, IRResponseObject, IRSchemaObject } from './ir'; +import type { IRRequestBodyObject } from './ir'; +import { + type IROperationObject, + type IRResponseObject, + type IRSchemaObject, +} from './ir'; import type { Pagination } from './pagination'; import { hasParametersObjectRequired, @@ -39,12 +44,15 @@ export const operationPagination = ({ } const schema = operation.body.schema.$ref - ? context.resolveIrRef(operation.body.schema.$ref) + ? context.resolveIrRef( + operation.body.schema.$ref, + ) : operation.body.schema; + const finalSchema = 'schema' in schema ? schema.schema : schema; return { in: 'body', name: operation.body.pagination, - schema: schema.properties![operation.body.pagination], + schema: finalSchema.properties![operation.body.pagination], }; } diff --git a/packages/openapi-ts/src/ir/parser.ts b/packages/openapi-ts/src/ir/parser.ts index ac02cb6f2..c4e9c28f2 100644 --- a/packages/openapi-ts/src/ir/parser.ts +++ b/packages/openapi-ts/src/ir/parser.ts @@ -20,6 +20,12 @@ export const parseIR = async ({ context }: { context: IRContext }) => { const $ref = `#/components/parameters/${name}`; await context.broadcast('parameter', { $ref, name, parameter }); } + + for (const name in context.ir.components.requestBodies) { + const requestBody = context.ir.components.requestBodies[name]; + const $ref = `#/components/requestBodies/${name}`; + await context.broadcast('requestBody', { $ref, name, requestBody }); + } } for (const path in context.ir.paths) { diff --git a/packages/openapi-ts/src/openApi/3.0.x/parser/index.ts b/packages/openapi-ts/src/openApi/3.0.x/parser/index.ts index cf8fe7b9e..dea7a78d7 100644 --- a/packages/openapi-ts/src/openApi/3.0.x/parser/index.ts +++ b/packages/openapi-ts/src/openApi/3.0.x/parser/index.ts @@ -5,6 +5,7 @@ import type { ParameterObject, PathItemObject, PathsObject, + RequestBodyObject, } from '../types/spec'; import { parseOperation } from './operation'; import { @@ -12,6 +13,7 @@ import { parametersArrayToObject, parseParameter, } from './parameter'; +import { parseRequestBody } from './requestBody'; import { parseSchema } from './schema'; export const parseV3_0_X = (context: IRContext) => { @@ -24,6 +26,70 @@ export const parseV3_0_X = (context: IRContext) => { ? new RegExp(context.config.input.include) : undefined; + const shouldProcessRef = ($ref: string) => + canProcessRef({ + $ref, + excludeRegExp, + includeRegExp, + }); + + // TODO: parser - handle more component types, old parser handles only parameters and schemas + if (context.spec.components) { + for (const name in context.spec.components.parameters) { + const $ref = `#/components/parameters/${name}`; + if (!shouldProcessRef($ref)) { + continue; + } + + const parameterOrReference = context.spec.components.parameters[name]; + const parameter = + '$ref' in parameterOrReference + ? context.resolveRef(parameterOrReference.$ref) + : parameterOrReference; + + parseParameter({ + $ref, + context, + parameter, + }); + } + + for (const name in context.spec.components.requestBodies) { + const $ref = `#/components/requestBodies/${name}`; + if (!shouldProcessRef($ref)) { + continue; + } + + const requestBodyOrReference = + context.spec.components.requestBodies[name]; + const requestBody = + '$ref' in requestBodyOrReference + ? context.resolveRef(requestBodyOrReference.$ref) + : requestBodyOrReference; + + parseRequestBody({ + $ref, + context, + requestBody, + }); + } + + for (const name in context.spec.components.schemas) { + const $ref = `#/components/schemas/${name}`; + if (!shouldProcessRef($ref)) { + continue; + } + + const schema = context.spec.components.schemas[name]; + + parseSchema({ + $ref, + context, + schema, + }); + } + } + for (const path in context.spec.paths) { const pathItem = context.spec.paths[path as keyof PathsObject]; @@ -59,14 +125,7 @@ export const parseV3_0_X = (context: IRContext) => { }; const $refDelete = `#/paths${path}/delete`; - if ( - finalPathItem.delete && - canProcessRef({ - $ref: $refDelete, - excludeRegExp, - includeRegExp, - }) - ) { + if (finalPathItem.delete && shouldProcessRef($refDelete)) { parseOperation({ ...operationArgs, method: 'delete', @@ -85,14 +144,7 @@ export const parseV3_0_X = (context: IRContext) => { } const $refGet = `#/paths${path}/get`; - if ( - finalPathItem.get && - canProcessRef({ - $ref: $refGet, - excludeRegExp, - includeRegExp, - }) - ) { + if (finalPathItem.get && shouldProcessRef($refGet)) { parseOperation({ ...operationArgs, method: 'get', @@ -111,14 +163,7 @@ export const parseV3_0_X = (context: IRContext) => { } const $refHead = `#/paths${path}/head`; - if ( - finalPathItem.head && - canProcessRef({ - $ref: $refHead, - excludeRegExp, - includeRegExp, - }) - ) { + if (finalPathItem.head && shouldProcessRef($refHead)) { parseOperation({ ...operationArgs, method: 'head', @@ -137,14 +182,7 @@ export const parseV3_0_X = (context: IRContext) => { } const $refOptions = `#/paths${path}/options`; - if ( - finalPathItem.options && - canProcessRef({ - $ref: $refOptions, - excludeRegExp, - includeRegExp, - }) - ) { + if (finalPathItem.options && shouldProcessRef($refOptions)) { parseOperation({ ...operationArgs, method: 'options', @@ -163,14 +201,7 @@ export const parseV3_0_X = (context: IRContext) => { } const $refPatch = `#/paths${path}/patch`; - if ( - finalPathItem.patch && - canProcessRef({ - $ref: $refPatch, - excludeRegExp, - includeRegExp, - }) - ) { + if (finalPathItem.patch && shouldProcessRef($refPatch)) { parseOperation({ ...operationArgs, method: 'patch', @@ -189,14 +220,7 @@ export const parseV3_0_X = (context: IRContext) => { } const $refPost = `#/paths${path}/post`; - if ( - finalPathItem.post && - canProcessRef({ - $ref: $refPost, - excludeRegExp, - includeRegExp, - }) - ) { + if (finalPathItem.post && shouldProcessRef($refPost)) { parseOperation({ ...operationArgs, method: 'post', @@ -215,14 +239,7 @@ export const parseV3_0_X = (context: IRContext) => { } const $refPut = `#/paths${path}/put`; - if ( - finalPathItem.put && - canProcessRef({ - $ref: $refPut, - excludeRegExp, - includeRegExp, - }) - ) { + if (finalPathItem.put && shouldProcessRef($refPut)) { parseOperation({ ...operationArgs, method: 'put', @@ -241,14 +258,7 @@ export const parseV3_0_X = (context: IRContext) => { } const $refTrace = `#/paths${path}/trace`; - if ( - finalPathItem.trace && - canProcessRef({ - $ref: $refTrace, - excludeRegExp, - includeRegExp, - }) - ) { + if (finalPathItem.trace && shouldProcessRef($refTrace)) { parseOperation({ ...operationArgs, method: 'trace', @@ -266,53 +276,4 @@ export const parseV3_0_X = (context: IRContext) => { }); } } - - // TODO: parser - handle more component types, old parser handles only parameters and schemas - if (context.spec.components) { - for (const name in context.spec.components.parameters) { - const $ref = `#/components/parameters/${name}`; - if ( - !canProcessRef({ - $ref, - excludeRegExp, - includeRegExp, - }) - ) { - continue; - } - - const parameterOrReference = context.spec.components.parameters[name]; - const parameter = - '$ref' in parameterOrReference - ? context.resolveRef(parameterOrReference.$ref) - : parameterOrReference; - - parseParameter({ - context, - name, - parameter, - }); - } - - for (const name in context.spec.components.schemas) { - const $ref = `#/components/schemas/${name}`; - if ( - !canProcessRef({ - $ref, - excludeRegExp, - includeRegExp, - }) - ) { - continue; - } - - const schema = context.spec.components.schemas[name]; - - parseSchema({ - $ref, - context, - schema, - }); - } - } }; diff --git a/packages/openapi-ts/src/openApi/3.0.x/parser/operation.ts b/packages/openapi-ts/src/openApi/3.0.x/parser/operation.ts index 06bf03fd9..ce8773d00 100644 --- a/packages/openapi-ts/src/openApi/3.0.x/parser/operation.ts +++ b/packages/openapi-ts/src/openApi/3.0.x/parser/operation.ts @@ -6,7 +6,6 @@ import type { PathItemObject, RequestBodyObject, ResponseObject, - SchemaObject, } from '../types/spec'; import { contentToSchema, mediaTypeObject } from './mediaType'; import { paginationField } from './pagination'; @@ -77,36 +76,48 @@ const operationToIrOperation = ({ } if (operation.requestBody) { - const requestBodyObject = + const requestBody = '$ref' in operation.requestBody ? context.resolveRef(operation.requestBody.$ref) : operation.requestBody; const content = mediaTypeObject({ - content: requestBodyObject.content, + content: requestBody.content, }); if (content) { - const finalSchema: SchemaObject = - content.schema && '$ref' in content.schema - ? { - allOf: [{ ...content.schema }], - description: requestBodyObject.description, - } - : { - description: requestBodyObject.description, - ...content.schema, - }; - const pagination = paginationField({ context, name: '', - schema: finalSchema, + schema: + content.schema && '$ref' in content.schema + ? { + allOf: [{ ...content.schema }], + description: requestBody.description, + } + : { + description: requestBody.description, + ...content.schema, + }, }); irOperation.body = { mediaType: content.mediaType, schema: schemaToIrSchema({ context, - schema: finalSchema, + schema: + '$ref' in operation.requestBody + ? { + allOf: [{ ...operation.requestBody }], + description: requestBody.description, + } + : content.schema && '$ref' in content.schema + ? { + allOf: [{ ...content.schema }], + description: requestBody.description, + } + : { + description: requestBody.description, + ...content.schema, + }, }), }; @@ -114,8 +125,8 @@ const operationToIrOperation = ({ irOperation.body.pagination = pagination; } - if (requestBodyObject.required) { - irOperation.body.required = requestBodyObject.required; + if (requestBody.required) { + irOperation.body.required = requestBody.required; } if (content.type) { diff --git a/packages/openapi-ts/src/openApi/3.0.x/parser/parameter.ts b/packages/openapi-ts/src/openApi/3.0.x/parser/parameter.ts index 7e24ec6bc..1905cfc9b 100644 --- a/packages/openapi-ts/src/openApi/3.0.x/parser/parameter.ts +++ b/packages/openapi-ts/src/openApi/3.0.x/parser/parameter.ts @@ -1,5 +1,6 @@ import type { IRContext } from '../../../ir/context'; import type { IRParameterObject, IRParametersObject } from '../../../ir/ir'; +import { refToName } from '../../../utils/ref'; import type { ParameterObject, ReferenceObject, @@ -207,6 +208,14 @@ const parameterToIrParameter = ({ style, }; + if (parameter.deprecated) { + irParameter.deprecated = parameter.deprecated; + } + + if (parameter.description) { + irParameter.description = parameter.description; + } + if (pagination) { irParameter.pagination = pagination; } @@ -219,12 +228,12 @@ const parameterToIrParameter = ({ }; export const parseParameter = ({ + $ref, context, - name, parameter, }: { + $ref: string; context: IRContext; - name: string; parameter: ParameterObject; }) => { if (!context.ir.components) { @@ -235,7 +244,7 @@ export const parseParameter = ({ context.ir.components.parameters = {}; } - context.ir.components.parameters[name] = parameterToIrParameter({ + context.ir.components.parameters[refToName($ref)] = parameterToIrParameter({ context, parameter, }); diff --git a/packages/openapi-ts/src/openApi/3.0.x/parser/requestBody.ts b/packages/openapi-ts/src/openApi/3.0.x/parser/requestBody.ts new file mode 100644 index 000000000..1ddcdadb4 --- /dev/null +++ b/packages/openapi-ts/src/openApi/3.0.x/parser/requestBody.ts @@ -0,0 +1,66 @@ +import type { IRContext } from '../../../ir/context'; +import type { IRRequestBodyObject } from '../../../ir/ir'; +import { refToName } from '../../../utils/ref'; +import type { RequestBodyObject, SchemaObject } from '../types/spec'; +import { mediaTypeObject } from './mediaType'; +import { schemaToIrSchema } from './schema'; + +const requestBodyToIrRequestBody = ({ + context, + requestBody, +}: { + context: IRContext; + requestBody: RequestBodyObject; +}): IRRequestBodyObject => { + // TODO: parser - fix + const content = mediaTypeObject({ + content: requestBody.content, + }); + const schema = content ? content.schema : undefined; + + const finalSchema: SchemaObject = { + description: requestBody.description, + ...schema, + }; + + const irRequestBody: IRRequestBodyObject = { + schema: schemaToIrSchema({ + context, + schema: finalSchema, + }), + }; + + if (requestBody.description) { + irRequestBody.description = requestBody.description; + } + + if (requestBody.required) { + irRequestBody.required = requestBody.required; + } + + return irRequestBody; +}; + +export const parseRequestBody = ({ + $ref, + context, + requestBody, +}: { + $ref: string; + context: IRContext; + requestBody: RequestBodyObject; +}) => { + if (!context.ir.components) { + context.ir.components = {}; + } + + if (!context.ir.components.requestBodies) { + context.ir.components.requestBodies = {}; + } + + context.ir.components.requestBodies[refToName($ref)] = + requestBodyToIrRequestBody({ + context, + requestBody, + }); +}; diff --git a/packages/openapi-ts/src/openApi/3.1.x/parser/index.ts b/packages/openapi-ts/src/openApi/3.1.x/parser/index.ts index 1b4f40fda..e0005a819 100644 --- a/packages/openapi-ts/src/openApi/3.1.x/parser/index.ts +++ b/packages/openapi-ts/src/openApi/3.1.x/parser/index.ts @@ -5,6 +5,7 @@ import type { ParameterObject, PathItemObject, PathsObject, + RequestBodyObject, } from '../types/spec'; import { parseOperation } from './operation'; import { @@ -12,6 +13,7 @@ import { parametersArrayToObject, parseParameter, } from './parameter'; +import { parseRequestBody } from './requestBody'; import { parseSchema } from './schema'; export const parseV3_1_X = (context: IRContext) => { @@ -24,6 +26,70 @@ export const parseV3_1_X = (context: IRContext) => { ? new RegExp(context.config.input.include) : undefined; + const shouldProcessRef = ($ref: string) => + canProcessRef({ + $ref, + excludeRegExp, + includeRegExp, + }); + + // TODO: parser - handle more component types, old parser handles only parameters and schemas + if (context.spec.components) { + for (const name in context.spec.components.parameters) { + const $ref = `#/components/parameters/${name}`; + if (!shouldProcessRef($ref)) { + continue; + } + + const parameterOrReference = context.spec.components.parameters[name]; + const parameter = + '$ref' in parameterOrReference + ? context.resolveRef(parameterOrReference.$ref) + : parameterOrReference; + + parseParameter({ + $ref, + context, + parameter, + }); + } + + for (const name in context.spec.components.requestBodies) { + const $ref = `#/components/requestBodies/${name}`; + if (!shouldProcessRef($ref)) { + continue; + } + + const requestBodyOrReference = + context.spec.components.requestBodies[name]; + const requestBody = + '$ref' in requestBodyOrReference + ? context.resolveRef(requestBodyOrReference.$ref) + : requestBodyOrReference; + + parseRequestBody({ + $ref, + context, + requestBody, + }); + } + + for (const name in context.spec.components.schemas) { + const $ref = `#/components/schemas/${name}`; + if (!shouldProcessRef($ref)) { + continue; + } + + const schema = context.spec.components.schemas[name]; + + parseSchema({ + $ref, + context, + schema, + }); + } + } + for (const path in context.spec.paths) { const pathItem = context.spec.paths[path as keyof PathsObject]; @@ -52,14 +118,7 @@ export const parseV3_1_X = (context: IRContext) => { }; const $refDelete = `#/paths${path}/delete`; - if ( - finalPathItem.delete && - canProcessRef({ - $ref: $refDelete, - excludeRegExp, - includeRegExp, - }) - ) { + if (finalPathItem.delete && shouldProcessRef($refDelete)) { parseOperation({ ...operationArgs, method: 'delete', @@ -78,14 +137,7 @@ export const parseV3_1_X = (context: IRContext) => { } const $refGet = `#/paths${path}/get`; - if ( - finalPathItem.get && - canProcessRef({ - $ref: $refGet, - excludeRegExp, - includeRegExp, - }) - ) { + if (finalPathItem.get && shouldProcessRef($refGet)) { parseOperation({ ...operationArgs, method: 'get', @@ -104,14 +156,7 @@ export const parseV3_1_X = (context: IRContext) => { } const $refHead = `#/paths${path}/head`; - if ( - finalPathItem.head && - canProcessRef({ - $ref: $refHead, - excludeRegExp, - includeRegExp, - }) - ) { + if (finalPathItem.head && shouldProcessRef($refHead)) { parseOperation({ ...operationArgs, method: 'head', @@ -130,14 +175,7 @@ export const parseV3_1_X = (context: IRContext) => { } const $refOptions = `#/paths${path}/options`; - if ( - finalPathItem.options && - canProcessRef({ - $ref: $refOptions, - excludeRegExp, - includeRegExp, - }) - ) { + if (finalPathItem.options && shouldProcessRef($refOptions)) { parseOperation({ ...operationArgs, method: 'options', @@ -156,14 +194,7 @@ export const parseV3_1_X = (context: IRContext) => { } const $refPatch = `#/paths${path}/patch`; - if ( - finalPathItem.patch && - canProcessRef({ - $ref: $refPatch, - excludeRegExp, - includeRegExp, - }) - ) { + if (finalPathItem.patch && shouldProcessRef($refPatch)) { parseOperation({ ...operationArgs, method: 'patch', @@ -182,14 +213,7 @@ export const parseV3_1_X = (context: IRContext) => { } const $refPost = `#/paths${path}/post`; - if ( - finalPathItem.post && - canProcessRef({ - $ref: $refPost, - excludeRegExp, - includeRegExp, - }) - ) { + if (finalPathItem.post && shouldProcessRef($refPost)) { parseOperation({ ...operationArgs, method: 'post', @@ -208,14 +232,7 @@ export const parseV3_1_X = (context: IRContext) => { } const $refPut = `#/paths${path}/put`; - if ( - finalPathItem.put && - canProcessRef({ - $ref: $refPut, - excludeRegExp, - includeRegExp, - }) - ) { + if (finalPathItem.put && shouldProcessRef($refPut)) { parseOperation({ ...operationArgs, method: 'put', @@ -234,14 +251,7 @@ export const parseV3_1_X = (context: IRContext) => { } const $refTrace = `#/paths${path}/trace`; - if ( - finalPathItem.trace && - canProcessRef({ - $ref: $refTrace, - excludeRegExp, - includeRegExp, - }) - ) { + if (finalPathItem.trace && shouldProcessRef($refTrace)) { parseOperation({ ...operationArgs, method: 'trace', @@ -259,53 +269,4 @@ export const parseV3_1_X = (context: IRContext) => { }); } } - - // TODO: parser - handle more component types, old parser handles only parameters and schemas - if (context.spec.components) { - for (const name in context.spec.components.parameters) { - const $ref = `#/components/parameters/${name}`; - if ( - !canProcessRef({ - $ref, - excludeRegExp, - includeRegExp, - }) - ) { - continue; - } - - const parameterOrReference = context.spec.components.parameters[name]; - const parameter = - '$ref' in parameterOrReference - ? context.resolveRef(parameterOrReference.$ref) - : parameterOrReference; - - parseParameter({ - context, - name, - parameter, - }); - } - - for (const name in context.spec.components.schemas) { - const $ref = `#/components/schemas/${name}`; - if ( - !canProcessRef({ - $ref, - excludeRegExp, - includeRegExp, - }) - ) { - continue; - } - - const schema = context.spec.components.schemas[name]; - - parseSchema({ - $ref, - context, - schema, - }); - } - } }; diff --git a/packages/openapi-ts/src/openApi/3.1.x/parser/operation.ts b/packages/openapi-ts/src/openApi/3.1.x/parser/operation.ts index 492b3c61c..b9bb868db 100644 --- a/packages/openapi-ts/src/openApi/3.1.x/parser/operation.ts +++ b/packages/openapi-ts/src/openApi/3.1.x/parser/operation.ts @@ -6,7 +6,6 @@ import type { PathItemObject, RequestBodyObject, ResponseObject, - SchemaObject, } from '../types/spec'; import { contentToSchema, mediaTypeObject } from './mediaType'; import { paginationField } from './pagination'; @@ -77,30 +76,33 @@ const operationToIrOperation = ({ } if (operation.requestBody) { - const requestBodyObject = + const requestBody = '$ref' in operation.requestBody ? context.resolveRef(operation.requestBody.$ref) : operation.requestBody; const content = mediaTypeObject({ - content: requestBodyObject.content, + content: requestBody.content, }); if (content) { - const finalSchema: SchemaObject = { - description: requestBodyObject.description, - ...content.schema, - }; - const pagination = paginationField({ context, name: '', - schema: finalSchema, + schema: { + description: requestBody.description, + ...content.schema, + }, }); irOperation.body = { mediaType: content.mediaType, schema: schemaToIrSchema({ context, - schema: finalSchema, + schema: { + description: requestBody.description, + ...('$ref' in operation.requestBody + ? operation.requestBody + : content.schema), + }, }), }; @@ -108,8 +110,8 @@ const operationToIrOperation = ({ irOperation.body.pagination = pagination; } - if (requestBodyObject.required) { - irOperation.body.required = requestBodyObject.required; + if (requestBody.required) { + irOperation.body.required = requestBody.required; } if (content.type) { diff --git a/packages/openapi-ts/src/openApi/3.1.x/parser/parameter.ts b/packages/openapi-ts/src/openApi/3.1.x/parser/parameter.ts index 78d4e19c7..a89366596 100644 --- a/packages/openapi-ts/src/openApi/3.1.x/parser/parameter.ts +++ b/packages/openapi-ts/src/openApi/3.1.x/parser/parameter.ts @@ -1,5 +1,6 @@ import type { IRContext } from '../../../ir/context'; import type { IRParameterObject, IRParametersObject } from '../../../ir/ir'; +import { refToName } from '../../../utils/ref'; import type { ParameterObject, ReferenceObject, @@ -200,6 +201,14 @@ const parameterToIrParameter = ({ style, }; + if (parameter.deprecated) { + irParameter.deprecated = parameter.deprecated; + } + + if (parameter.description) { + irParameter.description = parameter.description; + } + if (pagination) { irParameter.pagination = pagination; } @@ -212,12 +221,12 @@ const parameterToIrParameter = ({ }; export const parseParameter = ({ + $ref, context, - name, parameter, }: { + $ref: string; context: IRContext; - name: string; parameter: ParameterObject; }) => { if (!context.ir.components) { @@ -228,7 +237,7 @@ export const parseParameter = ({ context.ir.components.parameters = {}; } - context.ir.components.parameters[name] = parameterToIrParameter({ + context.ir.components.parameters[refToName($ref)] = parameterToIrParameter({ context, parameter, }); diff --git a/packages/openapi-ts/src/openApi/3.1.x/parser/requestBody.ts b/packages/openapi-ts/src/openApi/3.1.x/parser/requestBody.ts new file mode 100644 index 000000000..1ddcdadb4 --- /dev/null +++ b/packages/openapi-ts/src/openApi/3.1.x/parser/requestBody.ts @@ -0,0 +1,66 @@ +import type { IRContext } from '../../../ir/context'; +import type { IRRequestBodyObject } from '../../../ir/ir'; +import { refToName } from '../../../utils/ref'; +import type { RequestBodyObject, SchemaObject } from '../types/spec'; +import { mediaTypeObject } from './mediaType'; +import { schemaToIrSchema } from './schema'; + +const requestBodyToIrRequestBody = ({ + context, + requestBody, +}: { + context: IRContext; + requestBody: RequestBodyObject; +}): IRRequestBodyObject => { + // TODO: parser - fix + const content = mediaTypeObject({ + content: requestBody.content, + }); + const schema = content ? content.schema : undefined; + + const finalSchema: SchemaObject = { + description: requestBody.description, + ...schema, + }; + + const irRequestBody: IRRequestBodyObject = { + schema: schemaToIrSchema({ + context, + schema: finalSchema, + }), + }; + + if (requestBody.description) { + irRequestBody.description = requestBody.description; + } + + if (requestBody.required) { + irRequestBody.required = requestBody.required; + } + + return irRequestBody; +}; + +export const parseRequestBody = ({ + $ref, + context, + requestBody, +}: { + $ref: string; + context: IRContext; + requestBody: RequestBodyObject; +}) => { + if (!context.ir.components) { + context.ir.components = {}; + } + + if (!context.ir.components.requestBodies) { + context.ir.components.requestBodies = {}; + } + + context.ir.components.requestBodies[refToName($ref)] = + requestBodyToIrRequestBody({ + context, + requestBody, + }); +}; diff --git a/packages/openapi-ts/src/plugins/@hey-api/typescript/plugin.ts b/packages/openapi-ts/src/plugins/@hey-api/typescript/plugin.ts index 07651513d..7fbd53476 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/typescript/plugin.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/typescript/plugin.ts @@ -1010,6 +1010,15 @@ export const handler: PluginHandler = ({ context, plugin }) => { }); }); + context.subscribe('requestBody', ({ $ref, requestBody }) => { + schemaToType({ + $ref, + context, + plugin, + schema: requestBody.schema, + }); + }); + context.subscribe('operation', ({ operation }) => { operationToType({ context, diff --git a/packages/openapi-ts/src/utils/ref.ts b/packages/openapi-ts/src/utils/ref.ts index b48909569..0a8ed840b 100644 --- a/packages/openapi-ts/src/utils/ref.ts +++ b/packages/openapi-ts/src/utils/ref.ts @@ -7,7 +7,7 @@ export const isRefOpenApiComponent = ($ref: string): boolean => { }; /** - * Returns the component name from `$ref`. + * Returns the reusable component name from `$ref`. */ export const refToName = ($ref: string): string => { const parts = refToParts($ref); diff --git a/packages/openapi-ts/test/3.0.x.test.ts b/packages/openapi-ts/test/3.0.x.test.ts index 26112feba..a76f9c862 100644 --- a/packages/openapi-ts/test/3.0.x.test.ts +++ b/packages/openapi-ts/test/3.0.x.test.ts @@ -56,6 +56,13 @@ describe(`OpenAPI ${VERSION}`, () => { description: 'generates correct array when items are oneOf array with single item', }, + { + config: createConfig({ + input: 'components-request-bodies.json', + output: 'components-request-bodies', + }), + description: 'handles reusable request bodies', + }, { config: createConfig({ input: 'content-binary.json', diff --git a/packages/openapi-ts/test/3.1.x.test.ts b/packages/openapi-ts/test/3.1.x.test.ts index 119c49397..51c724443 100644 --- a/packages/openapi-ts/test/3.1.x.test.ts +++ b/packages/openapi-ts/test/3.1.x.test.ts @@ -56,6 +56,13 @@ describe(`OpenAPI ${VERSION}`, () => { description: 'generates correct array when items are oneOf array with single item', }, + { + config: createConfig({ + input: 'components-request-bodies.json', + output: 'components-request-bodies', + }), + description: 'handles reusable request bodies', + }, { config: createConfig({ input: 'const.json', diff --git a/packages/openapi-ts/test/__snapshots__/3.0.x/components-request-bodies/index.ts b/packages/openapi-ts/test/__snapshots__/3.0.x/components-request-bodies/index.ts new file mode 100644 index 000000000..56bade120 --- /dev/null +++ b/packages/openapi-ts/test/__snapshots__/3.0.x/components-request-bodies/index.ts @@ -0,0 +1,2 @@ +// This file is auto-generated by @hey-api/openapi-ts +export * from './types.gen'; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/3.0.x/components-request-bodies/types.gen.ts b/packages/openapi-ts/test/__snapshots__/3.0.x/components-request-bodies/types.gen.ts new file mode 100644 index 000000000..affd48330 --- /dev/null +++ b/packages/openapi-ts/test/__snapshots__/3.0.x/components-request-bodies/types.gen.ts @@ -0,0 +1,23 @@ +// This file is auto-generated by @hey-api/openapi-ts + +/** + * Foo + */ +export type Foo = { + page?: number; +}; + +export type PostFooData = { + /** + * Foo + */ + body: Foo; + url: '/foo'; +}; + +export type PostFooResponses = { + /** + * OK + */ + 200: unknown; +}; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/@hey-api/sdk/default/types.gen.ts b/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/@hey-api/sdk/default/types.gen.ts index 4dbfcab02..0dd092930 100644 --- a/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/@hey-api/sdk/default/types.gen.ts +++ b/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/@hey-api/sdk/default/types.gen.ts @@ -943,6 +943,10 @@ export type SimpleParameter = string; */ export type x_Foo_Bar = ModelWithString; +export type SimpleRequestBody = ModelWithString; + +export type SimpleFormData = ModelWithString; + export type ExportData = { body?: never; url: '/api/v{api-version}/no-tag'; @@ -1239,7 +1243,7 @@ export type PostApiVbyApiVersionRequestBodyData = { /** * A reusable request body */ - body?: ModelWithString; + body?: SimpleRequestBody; path?: never; query?: { /** @@ -1254,7 +1258,7 @@ export type PostApiVbyApiVersionFormDataData = { /** * A reusable request body */ - body?: ModelWithString; + body?: SimpleFormData; path?: never; query?: { /** diff --git a/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/asClass/types.gen.ts b/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/asClass/types.gen.ts index 4dbfcab02..0dd092930 100644 --- a/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/asClass/types.gen.ts +++ b/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/asClass/types.gen.ts @@ -943,6 +943,10 @@ export type SimpleParameter = string; */ export type x_Foo_Bar = ModelWithString; +export type SimpleRequestBody = ModelWithString; + +export type SimpleFormData = ModelWithString; + export type ExportData = { body?: never; url: '/api/v{api-version}/no-tag'; @@ -1239,7 +1243,7 @@ export type PostApiVbyApiVersionRequestBodyData = { /** * A reusable request body */ - body?: ModelWithString; + body?: SimpleRequestBody; path?: never; query?: { /** @@ -1254,7 +1258,7 @@ export type PostApiVbyApiVersionFormDataData = { /** * A reusable request body */ - body?: ModelWithString; + body?: SimpleFormData; path?: never; query?: { /** diff --git a/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/axios/types.gen.ts b/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/axios/types.gen.ts index 4dbfcab02..0dd092930 100644 --- a/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/axios/types.gen.ts +++ b/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/axios/types.gen.ts @@ -943,6 +943,10 @@ export type SimpleParameter = string; */ export type x_Foo_Bar = ModelWithString; +export type SimpleRequestBody = ModelWithString; + +export type SimpleFormData = ModelWithString; + export type ExportData = { body?: never; url: '/api/v{api-version}/no-tag'; @@ -1239,7 +1243,7 @@ export type PostApiVbyApiVersionRequestBodyData = { /** * A reusable request body */ - body?: ModelWithString; + body?: SimpleRequestBody; path?: never; query?: { /** @@ -1254,7 +1258,7 @@ export type PostApiVbyApiVersionFormDataData = { /** * A reusable request body */ - body?: ModelWithString; + body?: SimpleFormData; path?: never; query?: { /** diff --git a/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/fetch/types.gen.ts b/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/fetch/types.gen.ts index 4dbfcab02..0dd092930 100644 --- a/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/fetch/types.gen.ts +++ b/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/fetch/types.gen.ts @@ -943,6 +943,10 @@ export type SimpleParameter = string; */ export type x_Foo_Bar = ModelWithString; +export type SimpleRequestBody = ModelWithString; + +export type SimpleFormData = ModelWithString; + export type ExportData = { body?: never; url: '/api/v{api-version}/no-tag'; @@ -1239,7 +1243,7 @@ export type PostApiVbyApiVersionRequestBodyData = { /** * A reusable request body */ - body?: ModelWithString; + body?: SimpleRequestBody; path?: never; query?: { /** @@ -1254,7 +1258,7 @@ export type PostApiVbyApiVersionFormDataData = { /** * A reusable request body */ - body?: ModelWithString; + body?: SimpleFormData; path?: never; query?: { /** diff --git a/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/asClass/types.gen.ts b/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/asClass/types.gen.ts index 4dbfcab02..0dd092930 100644 --- a/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/asClass/types.gen.ts +++ b/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/asClass/types.gen.ts @@ -943,6 +943,10 @@ export type SimpleParameter = string; */ export type x_Foo_Bar = ModelWithString; +export type SimpleRequestBody = ModelWithString; + +export type SimpleFormData = ModelWithString; + export type ExportData = { body?: never; url: '/api/v{api-version}/no-tag'; @@ -1239,7 +1243,7 @@ export type PostApiVbyApiVersionRequestBodyData = { /** * A reusable request body */ - body?: ModelWithString; + body?: SimpleRequestBody; path?: never; query?: { /** @@ -1254,7 +1258,7 @@ export type PostApiVbyApiVersionFormDataData = { /** * A reusable request body */ - body?: ModelWithString; + body?: SimpleFormData; path?: never; query?: { /** diff --git a/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/axios/types.gen.ts b/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/axios/types.gen.ts index 4dbfcab02..0dd092930 100644 --- a/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/axios/types.gen.ts +++ b/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/axios/types.gen.ts @@ -943,6 +943,10 @@ export type SimpleParameter = string; */ export type x_Foo_Bar = ModelWithString; +export type SimpleRequestBody = ModelWithString; + +export type SimpleFormData = ModelWithString; + export type ExportData = { body?: never; url: '/api/v{api-version}/no-tag'; @@ -1239,7 +1243,7 @@ export type PostApiVbyApiVersionRequestBodyData = { /** * A reusable request body */ - body?: ModelWithString; + body?: SimpleRequestBody; path?: never; query?: { /** @@ -1254,7 +1258,7 @@ export type PostApiVbyApiVersionFormDataData = { /** * A reusable request body */ - body?: ModelWithString; + body?: SimpleFormData; path?: never; query?: { /** diff --git a/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/fetch/types.gen.ts b/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/fetch/types.gen.ts index 4dbfcab02..0dd092930 100644 --- a/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/fetch/types.gen.ts +++ b/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/fetch/types.gen.ts @@ -943,6 +943,10 @@ export type SimpleParameter = string; */ export type x_Foo_Bar = ModelWithString; +export type SimpleRequestBody = ModelWithString; + +export type SimpleFormData = ModelWithString; + export type ExportData = { body?: never; url: '/api/v{api-version}/no-tag'; @@ -1239,7 +1243,7 @@ export type PostApiVbyApiVersionRequestBodyData = { /** * A reusable request body */ - body?: ModelWithString; + body?: SimpleRequestBody; path?: never; query?: { /** @@ -1254,7 +1258,7 @@ export type PostApiVbyApiVersionFormDataData = { /** * A reusable request body */ - body?: ModelWithString; + body?: SimpleFormData; path?: never; query?: { /** diff --git a/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/asClass/types.gen.ts b/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/asClass/types.gen.ts index 4dbfcab02..0dd092930 100644 --- a/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/asClass/types.gen.ts +++ b/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/asClass/types.gen.ts @@ -943,6 +943,10 @@ export type SimpleParameter = string; */ export type x_Foo_Bar = ModelWithString; +export type SimpleRequestBody = ModelWithString; + +export type SimpleFormData = ModelWithString; + export type ExportData = { body?: never; url: '/api/v{api-version}/no-tag'; @@ -1239,7 +1243,7 @@ export type PostApiVbyApiVersionRequestBodyData = { /** * A reusable request body */ - body?: ModelWithString; + body?: SimpleRequestBody; path?: never; query?: { /** @@ -1254,7 +1258,7 @@ export type PostApiVbyApiVersionFormDataData = { /** * A reusable request body */ - body?: ModelWithString; + body?: SimpleFormData; path?: never; query?: { /** diff --git a/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/axios/types.gen.ts b/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/axios/types.gen.ts index 4dbfcab02..0dd092930 100644 --- a/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/axios/types.gen.ts +++ b/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/axios/types.gen.ts @@ -943,6 +943,10 @@ export type SimpleParameter = string; */ export type x_Foo_Bar = ModelWithString; +export type SimpleRequestBody = ModelWithString; + +export type SimpleFormData = ModelWithString; + export type ExportData = { body?: never; url: '/api/v{api-version}/no-tag'; @@ -1239,7 +1243,7 @@ export type PostApiVbyApiVersionRequestBodyData = { /** * A reusable request body */ - body?: ModelWithString; + body?: SimpleRequestBody; path?: never; query?: { /** @@ -1254,7 +1258,7 @@ export type PostApiVbyApiVersionFormDataData = { /** * A reusable request body */ - body?: ModelWithString; + body?: SimpleFormData; path?: never; query?: { /** diff --git a/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/fetch/types.gen.ts b/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/fetch/types.gen.ts index 4dbfcab02..0dd092930 100644 --- a/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/fetch/types.gen.ts +++ b/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/fetch/types.gen.ts @@ -943,6 +943,10 @@ export type SimpleParameter = string; */ export type x_Foo_Bar = ModelWithString; +export type SimpleRequestBody = ModelWithString; + +export type SimpleFormData = ModelWithString; + export type ExportData = { body?: never; url: '/api/v{api-version}/no-tag'; @@ -1239,7 +1243,7 @@ export type PostApiVbyApiVersionRequestBodyData = { /** * A reusable request body */ - body?: ModelWithString; + body?: SimpleRequestBody; path?: never; query?: { /** @@ -1254,7 +1258,7 @@ export type PostApiVbyApiVersionFormDataData = { /** * A reusable request body */ - body?: ModelWithString; + body?: SimpleFormData; path?: never; query?: { /** diff --git a/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/asClass/types.gen.ts b/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/asClass/types.gen.ts index 4dbfcab02..0dd092930 100644 --- a/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/asClass/types.gen.ts +++ b/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/asClass/types.gen.ts @@ -943,6 +943,10 @@ export type SimpleParameter = string; */ export type x_Foo_Bar = ModelWithString; +export type SimpleRequestBody = ModelWithString; + +export type SimpleFormData = ModelWithString; + export type ExportData = { body?: never; url: '/api/v{api-version}/no-tag'; @@ -1239,7 +1243,7 @@ export type PostApiVbyApiVersionRequestBodyData = { /** * A reusable request body */ - body?: ModelWithString; + body?: SimpleRequestBody; path?: never; query?: { /** @@ -1254,7 +1258,7 @@ export type PostApiVbyApiVersionFormDataData = { /** * A reusable request body */ - body?: ModelWithString; + body?: SimpleFormData; path?: never; query?: { /** diff --git a/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/axios/types.gen.ts b/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/axios/types.gen.ts index 4dbfcab02..0dd092930 100644 --- a/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/axios/types.gen.ts +++ b/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/axios/types.gen.ts @@ -943,6 +943,10 @@ export type SimpleParameter = string; */ export type x_Foo_Bar = ModelWithString; +export type SimpleRequestBody = ModelWithString; + +export type SimpleFormData = ModelWithString; + export type ExportData = { body?: never; url: '/api/v{api-version}/no-tag'; @@ -1239,7 +1243,7 @@ export type PostApiVbyApiVersionRequestBodyData = { /** * A reusable request body */ - body?: ModelWithString; + body?: SimpleRequestBody; path?: never; query?: { /** @@ -1254,7 +1258,7 @@ export type PostApiVbyApiVersionFormDataData = { /** * A reusable request body */ - body?: ModelWithString; + body?: SimpleFormData; path?: never; query?: { /** diff --git a/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/fetch/types.gen.ts b/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/fetch/types.gen.ts index 4dbfcab02..0dd092930 100644 --- a/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/fetch/types.gen.ts +++ b/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/fetch/types.gen.ts @@ -943,6 +943,10 @@ export type SimpleParameter = string; */ export type x_Foo_Bar = ModelWithString; +export type SimpleRequestBody = ModelWithString; + +export type SimpleFormData = ModelWithString; + export type ExportData = { body?: never; url: '/api/v{api-version}/no-tag'; @@ -1239,7 +1243,7 @@ export type PostApiVbyApiVersionRequestBodyData = { /** * A reusable request body */ - body?: ModelWithString; + body?: SimpleRequestBody; path?: never; query?: { /** @@ -1254,7 +1258,7 @@ export type PostApiVbyApiVersionFormDataData = { /** * A reusable request body */ - body?: ModelWithString; + body?: SimpleFormData; path?: never; query?: { /** diff --git a/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/asClass/types.gen.ts b/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/asClass/types.gen.ts index 4dbfcab02..0dd092930 100644 --- a/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/asClass/types.gen.ts +++ b/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/asClass/types.gen.ts @@ -943,6 +943,10 @@ export type SimpleParameter = string; */ export type x_Foo_Bar = ModelWithString; +export type SimpleRequestBody = ModelWithString; + +export type SimpleFormData = ModelWithString; + export type ExportData = { body?: never; url: '/api/v{api-version}/no-tag'; @@ -1239,7 +1243,7 @@ export type PostApiVbyApiVersionRequestBodyData = { /** * A reusable request body */ - body?: ModelWithString; + body?: SimpleRequestBody; path?: never; query?: { /** @@ -1254,7 +1258,7 @@ export type PostApiVbyApiVersionFormDataData = { /** * A reusable request body */ - body?: ModelWithString; + body?: SimpleFormData; path?: never; query?: { /** diff --git a/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/axios/types.gen.ts b/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/axios/types.gen.ts index 4dbfcab02..0dd092930 100644 --- a/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/axios/types.gen.ts +++ b/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/axios/types.gen.ts @@ -943,6 +943,10 @@ export type SimpleParameter = string; */ export type x_Foo_Bar = ModelWithString; +export type SimpleRequestBody = ModelWithString; + +export type SimpleFormData = ModelWithString; + export type ExportData = { body?: never; url: '/api/v{api-version}/no-tag'; @@ -1239,7 +1243,7 @@ export type PostApiVbyApiVersionRequestBodyData = { /** * A reusable request body */ - body?: ModelWithString; + body?: SimpleRequestBody; path?: never; query?: { /** @@ -1254,7 +1258,7 @@ export type PostApiVbyApiVersionFormDataData = { /** * A reusable request body */ - body?: ModelWithString; + body?: SimpleFormData; path?: never; query?: { /** diff --git a/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/fetch/types.gen.ts b/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/fetch/types.gen.ts index 4dbfcab02..0dd092930 100644 --- a/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/fetch/types.gen.ts +++ b/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/fetch/types.gen.ts @@ -943,6 +943,10 @@ export type SimpleParameter = string; */ export type x_Foo_Bar = ModelWithString; +export type SimpleRequestBody = ModelWithString; + +export type SimpleFormData = ModelWithString; + export type ExportData = { body?: never; url: '/api/v{api-version}/no-tag'; @@ -1239,7 +1243,7 @@ export type PostApiVbyApiVersionRequestBodyData = { /** * A reusable request body */ - body?: ModelWithString; + body?: SimpleRequestBody; path?: never; query?: { /** @@ -1254,7 +1258,7 @@ export type PostApiVbyApiVersionFormDataData = { /** * A reusable request body */ - body?: ModelWithString; + body?: SimpleFormData; path?: never; query?: { /** diff --git a/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/fastify/default/types.gen.ts b/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/fastify/default/types.gen.ts index 4dbfcab02..0dd092930 100644 --- a/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/fastify/default/types.gen.ts +++ b/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/fastify/default/types.gen.ts @@ -943,6 +943,10 @@ export type SimpleParameter = string; */ export type x_Foo_Bar = ModelWithString; +export type SimpleRequestBody = ModelWithString; + +export type SimpleFormData = ModelWithString; + export type ExportData = { body?: never; url: '/api/v{api-version}/no-tag'; @@ -1239,7 +1243,7 @@ export type PostApiVbyApiVersionRequestBodyData = { /** * A reusable request body */ - body?: ModelWithString; + body?: SimpleRequestBody; path?: never; query?: { /** @@ -1254,7 +1258,7 @@ export type PostApiVbyApiVersionFormDataData = { /** * A reusable request body */ - body?: ModelWithString; + body?: SimpleFormData; path?: never; query?: { /** diff --git a/packages/openapi-ts/test/__snapshots__/3.1.x/components-request-bodies/index.ts b/packages/openapi-ts/test/__snapshots__/3.1.x/components-request-bodies/index.ts new file mode 100644 index 000000000..56bade120 --- /dev/null +++ b/packages/openapi-ts/test/__snapshots__/3.1.x/components-request-bodies/index.ts @@ -0,0 +1,2 @@ +// This file is auto-generated by @hey-api/openapi-ts +export * from './types.gen'; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/3.1.x/components-request-bodies/types.gen.ts b/packages/openapi-ts/test/__snapshots__/3.1.x/components-request-bodies/types.gen.ts new file mode 100644 index 000000000..affd48330 --- /dev/null +++ b/packages/openapi-ts/test/__snapshots__/3.1.x/components-request-bodies/types.gen.ts @@ -0,0 +1,23 @@ +// This file is auto-generated by @hey-api/openapi-ts + +/** + * Foo + */ +export type Foo = { + page?: number; +}; + +export type PostFooData = { + /** + * Foo + */ + body: Foo; + url: '/foo'; +}; + +export type PostFooResponses = { + /** + * OK + */ + 200: unknown; +}; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/@hey-api/sdk/default/types.gen.ts b/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/@hey-api/sdk/default/types.gen.ts index 09ad2015d..e76cefd9f 100644 --- a/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/@hey-api/sdk/default/types.gen.ts +++ b/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/@hey-api/sdk/default/types.gen.ts @@ -947,6 +947,16 @@ export type SimpleParameter = string; */ export type x_Foo_Bar = ModelWithString; +/** + * A reusable request body + */ +export type SimpleRequestBody = ModelWithString; + +/** + * A reusable request body + */ +export type SimpleFormData = ModelWithString; + export type ExportData = { body?: never; url: '/api/v{api-version}/no-tag'; @@ -1243,7 +1253,7 @@ export type PostApiVbyApiVersionRequestBodyData = { /** * A reusable request body */ - body?: ModelWithString; + body?: SimpleRequestBody; path?: never; query?: { /** @@ -1258,7 +1268,7 @@ export type PostApiVbyApiVersionFormDataData = { /** * A reusable request body */ - body?: ModelWithString; + body?: SimpleFormData; path?: never; query?: { /** diff --git a/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/asClass/types.gen.ts b/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/asClass/types.gen.ts index 09ad2015d..e76cefd9f 100644 --- a/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/asClass/types.gen.ts +++ b/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/asClass/types.gen.ts @@ -947,6 +947,16 @@ export type SimpleParameter = string; */ export type x_Foo_Bar = ModelWithString; +/** + * A reusable request body + */ +export type SimpleRequestBody = ModelWithString; + +/** + * A reusable request body + */ +export type SimpleFormData = ModelWithString; + export type ExportData = { body?: never; url: '/api/v{api-version}/no-tag'; @@ -1243,7 +1253,7 @@ export type PostApiVbyApiVersionRequestBodyData = { /** * A reusable request body */ - body?: ModelWithString; + body?: SimpleRequestBody; path?: never; query?: { /** @@ -1258,7 +1268,7 @@ export type PostApiVbyApiVersionFormDataData = { /** * A reusable request body */ - body?: ModelWithString; + body?: SimpleFormData; path?: never; query?: { /** diff --git a/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/axios/types.gen.ts b/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/axios/types.gen.ts index 09ad2015d..e76cefd9f 100644 --- a/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/axios/types.gen.ts +++ b/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/axios/types.gen.ts @@ -947,6 +947,16 @@ export type SimpleParameter = string; */ export type x_Foo_Bar = ModelWithString; +/** + * A reusable request body + */ +export type SimpleRequestBody = ModelWithString; + +/** + * A reusable request body + */ +export type SimpleFormData = ModelWithString; + export type ExportData = { body?: never; url: '/api/v{api-version}/no-tag'; @@ -1243,7 +1253,7 @@ export type PostApiVbyApiVersionRequestBodyData = { /** * A reusable request body */ - body?: ModelWithString; + body?: SimpleRequestBody; path?: never; query?: { /** @@ -1258,7 +1268,7 @@ export type PostApiVbyApiVersionFormDataData = { /** * A reusable request body */ - body?: ModelWithString; + body?: SimpleFormData; path?: never; query?: { /** diff --git a/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/fetch/types.gen.ts b/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/fetch/types.gen.ts index 09ad2015d..e76cefd9f 100644 --- a/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/fetch/types.gen.ts +++ b/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/fetch/types.gen.ts @@ -947,6 +947,16 @@ export type SimpleParameter = string; */ export type x_Foo_Bar = ModelWithString; +/** + * A reusable request body + */ +export type SimpleRequestBody = ModelWithString; + +/** + * A reusable request body + */ +export type SimpleFormData = ModelWithString; + export type ExportData = { body?: never; url: '/api/v{api-version}/no-tag'; @@ -1243,7 +1253,7 @@ export type PostApiVbyApiVersionRequestBodyData = { /** * A reusable request body */ - body?: ModelWithString; + body?: SimpleRequestBody; path?: never; query?: { /** @@ -1258,7 +1268,7 @@ export type PostApiVbyApiVersionFormDataData = { /** * A reusable request body */ - body?: ModelWithString; + body?: SimpleFormData; path?: never; query?: { /** diff --git a/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/asClass/types.gen.ts b/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/asClass/types.gen.ts index 09ad2015d..e76cefd9f 100644 --- a/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/asClass/types.gen.ts +++ b/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/asClass/types.gen.ts @@ -947,6 +947,16 @@ export type SimpleParameter = string; */ export type x_Foo_Bar = ModelWithString; +/** + * A reusable request body + */ +export type SimpleRequestBody = ModelWithString; + +/** + * A reusable request body + */ +export type SimpleFormData = ModelWithString; + export type ExportData = { body?: never; url: '/api/v{api-version}/no-tag'; @@ -1243,7 +1253,7 @@ export type PostApiVbyApiVersionRequestBodyData = { /** * A reusable request body */ - body?: ModelWithString; + body?: SimpleRequestBody; path?: never; query?: { /** @@ -1258,7 +1268,7 @@ export type PostApiVbyApiVersionFormDataData = { /** * A reusable request body */ - body?: ModelWithString; + body?: SimpleFormData; path?: never; query?: { /** diff --git a/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/axios/types.gen.ts b/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/axios/types.gen.ts index 09ad2015d..e76cefd9f 100644 --- a/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/axios/types.gen.ts +++ b/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/axios/types.gen.ts @@ -947,6 +947,16 @@ export type SimpleParameter = string; */ export type x_Foo_Bar = ModelWithString; +/** + * A reusable request body + */ +export type SimpleRequestBody = ModelWithString; + +/** + * A reusable request body + */ +export type SimpleFormData = ModelWithString; + export type ExportData = { body?: never; url: '/api/v{api-version}/no-tag'; @@ -1243,7 +1253,7 @@ export type PostApiVbyApiVersionRequestBodyData = { /** * A reusable request body */ - body?: ModelWithString; + body?: SimpleRequestBody; path?: never; query?: { /** @@ -1258,7 +1268,7 @@ export type PostApiVbyApiVersionFormDataData = { /** * A reusable request body */ - body?: ModelWithString; + body?: SimpleFormData; path?: never; query?: { /** diff --git a/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/fetch/types.gen.ts b/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/fetch/types.gen.ts index 09ad2015d..e76cefd9f 100644 --- a/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/fetch/types.gen.ts +++ b/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/fetch/types.gen.ts @@ -947,6 +947,16 @@ export type SimpleParameter = string; */ export type x_Foo_Bar = ModelWithString; +/** + * A reusable request body + */ +export type SimpleRequestBody = ModelWithString; + +/** + * A reusable request body + */ +export type SimpleFormData = ModelWithString; + export type ExportData = { body?: never; url: '/api/v{api-version}/no-tag'; @@ -1243,7 +1253,7 @@ export type PostApiVbyApiVersionRequestBodyData = { /** * A reusable request body */ - body?: ModelWithString; + body?: SimpleRequestBody; path?: never; query?: { /** @@ -1258,7 +1268,7 @@ export type PostApiVbyApiVersionFormDataData = { /** * A reusable request body */ - body?: ModelWithString; + body?: SimpleFormData; path?: never; query?: { /** diff --git a/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/asClass/types.gen.ts b/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/asClass/types.gen.ts index 09ad2015d..e76cefd9f 100644 --- a/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/asClass/types.gen.ts +++ b/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/asClass/types.gen.ts @@ -947,6 +947,16 @@ export type SimpleParameter = string; */ export type x_Foo_Bar = ModelWithString; +/** + * A reusable request body + */ +export type SimpleRequestBody = ModelWithString; + +/** + * A reusable request body + */ +export type SimpleFormData = ModelWithString; + export type ExportData = { body?: never; url: '/api/v{api-version}/no-tag'; @@ -1243,7 +1253,7 @@ export type PostApiVbyApiVersionRequestBodyData = { /** * A reusable request body */ - body?: ModelWithString; + body?: SimpleRequestBody; path?: never; query?: { /** @@ -1258,7 +1268,7 @@ export type PostApiVbyApiVersionFormDataData = { /** * A reusable request body */ - body?: ModelWithString; + body?: SimpleFormData; path?: never; query?: { /** diff --git a/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/axios/types.gen.ts b/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/axios/types.gen.ts index 09ad2015d..e76cefd9f 100644 --- a/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/axios/types.gen.ts +++ b/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/axios/types.gen.ts @@ -947,6 +947,16 @@ export type SimpleParameter = string; */ export type x_Foo_Bar = ModelWithString; +/** + * A reusable request body + */ +export type SimpleRequestBody = ModelWithString; + +/** + * A reusable request body + */ +export type SimpleFormData = ModelWithString; + export type ExportData = { body?: never; url: '/api/v{api-version}/no-tag'; @@ -1243,7 +1253,7 @@ export type PostApiVbyApiVersionRequestBodyData = { /** * A reusable request body */ - body?: ModelWithString; + body?: SimpleRequestBody; path?: never; query?: { /** @@ -1258,7 +1268,7 @@ export type PostApiVbyApiVersionFormDataData = { /** * A reusable request body */ - body?: ModelWithString; + body?: SimpleFormData; path?: never; query?: { /** diff --git a/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/fetch/types.gen.ts b/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/fetch/types.gen.ts index 09ad2015d..e76cefd9f 100644 --- a/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/fetch/types.gen.ts +++ b/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/fetch/types.gen.ts @@ -947,6 +947,16 @@ export type SimpleParameter = string; */ export type x_Foo_Bar = ModelWithString; +/** + * A reusable request body + */ +export type SimpleRequestBody = ModelWithString; + +/** + * A reusable request body + */ +export type SimpleFormData = ModelWithString; + export type ExportData = { body?: never; url: '/api/v{api-version}/no-tag'; @@ -1243,7 +1253,7 @@ export type PostApiVbyApiVersionRequestBodyData = { /** * A reusable request body */ - body?: ModelWithString; + body?: SimpleRequestBody; path?: never; query?: { /** @@ -1258,7 +1268,7 @@ export type PostApiVbyApiVersionFormDataData = { /** * A reusable request body */ - body?: ModelWithString; + body?: SimpleFormData; path?: never; query?: { /** diff --git a/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/asClass/types.gen.ts b/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/asClass/types.gen.ts index 09ad2015d..e76cefd9f 100644 --- a/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/asClass/types.gen.ts +++ b/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/asClass/types.gen.ts @@ -947,6 +947,16 @@ export type SimpleParameter = string; */ export type x_Foo_Bar = ModelWithString; +/** + * A reusable request body + */ +export type SimpleRequestBody = ModelWithString; + +/** + * A reusable request body + */ +export type SimpleFormData = ModelWithString; + export type ExportData = { body?: never; url: '/api/v{api-version}/no-tag'; @@ -1243,7 +1253,7 @@ export type PostApiVbyApiVersionRequestBodyData = { /** * A reusable request body */ - body?: ModelWithString; + body?: SimpleRequestBody; path?: never; query?: { /** @@ -1258,7 +1268,7 @@ export type PostApiVbyApiVersionFormDataData = { /** * A reusable request body */ - body?: ModelWithString; + body?: SimpleFormData; path?: never; query?: { /** diff --git a/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/axios/types.gen.ts b/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/axios/types.gen.ts index 09ad2015d..e76cefd9f 100644 --- a/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/axios/types.gen.ts +++ b/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/axios/types.gen.ts @@ -947,6 +947,16 @@ export type SimpleParameter = string; */ export type x_Foo_Bar = ModelWithString; +/** + * A reusable request body + */ +export type SimpleRequestBody = ModelWithString; + +/** + * A reusable request body + */ +export type SimpleFormData = ModelWithString; + export type ExportData = { body?: never; url: '/api/v{api-version}/no-tag'; @@ -1243,7 +1253,7 @@ export type PostApiVbyApiVersionRequestBodyData = { /** * A reusable request body */ - body?: ModelWithString; + body?: SimpleRequestBody; path?: never; query?: { /** @@ -1258,7 +1268,7 @@ export type PostApiVbyApiVersionFormDataData = { /** * A reusable request body */ - body?: ModelWithString; + body?: SimpleFormData; path?: never; query?: { /** diff --git a/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/fetch/types.gen.ts b/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/fetch/types.gen.ts index 09ad2015d..e76cefd9f 100644 --- a/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/fetch/types.gen.ts +++ b/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/fetch/types.gen.ts @@ -947,6 +947,16 @@ export type SimpleParameter = string; */ export type x_Foo_Bar = ModelWithString; +/** + * A reusable request body + */ +export type SimpleRequestBody = ModelWithString; + +/** + * A reusable request body + */ +export type SimpleFormData = ModelWithString; + export type ExportData = { body?: never; url: '/api/v{api-version}/no-tag'; @@ -1243,7 +1253,7 @@ export type PostApiVbyApiVersionRequestBodyData = { /** * A reusable request body */ - body?: ModelWithString; + body?: SimpleRequestBody; path?: never; query?: { /** @@ -1258,7 +1268,7 @@ export type PostApiVbyApiVersionFormDataData = { /** * A reusable request body */ - body?: ModelWithString; + body?: SimpleFormData; path?: never; query?: { /** diff --git a/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/asClass/types.gen.ts b/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/asClass/types.gen.ts index 09ad2015d..e76cefd9f 100644 --- a/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/asClass/types.gen.ts +++ b/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/asClass/types.gen.ts @@ -947,6 +947,16 @@ export type SimpleParameter = string; */ export type x_Foo_Bar = ModelWithString; +/** + * A reusable request body + */ +export type SimpleRequestBody = ModelWithString; + +/** + * A reusable request body + */ +export type SimpleFormData = ModelWithString; + export type ExportData = { body?: never; url: '/api/v{api-version}/no-tag'; @@ -1243,7 +1253,7 @@ export type PostApiVbyApiVersionRequestBodyData = { /** * A reusable request body */ - body?: ModelWithString; + body?: SimpleRequestBody; path?: never; query?: { /** @@ -1258,7 +1268,7 @@ export type PostApiVbyApiVersionFormDataData = { /** * A reusable request body */ - body?: ModelWithString; + body?: SimpleFormData; path?: never; query?: { /** diff --git a/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/axios/types.gen.ts b/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/axios/types.gen.ts index 09ad2015d..e76cefd9f 100644 --- a/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/axios/types.gen.ts +++ b/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/axios/types.gen.ts @@ -947,6 +947,16 @@ export type SimpleParameter = string; */ export type x_Foo_Bar = ModelWithString; +/** + * A reusable request body + */ +export type SimpleRequestBody = ModelWithString; + +/** + * A reusable request body + */ +export type SimpleFormData = ModelWithString; + export type ExportData = { body?: never; url: '/api/v{api-version}/no-tag'; @@ -1243,7 +1253,7 @@ export type PostApiVbyApiVersionRequestBodyData = { /** * A reusable request body */ - body?: ModelWithString; + body?: SimpleRequestBody; path?: never; query?: { /** @@ -1258,7 +1268,7 @@ export type PostApiVbyApiVersionFormDataData = { /** * A reusable request body */ - body?: ModelWithString; + body?: SimpleFormData; path?: never; query?: { /** diff --git a/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/fetch/types.gen.ts b/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/fetch/types.gen.ts index 09ad2015d..e76cefd9f 100644 --- a/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/fetch/types.gen.ts +++ b/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/fetch/types.gen.ts @@ -947,6 +947,16 @@ export type SimpleParameter = string; */ export type x_Foo_Bar = ModelWithString; +/** + * A reusable request body + */ +export type SimpleRequestBody = ModelWithString; + +/** + * A reusable request body + */ +export type SimpleFormData = ModelWithString; + export type ExportData = { body?: never; url: '/api/v{api-version}/no-tag'; @@ -1243,7 +1253,7 @@ export type PostApiVbyApiVersionRequestBodyData = { /** * A reusable request body */ - body?: ModelWithString; + body?: SimpleRequestBody; path?: never; query?: { /** @@ -1258,7 +1268,7 @@ export type PostApiVbyApiVersionFormDataData = { /** * A reusable request body */ - body?: ModelWithString; + body?: SimpleFormData; path?: never; query?: { /** diff --git a/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/fastify/default/types.gen.ts b/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/fastify/default/types.gen.ts index 09ad2015d..e76cefd9f 100644 --- a/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/fastify/default/types.gen.ts +++ b/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/fastify/default/types.gen.ts @@ -947,6 +947,16 @@ export type SimpleParameter = string; */ export type x_Foo_Bar = ModelWithString; +/** + * A reusable request body + */ +export type SimpleRequestBody = ModelWithString; + +/** + * A reusable request body + */ +export type SimpleFormData = ModelWithString; + export type ExportData = { body?: never; url: '/api/v{api-version}/no-tag'; @@ -1243,7 +1253,7 @@ export type PostApiVbyApiVersionRequestBodyData = { /** * A reusable request body */ - body?: ModelWithString; + body?: SimpleRequestBody; path?: never; query?: { /** @@ -1258,7 +1268,7 @@ export type PostApiVbyApiVersionFormDataData = { /** * A reusable request body */ - body?: ModelWithString; + body?: SimpleFormData; path?: never; query?: { /** diff --git a/packages/openapi-ts/test/sample.cjs b/packages/openapi-ts/test/sample.cjs index ba2677911..b7b954b32 100644 --- a/packages/openapi-ts/test/sample.cjs +++ b/packages/openapi-ts/test/sample.cjs @@ -14,7 +14,7 @@ const main = async () => { exclude: '^#/components/schemas/ModelWithCircularReference$', // include: // '^(#/components/schemas/import|#/paths/api/v{api-version}/simple/options)$', - path: './test/spec/3.1.x/transformers-any-of-null.json', + path: './test/spec/3.0.x/components-request-bodies.json', // path: 'https://mongodb-mms-prod-build-server.s3.amazonaws.com/openapi/2caffd88277a4e27c95dcefc7e3b6a63a3b03297-v2-2023-11-15.json', }, // name: 'foo', @@ -37,7 +37,7 @@ const main = async () => { }, { // dates: true, - name: '@hey-api/transformers', + // name: '@hey-api/transformers', }, { // enums: 'typescript', @@ -49,7 +49,7 @@ const main = async () => { // tree: true, }, { - // name: '@tanstack/react-query', + name: '@tanstack/react-query', // name: 'fastify', // name: 'zod', }, diff --git a/packages/openapi-ts/test/spec/3.0.x/components-request-bodies.json b/packages/openapi-ts/test/spec/3.0.x/components-request-bodies.json new file mode 100644 index 000000000..517c24748 --- /dev/null +++ b/packages/openapi-ts/test/spec/3.0.x/components-request-bodies.json @@ -0,0 +1,41 @@ +{ + "openapi": "3.0.4", + "info": { + "title": "OpenAPI 3.0.4 components request bodies example", + "version": "1" + }, + "paths": { + "/foo": { + "post": { + "requestBody": { + "$ref": "#/components/requestBodies/Foo" + }, + "responses": { + "200": { + "description": "OK" + } + } + } + } + }, + "components": { + "requestBodies": { + "Foo": { + "description": "Foo", + "required": true, + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "page": { + "type": "number" + } + } + } + } + } + } + } + } +} diff --git a/packages/openapi-ts/test/spec/3.1.x/components-request-bodies.json b/packages/openapi-ts/test/spec/3.1.x/components-request-bodies.json new file mode 100644 index 000000000..f778cecef --- /dev/null +++ b/packages/openapi-ts/test/spec/3.1.x/components-request-bodies.json @@ -0,0 +1,41 @@ +{ + "openapi": "3.1.1", + "info": { + "title": "OpenAPI 3.1.1 components request bodies example", + "version": "1" + }, + "paths": { + "/foo": { + "post": { + "requestBody": { + "$ref": "#/components/requestBodies/Foo" + }, + "responses": { + "200": { + "description": "OK" + } + } + } + } + }, + "components": { + "requestBodies": { + "Foo": { + "description": "Foo", + "required": true, + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "page": { + "type": "number" + } + } + } + } + } + } + } + } +}