diff --git a/.changeset/plenty-carpets-fold.md b/.changeset/plenty-carpets-fold.md new file mode 100644 index 000000000..51ffe99ec --- /dev/null +++ b/.changeset/plenty-carpets-fold.md @@ -0,0 +1,5 @@ +--- +"@hey-api/openapi-ts": patch +--- + +fix: prefix parameter type exports to avoid conflicts diff --git a/packages/openapi-ts/src/openApi/common/parser/type.ts b/packages/openapi-ts/src/openApi/common/parser/type.ts index 5681bf079..fa6f31380 100644 --- a/packages/openapi-ts/src/openApi/common/parser/type.ts +++ b/packages/openapi-ts/src/openApi/common/parser/type.ts @@ -121,8 +121,13 @@ export const getType = ( } if (typeWithoutNamespace) { - const encodedType = + let encodedType = ensureValidTypeScriptJavaScriptIdentifier(typeWithoutNamespace); + if (type.startsWith('#/components/parameters/')) { + // prefix parameter names to avoid conflicts, assuming people are mostly + // interested in importing schema types and don't care about this naming + encodedType = `Parameter${encodedType}`; + } result.type = encodedType; result.base = encodedType; if (type.startsWith('#')) { diff --git a/packages/openapi-ts/src/openApi/v2/parser/getModelProperties.ts b/packages/openapi-ts/src/openApi/v2/parser/getModelProperties.ts index 14b63e8fd..8c9042f8b 100644 --- a/packages/openapi-ts/src/openApi/v2/parser/getModelProperties.ts +++ b/packages/openapi-ts/src/openApi/v2/parser/getModelProperties.ts @@ -15,9 +15,9 @@ export const getModelProperties = ( getModel: GetModelFn, ): Model[] => { const models: Model[] = []; - for (const propertyName in definition.properties) { - if (definition.properties.hasOwnProperty(propertyName)) { - const property = definition.properties[propertyName]; + + Object.entries(definition.properties ?? {}).forEach( + ([propertyName, property]) => { const propertyRequired = !!definition.required?.includes(propertyName); if (property.$ref) { const model = getType(property.$ref); @@ -88,7 +88,8 @@ export const getModelProperties = ( uniqueItems: property.uniqueItems, }); } - } - } + }, + ); + return models; }; diff --git a/packages/openapi-ts/src/openApi/v2/parser/getModels.ts b/packages/openapi-ts/src/openApi/v2/parser/getModels.ts index d9462adca..113c64e89 100644 --- a/packages/openapi-ts/src/openApi/v2/parser/getModels.ts +++ b/packages/openapi-ts/src/openApi/v2/parser/getModels.ts @@ -5,10 +5,10 @@ import type { OpenApi } from '../interfaces/OpenApi'; import { getModel } from './getModel'; export const getModels = (openApi: OpenApi): Model[] => { - const models: Model[] = []; - for (const definitionName in openApi.definitions) { - if (openApi.definitions.hasOwnProperty(definitionName)) { - const definition = openApi.definitions[definitionName]; + let models: Model[] = []; + + Object.entries(openApi.definitions ?? {}).forEach( + ([definitionName, definition]) => { const definitionType = getType(definitionName); const model = getModel( openApi, @@ -16,8 +16,9 @@ export const getModels = (openApi: OpenApi): Model[] => { true, definitionType.base.replace(reservedWords, '_$1'), ); - models.push(model); - } - } + models = [...models, model]; + }, + ); + return models; }; diff --git a/packages/openapi-ts/src/openApi/v2/parser/getOperationResponse.ts b/packages/openapi-ts/src/openApi/v2/parser/getOperationResponse.ts index 1e30ace28..af62d9c5f 100644 --- a/packages/openapi-ts/src/openApi/v2/parser/getOperationResponse.ts +++ b/packages/openapi-ts/src/openApi/v2/parser/getOperationResponse.ts @@ -84,17 +84,13 @@ export const getOperationResponse = ( // We support basic properties from response headers, since both // fetch and XHR client just support string types. - if (response.headers) { - for (const name in response.headers) { - if (response.headers.hasOwnProperty(name)) { - operationResponse.in = 'header'; - operationResponse.name = name; - operationResponse.type = 'string'; - operationResponse.base = 'string'; - return operationResponse; - } - } - } + Object.keys(response.headers ?? {}).forEach((name) => { + operationResponse.in = 'header'; + operationResponse.name = name; + operationResponse.type = 'string'; + operationResponse.base = 'string'; + return operationResponse; + }); return operationResponse; }; diff --git a/packages/openapi-ts/src/openApi/v2/parser/getOperationResponses.ts b/packages/openapi-ts/src/openApi/v2/parser/getOperationResponses.ts index e1d4d89ae..14223a362 100644 --- a/packages/openapi-ts/src/openApi/v2/parser/getOperationResponses.ts +++ b/packages/openapi-ts/src/openApi/v2/parser/getOperationResponses.ts @@ -14,22 +14,19 @@ export const getOperationResponses = ( // Iterate over each response code and get the // status code and response message - for (const code in responses) { - if (responses.hasOwnProperty(code)) { - const responseOrReference = responses[code]; - const response = getRef(openApi, responseOrReference); - const responseCode = getOperationResponseCode(code); + Object.entries(responses).forEach(([code, responseOrReference]) => { + const response = getRef(openApi, responseOrReference); + const responseCode = getOperationResponseCode(code); - if (responseCode) { - const operationResponse = getOperationResponse( - openApi, - response, - responseCode, - ); - operationResponses.push(operationResponse); - } + if (responseCode) { + const operationResponse = getOperationResponse( + openApi, + response, + responseCode, + ); + operationResponses.push(operationResponse); } - } + }); // Sort the responses to 2xx success codes come before 4xx and 5xx error codes. return operationResponses.sort((a, b): number => diff --git a/packages/openapi-ts/src/openApi/v2/parser/getServices.ts b/packages/openapi-ts/src/openApi/v2/parser/getServices.ts index b5db31ed3..86e1de88a 100644 --- a/packages/openapi-ts/src/openApi/v2/parser/getServices.ts +++ b/packages/openapi-ts/src/openApi/v2/parser/getServices.ts @@ -9,58 +9,53 @@ import { getOperationParameters } from './getOperationParameters'; */ export const getServices = (openApi: OpenApi): Service[] => { const services = new Map(); - for (const url in openApi.paths) { - if (openApi.paths.hasOwnProperty(url)) { - // Grab path and parse any global path parameters - const path = openApi.paths[url]; - const pathParams = getOperationParameters(openApi, path.parameters || []); + Object.entries(openApi.paths).forEach(([url, path]) => { + // Grab path and parse any global path parameters + const pathParams = getOperationParameters(openApi, path.parameters || []); + + Object.keys(path).forEach((method) => { // Parse all the methods for this path - for (const method in path) { - if (path.hasOwnProperty(method)) { - switch (method) { - case 'get': - case 'put': - case 'post': - case 'delete': - case 'options': - case 'head': - case 'patch': { - // Each method contains an OpenAPI operation, we parse the operation - const op = path[method]!; - const tags = op.tags?.length - ? op.tags.filter(unique) - : ['Default']; - tags.forEach((tag) => { - const operation = getOperation( - openApi, - url, - method, - tag, - op, - pathParams, - ); + switch (method) { + case 'get': + case 'put': + case 'post': + case 'delete': + case 'options': + case 'head': + case 'patch': { + // Each method contains an OpenAPI operation, we parse the operation + const op = path[method]!; + const tags = op.tags?.length ? op.tags.filter(unique) : ['Default']; + tags.forEach((tag) => { + const operation = getOperation( + openApi, + url, + method, + tag, + op, + pathParams, + ); - // If we have already declared a service, then we should fetch that and - // append the new method to it. Otherwise we should create a new service object. - const service: Service = services.get(operation.service) || { - $refs: [], - imports: [], - name: operation.service, - operations: [], - }; + // If we have already declared a service, then we should fetch that and + // append the new method to it. Otherwise we should create a new service object. + const service: Service = services.get(operation.service) || { + $refs: [], + imports: [], + name: operation.service, + operations: [], + }; - // Push the operation in the service - service.operations.push(operation); - service.imports.push(...operation.imports); - services.set(operation.service, service); - }); - break; - } - } + // Push the operation in the service + service.operations.push(operation); + service.imports.push(...operation.imports); + services.set(operation.service, service); + }); + break; } } - } - } + }); + }); + return Array.from(services.values()); }; diff --git a/packages/openapi-ts/src/openApi/v3/parser/getModelProperties.ts b/packages/openapi-ts/src/openApi/v3/parser/getModelProperties.ts index 6d8db6e0c..7353553f6 100644 --- a/packages/openapi-ts/src/openApi/v3/parser/getModelProperties.ts +++ b/packages/openapi-ts/src/openApi/v3/parser/getModelProperties.ts @@ -76,9 +76,8 @@ export const getModelProperties = ( const models: Model[] = []; const discriminator = findOneOfParentDiscriminator(openApi, parent); - for (const propertyName in definition.properties) { - if (definition.properties.hasOwnProperty(propertyName)) { - const property = definition.properties[propertyName]; + Object.entries(definition.properties ?? {}).forEach( + ([propertyName, property]) => { const propertyRequired = !!definition.required?.includes(propertyName); const propertyValues: Omit< Model, @@ -166,8 +165,8 @@ export const getModelProperties = ( type: model.type, }); } - } - } + }, + ); return models; }; diff --git a/packages/openapi-ts/src/openApi/v3/parser/getModels.ts b/packages/openapi-ts/src/openApi/v3/parser/getModels.ts index 5f9f1b4e5..cecbe1c2d 100644 --- a/packages/openapi-ts/src/openApi/v3/parser/getModels.ts +++ b/packages/openapi-ts/src/openApi/v3/parser/getModels.ts @@ -5,39 +5,46 @@ import type { OpenApi } from '../interfaces/OpenApi'; import { getModel } from './getModel'; export const getModels = (openApi: OpenApi): Model[] => { - const models: Model[] = []; - if (openApi.components) { - for (const definitionName in openApi.components.schemas) { - if (openApi.components.schemas.hasOwnProperty(definitionName)) { - const definition = openApi.components.schemas[definitionName]; - const definitionType = getType(definitionName); - const model = getModel( - openApi, - definition, - true, - definitionType.base.replace(reservedWords, '_$1'), - ); - models.push(model); - } - } - for (const definitionName in openApi.components.parameters) { - if (openApi.components.parameters.hasOwnProperty(definitionName)) { - const definition = openApi.components.parameters[definitionName]; - const definitionType = getType(definitionName); - const schema = definition.schema; - if (schema) { - const model = getModel( - openApi, - schema, - true, - definitionType.base.replace(reservedWords, '_$1'), - ); - model.description = definition.description || null; - model.deprecated = definition.deprecated; - models.push(model); - } - } - } + if (!openApi.components) { + return []; } + + let models: Model[] = []; + + Object.entries(openApi.components.schemas ?? {}).forEach( + ([definitionName, definition]) => { + const definitionType = getType(definitionName); + const model = getModel( + openApi, + definition, + true, + definitionType.base.replace(reservedWords, '_$1'), + ); + models = [...models, model]; + }, + ); + + Object.entries(openApi.components.parameters ?? {}).forEach( + ([definitionName, definition]) => { + const schema = definition.schema; + if (!schema) { + return; + } + + const definitionType = getType(definitionName); + const model = getModel( + openApi, + schema, + true, + // prefix parameter names to avoid conflicts, assuming people are mostly + // interested in importing schema types and don't care about this naming + `Parameter${definitionType.base.replace(reservedWords, '_$1')}`, + ); + model.deprecated = definition.deprecated; + model.description = definition.description || null; + models = [...models, model]; + }, + ); + return models; }; diff --git a/packages/openapi-ts/src/openApi/v3/parser/getOperationResponse.ts b/packages/openapi-ts/src/openApi/v3/parser/getOperationResponse.ts index cadac557b..d5f82630f 100644 --- a/packages/openapi-ts/src/openApi/v3/parser/getOperationResponse.ts +++ b/packages/openapi-ts/src/openApi/v3/parser/getOperationResponse.ts @@ -91,17 +91,13 @@ export const getOperationResponse = ( // We support basic properties from response headers, since both // fetch and XHR client just support string types. - if (response.headers) { - for (const name in response.headers) { - if (response.headers.hasOwnProperty(name)) { - operationResponse.in = 'header'; - operationResponse.name = name; - operationResponse.type = 'string'; - operationResponse.base = 'string'; - return operationResponse; - } - } - } + Object.keys(response.headers ?? {}).forEach((name) => { + operationResponse.in = 'header'; + operationResponse.name = name; + operationResponse.type = 'string'; + operationResponse.base = 'string'; + return operationResponse; + }); return operationResponse; }; diff --git a/packages/openapi-ts/src/openApi/v3/parser/getOperationResponses.ts b/packages/openapi-ts/src/openApi/v3/parser/getOperationResponses.ts index e1d4d89ae..14223a362 100644 --- a/packages/openapi-ts/src/openApi/v3/parser/getOperationResponses.ts +++ b/packages/openapi-ts/src/openApi/v3/parser/getOperationResponses.ts @@ -14,22 +14,19 @@ export const getOperationResponses = ( // Iterate over each response code and get the // status code and response message - for (const code in responses) { - if (responses.hasOwnProperty(code)) { - const responseOrReference = responses[code]; - const response = getRef(openApi, responseOrReference); - const responseCode = getOperationResponseCode(code); + Object.entries(responses).forEach(([code, responseOrReference]) => { + const response = getRef(openApi, responseOrReference); + const responseCode = getOperationResponseCode(code); - if (responseCode) { - const operationResponse = getOperationResponse( - openApi, - response, - responseCode, - ); - operationResponses.push(operationResponse); - } + if (responseCode) { + const operationResponse = getOperationResponse( + openApi, + response, + responseCode, + ); + operationResponses.push(operationResponse); } - } + }); // Sort the responses to 2xx success codes come before 4xx and 5xx error codes. return operationResponses.sort((a, b): number => diff --git a/packages/openapi-ts/src/openApi/v3/parser/getServer.ts b/packages/openapi-ts/src/openApi/v3/parser/getServer.ts index 950ac7005..3f74b8ab9 100644 --- a/packages/openapi-ts/src/openApi/v3/parser/getServer.ts +++ b/packages/openapi-ts/src/openApi/v3/parser/getServer.ts @@ -4,10 +4,8 @@ export const getServer = (openApi: OpenApi): string => { const server = openApi.servers?.[0]; const variables = server?.variables || {}; let url = server?.url || ''; - for (const variable in variables) { - if (variables.hasOwnProperty(variable)) { - url = url.replace(`{${variable}}`, variables[variable].default); - } - } + Object.entries(variables).forEach(([name, variable]) => { + url = url.replace(`{${name}}`, variable.default); + }); return url.replace(/\/$/g, ''); }; diff --git a/packages/openapi-ts/src/utils/write/schemas.ts b/packages/openapi-ts/src/utils/write/schemas.ts index adb03e743..9490aeca6 100644 --- a/packages/openapi-ts/src/utils/write/schemas.ts +++ b/packages/openapi-ts/src/utils/write/schemas.ts @@ -59,23 +59,17 @@ export const processSchemas = async ({ // OpenAPI 2.0 if ('swagger' in openApi) { - for (const name in openApi.definitions) { - if (openApi.definitions.hasOwnProperty(name)) { - const definition = openApi.definitions[name]; - addSchema(name, definition); - } - } + Object.entries(openApi.definitions ?? {}).forEach(([name, definition]) => { + addSchema(name, definition); + }); } // OpenAPI 3.x if ('openapi' in openApi) { - if (openApi.components) { - for (const name in openApi.components.schemas) { - if (openApi.components.schemas.hasOwnProperty(name)) { - const schema = openApi.components.schemas[name]; - addSchema(name, schema); - } - } - } + Object.entries(openApi.components?.schemas ?? {}).forEach( + ([name, schema]) => { + addSchema(name, schema); + }, + ); } }; diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3/services.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3/services.gen.ts.snap index 35ccb0463..86d9c090c 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3/services.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3/services.gen.ts.snap @@ -515,7 +515,9 @@ export class ResponseService { } /** + * @returns unknown Message for 200 response * @returns ModelWithString Message for 201 response + * @returns ModelWithBoolean Message for default response * @throws ApiError */ public static callWithDuplicateResponses(): CancelablePromise { diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3/types.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3/types.gen.ts.snap index 8f051c403..21f87b65b 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3/types.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3/types.gen.ts.snap @@ -686,7 +686,7 @@ export type NestedAnyOfArraysNullable = { }; export type CompositionWithOneOfAndProperties = { - foo: SimpleParameter; + foo: ParameterSimpleParameter; baz: number | null; qux: number; } | { @@ -832,12 +832,12 @@ export type ModelWithBackticksInDescription = { /** * This is a reusable parameter */ -export type SimpleParameter = string; +export type ParameterSimpleParameter = string; /** * Parameter with illegal characters */ -export type x_Foo_Bar = string; +export type Parameterx_Foo_Bar = string; export type DefaultPostServiceWithEmptyTagData = { requestBody: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; @@ -1097,7 +1097,7 @@ export type ResponseCallWithResponseAndNoContentResponseResponse = number | void export type ResponseCallWithResponseResponse = ModelWithString; -export type ResponseCallWithDuplicateResponsesResponse = ModelWithString; +export type ResponseCallWithDuplicateResponsesResponse = ModelWithBoolean & ModelWithInteger | ModelWithString | ModelWithBoolean; export type ResponseCallWithResponsesResponse = { readonly '@namespace.string'?: string; @@ -1594,10 +1594,18 @@ export type $OpenApiTs = { }; post: { res: { + /** + * Message for 200 response + */ + 200: ModelWithBoolean & ModelWithInteger; /** * Message for 201 response */ 201: ModelWithString; + /** + * Message for default response + */ + default: ModelWithBoolean; /** * Message for 500 error */ diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/services.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/services.gen.ts.snap index c672ae0be..bf92a7bb5 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/services.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/services.gen.ts.snap @@ -572,7 +572,9 @@ export class ResponseService { } /** + * @returns unknown Message for 200 response * @returns ModelWithString Message for 201 response + * @returns ModelWithBoolean Message for default response * @throws ApiError */ public callWithDuplicateResponses(): Observable { diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/types.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/types.gen.ts.snap index 8f051c403..21f87b65b 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/types.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/types.gen.ts.snap @@ -686,7 +686,7 @@ export type NestedAnyOfArraysNullable = { }; export type CompositionWithOneOfAndProperties = { - foo: SimpleParameter; + foo: ParameterSimpleParameter; baz: number | null; qux: number; } | { @@ -832,12 +832,12 @@ export type ModelWithBackticksInDescription = { /** * This is a reusable parameter */ -export type SimpleParameter = string; +export type ParameterSimpleParameter = string; /** * Parameter with illegal characters */ -export type x_Foo_Bar = string; +export type Parameterx_Foo_Bar = string; export type DefaultPostServiceWithEmptyTagData = { requestBody: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; @@ -1097,7 +1097,7 @@ export type ResponseCallWithResponseAndNoContentResponseResponse = number | void export type ResponseCallWithResponseResponse = ModelWithString; -export type ResponseCallWithDuplicateResponsesResponse = ModelWithString; +export type ResponseCallWithDuplicateResponsesResponse = ModelWithBoolean & ModelWithInteger | ModelWithString | ModelWithBoolean; export type ResponseCallWithResponsesResponse = { readonly '@namespace.string'?: string; @@ -1594,10 +1594,18 @@ export type $OpenApiTs = { }; post: { res: { + /** + * Message for 200 response + */ + 200: ModelWithBoolean & ModelWithInteger; /** * Message for 201 response */ 201: ModelWithString; + /** + * Message for default response + */ + default: ModelWithBoolean; /** * Message for 500 error */ diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/services.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/services.gen.ts.snap index d4d9727c6..5477bc534 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/services.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/services.gen.ts.snap @@ -536,7 +536,9 @@ export class ResponseService { } /** + * @returns unknown Message for 200 response * @returns ModelWithString Message for 201 response + * @returns ModelWithBoolean Message for default response * @throws ApiError */ public callWithDuplicateResponses(): CancelablePromise { diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/types.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/types.gen.ts.snap index 9b0a9f36d..cb15f2ff9 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/types.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/types.gen.ts.snap @@ -686,7 +686,7 @@ export type NestedAnyOfArraysNullable = { }; export type CompositionWithOneOfAndProperties = { - foo: SimpleParameter; + foo: ParameterSimpleParameter; baz: number | null; qux: number; } | { @@ -832,12 +832,12 @@ export type ModelWithBackticksInDescription = { /** * This is a reusable parameter */ -export type SimpleParameter = string; +export type ParameterSimpleParameter = string; /** * Parameter with illegal characters */ -export type x_Foo_Bar = string; +export type Parameterx_Foo_Bar = string; export type DefaultPostServiceWithEmptyTagData = { requestBody: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; @@ -1097,7 +1097,7 @@ export type ResponseCallWithResponseAndNoContentResponseResponse = number | void export type ResponseCallWithResponseResponse = ModelWithString; -export type ResponseCallWithDuplicateResponsesResponse = ModelWithString; +export type ResponseCallWithDuplicateResponsesResponse = ModelWithBoolean & ModelWithInteger | ModelWithString | ModelWithBoolean; export type ResponseCallWithResponsesResponse = { readonly '@namespace.string'?: string; @@ -1594,10 +1594,18 @@ export type $OpenApiTs = { }; post: { res: { + /** + * Message for 200 response + */ + 200: ModelWithBoolean & ModelWithInteger; /** * Message for 201 response */ 201: ModelWithString; + /** + * Message for default response + */ + default: ModelWithBoolean; /** * Message for 500 error */ diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/services.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/services.gen.ts.snap index 35ccb0463..86d9c090c 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/services.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/services.gen.ts.snap @@ -515,7 +515,9 @@ export class ResponseService { } /** + * @returns unknown Message for 200 response * @returns ModelWithString Message for 201 response + * @returns ModelWithBoolean Message for default response * @throws ApiError */ public static callWithDuplicateResponses(): CancelablePromise { diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/types.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/types.gen.ts.snap index 8f051c403..21f87b65b 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/types.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/types.gen.ts.snap @@ -686,7 +686,7 @@ export type NestedAnyOfArraysNullable = { }; export type CompositionWithOneOfAndProperties = { - foo: SimpleParameter; + foo: ParameterSimpleParameter; baz: number | null; qux: number; } | { @@ -832,12 +832,12 @@ export type ModelWithBackticksInDescription = { /** * This is a reusable parameter */ -export type SimpleParameter = string; +export type ParameterSimpleParameter = string; /** * Parameter with illegal characters */ -export type x_Foo_Bar = string; +export type Parameterx_Foo_Bar = string; export type DefaultPostServiceWithEmptyTagData = { requestBody: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; @@ -1097,7 +1097,7 @@ export type ResponseCallWithResponseAndNoContentResponseResponse = number | void export type ResponseCallWithResponseResponse = ModelWithString; -export type ResponseCallWithDuplicateResponsesResponse = ModelWithString; +export type ResponseCallWithDuplicateResponsesResponse = ModelWithBoolean & ModelWithInteger | ModelWithString | ModelWithBoolean; export type ResponseCallWithResponsesResponse = { readonly '@namespace.string'?: string; @@ -1594,10 +1594,18 @@ export type $OpenApiTs = { }; post: { res: { + /** + * Message for 200 response + */ + 200: ModelWithBoolean & ModelWithInteger; /** * Message for 201 response */ 201: ModelWithString; + /** + * Message for default response + */ + default: ModelWithBoolean; /** * Message for 500 error */ diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_models/types.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_models/types.gen.ts.snap index e9d1c7baf..ec45842a9 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_models/types.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_models/types.gen.ts.snap @@ -686,7 +686,7 @@ export type NestedAnyOfArraysNullable = { }; export type CompositionWithOneOfAndProperties = { - foo: SimpleParameter; + foo: ParameterSimpleParameter; baz: number | null; qux: number; } | { @@ -832,9 +832,9 @@ export type ModelWithBackticksInDescription = { /** * This is a reusable parameter */ -export type SimpleParameter = string; +export type ParameterSimpleParameter = string; /** * Parameter with illegal characters */ -export type x_Foo_Bar = string; \ No newline at end of file +export type Parameterx_Foo_Bar = string; \ No newline at end of file diff --git a/packages/openapi-ts/test/spec/v3.json b/packages/openapi-ts/test/spec/v3.json index a9a4c35d6..be176b473 100644 --- a/packages/openapi-ts/test/spec/v3.json +++ b/packages/openapi-ts/test/spec/v3.json @@ -793,7 +793,24 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/ModelWithString" + "$ref": "#/components/schemas/ModelWithBoolean" + } + } + } + }, + "200": { + "description": "Message for 200 response", + "content": { + "application/json": { + "schema": { + "allOf": [ + { + "$ref": "#/components/schemas/ModelWithBoolean" + }, + { + "$ref": "#/components/schemas/ModelWithInteger" + } + ] } } }