diff --git a/packages/openapi-ts/src/compiler/typedef.ts b/packages/openapi-ts/src/compiler/typedef.ts index 599aa9e14..73a865540 100644 --- a/packages/openapi-ts/src/compiler/typedef.ts +++ b/packages/openapi-ts/src/compiler/typedef.ts @@ -22,7 +22,7 @@ export type Property = { comment?: Comments; isReadOnly?: boolean; isRequired?: boolean; - name: string; + name: string | ts.PropertyName; type: any | ts.TypeNode; }; @@ -87,7 +87,9 @@ export const createTypeInterfaceNode = ({ const signature = ts.factory.createPropertySignature( modifiers, useLegacyResolution || - property.name.match(validTypescriptIdentifierRegExp) + (typeof property.name === 'string' && + property.name.match(validTypescriptIdentifierRegExp)) || + (typeof property.name !== 'string' && ts.isPropertyName(property.name)) ? property.name : createStringLiteral({ text: property.name }), questionToken, @@ -111,7 +113,7 @@ export const createTypeInterfaceNode = ({ modifiers, [ createParameterDeclaration({ - name: createIdentifier({ text: indexProperty.name }), + name: createIdentifier({ text: String(indexProperty.name) }), type: createKeywordTypeNode({ keyword: 'string' }), }), ], diff --git a/packages/openapi-ts/src/ir/schema.ts b/packages/openapi-ts/src/ir/schema.ts index 045c00d21..d4e79610f 100644 --- a/packages/openapi-ts/src/ir/schema.ts +++ b/packages/openapi-ts/src/ir/schema.ts @@ -1,4 +1,4 @@ -import type { IRSchemaObject } from './ir'; +import type { IRParameterObject, IRSchemaObject } from './ir'; /** * Ensure we don't produce redundant types, e.g. string | string. @@ -70,3 +70,38 @@ export const deduplicateSchema = ({ return schema; }; + +export const irParametersToIrSchema = ({ + parameters, +}: { + parameters: Record; +}): IRSchemaObject => { + const irSchema: IRSchemaObject = { + type: 'object', + }; + + if (parameters) { + const properties: Record = {}; + const required: Array = []; + + for (const name in parameters) { + const parameter = parameters[name]; + + properties[name] = deduplicateSchema({ + schema: parameter.schema, + }); + + if (parameter.required) { + required.push(name); + } + } + + irSchema.properties = properties; + + if (required.length) { + irSchema.required = required; + } + } + + return irSchema; +}; diff --git a/packages/openapi-ts/src/plugins/@hey-api/types/plugin.ts b/packages/openapi-ts/src/plugins/@hey-api/types/plugin.ts index 830fd6f99..39135b1b6 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/types/plugin.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/types/plugin.ts @@ -1,21 +1,19 @@ -import type ts from 'typescript'; - -import type { Property } from '../../../compiler'; import { compiler } from '../../../compiler'; import type { IRContext } from '../../../ir/context'; import type { IROperationObject, - IRParameterObject, IRPathItemObject, IRPathsObject, IRSchemaObject, } from '../../../ir/ir'; import { operationResponsesMap } from '../../../ir/operation'; -import { deduplicateSchema } from '../../../ir/schema'; -import { ensureValidTypeScriptJavaScriptIdentifier } from '../../../openApi'; -import { escapeComment } from '../../../utils/escape'; -import { irRef, isRefOpenApiComponent } from '../../../utils/ref'; +import { irParametersToIrSchema } from '../../../ir/schema'; import type { PluginHandler } from '../../types'; +import { + componentsToType, + schemaToType, + type SchemaToTypeOptions, +} from '../../utils/types'; import { operationDataRef, operationErrorRef, @@ -23,633 +21,16 @@ import { } from '../services/plugin'; import type { Config } from './types'; -interface SchemaWithType['type']> - extends Omit { - type: Extract['type'], T>; -} - -const typesId = 'types'; - -const parseSchemaJsDoc = ({ schema }: { schema: IRSchemaObject }) => { - const comments = [ - schema.description && escapeComment(schema.description), - schema.deprecated && '@deprecated', - ]; - return comments; -}; - -const addJavaScriptEnum = ({ - $ref, - context, - schema, -}: { - $ref: string; - context: IRContext; - schema: SchemaWithType<'enum'>; -}) => { - const identifier = context.file({ id: typesId })!.identifier({ - $ref, - create: true, - namespace: 'value', - }); - - // TODO: parser - this is the old parser behavior where we would NOT - // print nested enum identifiers if they already exist. This is a - // blocker for referencing these identifiers within the file as - // we cannot guarantee just because they have a duplicate identifier, - // they have a duplicate value. - if (!identifier.created) { - return; - } - - const enumObject = schemaToEnumObject({ schema }); - - const expression = compiler.objectExpression({ - multiLine: true, - obj: enumObject.obj, - }); - const node = compiler.constVariable({ - assertion: 'const', - comment: parseSchemaJsDoc({ schema }), - exportConst: true, - expression, - name: identifier.name || '', - }); - return node; -}; - -const schemaToEnumObject = ({ schema }: { schema: IRSchemaObject }) => { - const typeofItems: Array< - | 'string' - | 'number' - | 'bigint' - | 'boolean' - | 'symbol' - | 'undefined' - | 'object' - | 'function' - > = []; - - const obj = (schema.items ?? []).map((item) => { - const typeOfItemConst = typeof item.const; - - if (!typeofItems.includes(typeOfItemConst)) { - typeofItems.push(typeOfItemConst); - } - - let key; - if (item.title) { - key = item.title; - } else if (typeOfItemConst === 'number') { - key = `_${item.const}`; - } else if (typeOfItemConst === 'boolean') { - const valid = typeOfItemConst ? 'true' : 'false'; - key = valid.toLocaleUpperCase(); - } else { - let valid = ensureValidTypeScriptJavaScriptIdentifier( - item.const as string, - ); - if (!valid) { - // TODO: parser - abstract empty string handling - valid = 'empty_string'; - } - key = valid.toLocaleUpperCase(); - } - return { - comments: parseSchemaJsDoc({ schema: item }), - key, - value: item.const, - }; - }); - - return { - obj, - typeofItems, - }; -}; - -const addTypeEnum = ({ - $ref, - context, - schema, -}: { - $ref: string; - context: IRContext; - schema: SchemaWithType<'enum'>; -}) => { - const identifier = context.file({ id: typesId })!.identifier({ - $ref, - create: true, - namespace: 'type', - }); - - // TODO: parser - this is the old parser behavior where we would NOT - // print nested enum identifiers if they already exist. This is a - // blocker for referencing these identifiers within the file as - // we cannot guarantee just because they have a duplicate identifier, - // they have a duplicate value. - if ( - !identifier.created && - !isRefOpenApiComponent($ref) && - context.config.plugins['@hey-api/types']?.enums !== 'typescript+namespace' - ) { - return; - } - - const node = compiler.typeAliasDeclaration({ - comment: parseSchemaJsDoc({ schema }), - exportType: true, - name: identifier.name || '', - type: schemaToType({ - context, - schema: { - ...schema, - type: undefined, - }, - }), - }); - return node; -}; - -const addTypeScriptEnum = ({ - $ref, - context, - schema, -}: { - $ref: string; - context: IRContext; - schema: SchemaWithType<'enum'>; -}) => { - const identifier = context.file({ id: typesId })!.identifier({ - $ref, - create: true, - namespace: 'value', - }); - - // TODO: parser - this is the old parser behavior where we would NOT - // print nested enum identifiers if they already exist. This is a - // blocker for referencing these identifiers within the file as - // we cannot guarantee just because they have a duplicate identifier, - // they have a duplicate value. - if ( - !identifier.created && - context.config.plugins['@hey-api/types']?.enums !== 'typescript+namespace' - ) { - return; - } - - const enumObject = schemaToEnumObject({ schema }); - - // TypeScript enums support only string and number values so we need to fallback to types - if ( - enumObject.typeofItems.filter( - (type) => type !== 'number' && type !== 'string', - ).length - ) { - const node = addTypeEnum({ - $ref, - context, - schema, - }); - return node; - } - - const node = compiler.enumDeclaration({ - leadingComment: parseSchemaJsDoc({ schema }), - name: identifier.name || '', - obj: enumObject.obj, - }); - return node; -}; - -const arrayTypeToIdentifier = ({ - context, - namespace, - schema, -}: { - context: IRContext; - namespace: Array; - schema: SchemaWithType<'array'>; -}) => { - if (!schema.items) { - return compiler.typeArrayNode( - compiler.keywordTypeNode({ - keyword: 'unknown', - }), - ); - } - - schema = deduplicateSchema({ schema }); - - // at least one item is guaranteed - const itemTypes = schema.items!.map((item) => - schemaToType({ - context, - namespace, - schema: item, - }), - ); - - if (itemTypes.length === 1) { - return compiler.typeArrayNode(itemTypes[0]); - } - - if (schema.logicalOperator === 'and') { - return compiler.typeArrayNode( - compiler.typeIntersectionNode({ types: itemTypes }), - ); - } - - return compiler.typeArrayNode(compiler.typeUnionNode({ types: itemTypes })); -}; - -const booleanTypeToIdentifier = ({ - schema, -}: { - context: IRContext; - namespace: Array; - schema: SchemaWithType<'boolean'>; -}) => { - if (schema.const !== undefined) { - return compiler.literalTypeNode({ - literal: compiler.ots.boolean(schema.const as boolean), - }); - } - - return compiler.keywordTypeNode({ - keyword: 'boolean', - }); -}; - -const enumTypeToIdentifier = ({ - $ref, - context, - namespace, - schema, -}: { - $ref?: string; - context: IRContext; - namespace: Array; - schema: SchemaWithType<'enum'>; -}): ts.TypeNode => { - // TODO: parser - add option to inline enums - if ($ref) { - const isRefComponent = isRefOpenApiComponent($ref); - - // when enums are disabled (default), emit only reusable components - // as types, otherwise the output would be broken if we skipped all enums - if (!context.config.plugins['@hey-api/types']?.enums && isRefComponent) { - const typeNode = addTypeEnum({ - $ref, - context, - schema, - }); - if (typeNode) { - context.file({ id: typesId })!.add(typeNode); - } - } - - if (context.config.plugins['@hey-api/types']?.enums === 'javascript') { - const typeNode = addTypeEnum({ - $ref, - context, - schema, - }); - if (typeNode) { - context.file({ id: typesId })!.add(typeNode); - } - - const objectNode = addJavaScriptEnum({ - $ref, - context, - schema, - }); - if (objectNode) { - context.file({ id: typesId })!.add(objectNode); - } - } - - if (context.config.plugins['@hey-api/types']?.enums === 'typescript') { - const enumNode = addTypeScriptEnum({ - $ref, - context, - schema, - }); - if (enumNode) { - context.file({ id: typesId })!.add(enumNode); - } - } - - if ( - context.config.plugins['@hey-api/types']?.enums === 'typescript+namespace' - ) { - const enumNode = addTypeScriptEnum({ - $ref, - context, - schema, - }); - if (enumNode) { - if (isRefComponent) { - context.file({ id: typesId })!.add(enumNode); - } else { - // emit enum inside TypeScript namespace - namespace.push(enumNode); - } - } - } - } - - const type = schemaToType({ - context, - schema: { - ...schema, - type: undefined, - }, - }); - return type; -}; - -const numberTypeToIdentifier = ({ - schema, -}: { - context: IRContext; - namespace: Array; - schema: SchemaWithType<'number'>; -}) => { - if (schema.const !== undefined) { - return compiler.literalTypeNode({ - literal: compiler.ots.number(schema.const as number), - }); - } - - return compiler.keywordTypeNode({ - keyword: 'number', - }); -}; - -const objectTypeToIdentifier = ({ - context, - namespace, - schema, -}: { - context: IRContext; - namespace: Array; - schema: SchemaWithType<'object'>; -}) => { - let indexProperty: Property | undefined; - const schemaProperties: Array = []; - let indexPropertyItems: Array = []; - const required = schema.required ?? []; - let hasOptionalProperties = false; - - for (const name in schema.properties) { - const property = schema.properties[name]; - const isRequired = required.includes(name); - schemaProperties.push({ - comment: parseSchemaJsDoc({ schema: property }), - isReadOnly: property.accessScope === 'read', - isRequired, - name, - type: schemaToType({ - $ref: `${irRef}${name}`, - context, - namespace, - schema: property, - }), - }); - indexPropertyItems.push(property); - - if (!isRequired) { - hasOptionalProperties = true; - } - } - - if ( - schema.additionalProperties && - (schema.additionalProperties.type !== 'never' || !indexPropertyItems.length) - ) { - if (schema.additionalProperties.type === 'never') { - indexPropertyItems = [schema.additionalProperties]; - } else { - indexPropertyItems.unshift(schema.additionalProperties); - } - - if (hasOptionalProperties) { - indexPropertyItems.push({ - type: 'undefined', - }); - } - - indexProperty = { - isRequired: true, - name: 'key', - type: schemaToType({ - context, - namespace, - schema: - indexPropertyItems.length === 1 - ? indexPropertyItems[0] - : { - items: indexPropertyItems, - logicalOperator: 'or', - }, - }), - }; - } - - return compiler.typeInterfaceNode({ - indexProperty, - properties: schemaProperties, - useLegacyResolution: false, - }); -}; - -const stringTypeToIdentifier = ({ - context, - schema, -}: { - context: IRContext; - namespace: Array; - schema: SchemaWithType<'string'>; -}) => { - if (schema.const !== undefined) { - return compiler.literalTypeNode({ - literal: compiler.stringLiteral({ text: schema.const as string }), - }); - } - - if (schema.format) { - if (schema.format === 'binary') { - return compiler.typeUnionNode({ - types: [ - compiler.typeReferenceNode({ - typeName: 'Blob', - }), - compiler.typeReferenceNode({ - typeName: 'File', - }), - ], - }); - } - - if (schema.format === 'date-time' || schema.format === 'date') { - // TODO: parser - add ability to skip type transformers - if (context.config.plugins['@hey-api/transformers']?.dates) { - return compiler.typeReferenceNode({ typeName: 'Date' }); - } - } - } - - return compiler.keywordTypeNode({ - keyword: 'string', - }); -}; - -const tupleTypeToIdentifier = ({ - context, - namespace, - schema, -}: { - context: IRContext; - namespace: Array; - schema: SchemaWithType<'tuple'>; -}) => { - const itemTypes: Array = []; - - for (const item of schema.items ?? []) { - itemTypes.push( - schemaToType({ - context, - namespace, - schema: item, - }), - ); - } - - return compiler.typeTupleNode({ - types: itemTypes, - }); -}; - -const schemaTypeToIdentifier = ({ - $ref, - context, - namespace, - schema, -}: { - $ref?: string; - context: IRContext; - namespace: Array; - schema: IRSchemaObject; -}): ts.TypeNode => { - switch (schema.type as Required['type']) { - case 'array': - return arrayTypeToIdentifier({ - context, - namespace, - schema: schema as SchemaWithType<'array'>, - }); - case 'boolean': - return booleanTypeToIdentifier({ - context, - namespace, - schema: schema as SchemaWithType<'boolean'>, - }); - case 'enum': - return enumTypeToIdentifier({ - $ref, - context, - namespace, - schema: schema as SchemaWithType<'enum'>, - }); - case 'never': - return compiler.keywordTypeNode({ - keyword: 'never', - }); - case 'null': - return compiler.literalTypeNode({ - literal: compiler.null(), - }); - case 'number': - return numberTypeToIdentifier({ - context, - namespace, - schema: schema as SchemaWithType<'number'>, - }); - case 'object': - return objectTypeToIdentifier({ - context, - namespace, - schema: schema as SchemaWithType<'object'>, - }); - case 'string': - return stringTypeToIdentifier({ - context, - namespace, - schema: schema as SchemaWithType<'string'>, - }); - case 'tuple': - return tupleTypeToIdentifier({ - context, - namespace, - schema: schema as SchemaWithType<'tuple'>, - }); - case 'undefined': - return compiler.keywordTypeNode({ - keyword: 'undefined', - }); - case 'unknown': - return compiler.keywordTypeNode({ - keyword: 'unknown', - }); - case 'void': - return compiler.keywordTypeNode({ - keyword: 'void', - }); - } -}; - -const irParametersToIrSchema = ({ - parameters, -}: { - parameters: Record; -}): IRSchemaObject => { - const irSchema: IRSchemaObject = { - type: 'object', - }; - - if (parameters) { - const properties: Record = {}; - const required: Array = []; - - for (const name in parameters) { - const parameter = parameters[name]; - - properties[name] = deduplicateSchema({ - schema: parameter.schema, - }); - - if (parameter.required) { - required.push(name); - } - } - - irSchema.properties = properties; - - if (required.length) { - irSchema.required = required; - } - } - - return irSchema; -}; +export const typesId = 'types'; const operationToDataType = ({ context, operation, + options, }: { context: IRContext; operation: IROperationObject; + options: SchemaToTypeOptions; }) => { const data: IRSchemaObject = { type: 'object', @@ -732,7 +113,7 @@ const operationToDataType = ({ exportType: true, name: identifier.name || '', type: schemaToType({ - context, + options, schema: data, }), }); @@ -743,13 +124,16 @@ const operationToDataType = ({ const operationToType = ({ context, operation, + options, }: { context: IRContext; operation: IROperationObject; + options: SchemaToTypeOptions; }) => { operationToDataType({ context, operation, + options, }); const { error, response } = operationResponsesMap(operation); @@ -764,7 +148,7 @@ const operationToType = ({ exportType: true, name: identifier.name || '', type: schemaToType({ - context, + options, schema: error, }), }); @@ -781,7 +165,7 @@ const operationToType = ({ exportType: true, name: identifier.name || '', type: schemaToType({ - context, + options, schema: response, }), }); @@ -789,146 +173,18 @@ const operationToType = ({ } }; -export const schemaToType = ({ - $ref, - context, - namespace = [], - schema, -}: { - $ref?: string; - context: IRContext; - namespace?: Array; - schema: IRSchemaObject; -}): ts.TypeNode => { - let type: ts.TypeNode | undefined; - - if (schema.$ref) { - const identifier = context.file({ id: typesId })!.identifier({ - $ref: schema.$ref, - create: true, - namespace: 'type', - }); - type = compiler.typeReferenceNode({ - typeName: identifier.name || '', - }); - } else if (schema.type) { - type = schemaTypeToIdentifier({ - $ref, - context, - namespace, - schema, - }); - } else if (schema.items) { - schema = deduplicateSchema({ schema }); - if (schema.items) { - const itemTypes = schema.items.map((item) => - schemaToType({ - context, - namespace, - schema: item, - }), - ); - type = - schema.logicalOperator === 'and' - ? compiler.typeIntersectionNode({ types: itemTypes }) - : compiler.typeUnionNode({ types: itemTypes }); - } else { - type = schemaToType({ - context, - namespace, - schema, - }); - } - } else { - // catch-all fallback for failed schemas - type = schemaTypeToIdentifier({ - context, - namespace, - schema: { - type: 'unknown', - }, - }); - } - - // emit nodes only if $ref points to a reusable component - if ($ref && isRefOpenApiComponent($ref)) { - // emit namespace if it has any members - if (namespace.length) { - const identifier = context.file({ id: typesId })!.identifier({ - $ref, - create: true, - namespace: 'value', - }); - const node = compiler.namespaceDeclaration({ - name: identifier.name || '', - statements: namespace, - }); - context.file({ id: typesId })!.add(node); - } - - // enum handler emits its own artifacts - if (schema.type !== 'enum') { - const identifier = context.file({ id: typesId })!.identifier({ - $ref, - create: true, - namespace: 'type', - }); - const node = compiler.typeAliasDeclaration({ - comment: parseSchemaJsDoc({ schema }), - exportType: true, - name: identifier.name || '', - type, - }); - context.file({ id: typesId })!.add(node); - } - } - - return type; -}; - export const handler: PluginHandler = ({ context }) => { - context.createFile({ + const file = context.createFile({ id: typesId, path: 'types', }); + const options: SchemaToTypeOptions = { + enums: context.config.plugins['@hey-api/types']?.enums, + file, + useTransformersDate: context.config.plugins['@hey-api/transformers']?.dates, + }; - if (context.ir.components) { - for (const name in context.ir.components.schemas) { - const schema = context.ir.components.schemas[name]; - const $ref = `#/components/schemas/${name}`; - - try { - schemaToType({ - $ref, - context, - schema, - }); - } catch (error) { - console.error( - `🔥 Failed to process schema ${name}\n$ref: ${$ref}\nschema: ${JSON.stringify(schema, null, 2)}`, - ); - throw error; - } - } - - for (const name in context.ir.components.parameters) { - const parameter = context.ir.components.parameters[name]; - const $ref = `#/components/parameters/${name}`; - - try { - schemaToType({ - $ref, - context, - schema: parameter.schema, - }); - } catch (error) { - console.error( - `🔥 Failed to process schema ${name}\n$ref: ${$ref}\nschema: ${JSON.stringify(parameter.schema, null, 2)}`, - ); - throw error; - } - } - } + componentsToType({ context, options }); // TODO: parser - once types are a plugin, this logic can be simplified // provide config option on types to generate path types and services @@ -947,6 +203,7 @@ export const handler: PluginHandler = ({ context }) => { operationToType({ context, operation, + options, }); } } diff --git a/packages/openapi-ts/src/plugins/@tanstack/query-core/plugin.ts b/packages/openapi-ts/src/plugins/@tanstack/query-core/plugin.ts index 07f44e3d9..7e6844b86 100644 --- a/packages/openapi-ts/src/plugins/@tanstack/query-core/plugin.ts +++ b/packages/openapi-ts/src/plugins/@tanstack/query-core/plugin.ts @@ -33,7 +33,7 @@ import { operationOptionsType, serviceFunctionIdentifier, } from '../../@hey-api/services/plugin-legacy'; -import { schemaToType } from '../../@hey-api/types/plugin'; +import { typesId } from '../../@hey-api/types/plugin'; import type { PluginHandler } from '../../types'; import type { Config as AngularQueryConfig } from '../angular-query-experimental'; import type { Config as ReactQueryConfig } from '../react-query'; @@ -890,11 +890,17 @@ export const handler: PluginHandler< const typeQueryKey = `${queryKeyName}<${typeData}>`; const typePageObjectParam = `Pick<${typeQueryKey}[0], 'body' | 'headers' | 'path' | 'query'>`; + const options: SchemaToTypeOptions = { + enums: context.config.plugins['@hey-api/types']?.enums, + file: context.file({ id: typesId })!, + useTransformersDate: + context.config.plugins['@hey-api/transformers']?.dates, + }; // TODO: parser - this is a bit clunky, need to compile type to string because // `compiler.returnFunctionCall()` accepts only strings, should be cleaned up const typePageParam = `${tsNodeToString({ node: schemaToType({ - context, + options, schema: pagination.schema, }), unescape: true, diff --git a/packages/openapi-ts/src/plugins/utils/types.ts b/packages/openapi-ts/src/plugins/utils/types.ts new file mode 100644 index 000000000..b6cdc1709 --- /dev/null +++ b/packages/openapi-ts/src/plugins/utils/types.ts @@ -0,0 +1,694 @@ +import type ts from 'typescript'; + +import type { Property } from '../../compiler'; +import { compiler } from '../../compiler'; +import type { TypeScriptFile } from '../../generate/files'; +import type { IRContext } from '../../ir/context'; +import type { IRSchemaObject } from '../../ir/ir'; +import { deduplicateSchema } from '../../ir/schema'; +import { ensureValidTypeScriptJavaScriptIdentifier } from '../../openApi'; +import { escapeComment } from '../../utils/escape'; +import { irRef, isRefOpenApiComponent } from '../../utils/ref'; + +export type SchemaToTypeOptions = { + enums?: 'javascript' | 'typescript' | 'typescript+namespace' | false; + file: TypeScriptFile; + useTransformersDate?: boolean; +}; + +interface SchemaWithType['type']> + extends Omit { + type: Extract['type'], T>; +} + +const parseSchemaJsDoc = ({ schema }: { schema: IRSchemaObject }) => { + const comments = [ + schema.description && escapeComment(schema.description), + schema.deprecated && '@deprecated', + ]; + return comments; +}; + +const addJavaScriptEnum = ({ + $ref, + schema, + options, +}: { + $ref: string; + options: SchemaToTypeOptions; + schema: SchemaWithType<'enum'>; +}) => { + const identifier = options.file.identifier({ + $ref, + create: true, + namespace: 'value', + }); + + // TODO: parser - this is the old parser behavior where we would NOT + // print nested enum identifiers if they already exist. This is a + // blocker for referencing these identifiers within the file as + // we cannot guarantee just because they have a duplicate identifier, + // they have a duplicate value. + if (!identifier.created) { + return; + } + + const enumObject = schemaToEnumObject({ schema }); + + const expression = compiler.objectExpression({ + multiLine: true, + obj: enumObject.obj, + }); + const node = compiler.constVariable({ + assertion: 'const', + comment: parseSchemaJsDoc({ schema }), + exportConst: true, + expression, + name: identifier.name || '', + }); + return node; +}; + +const schemaToEnumObject = ({ schema }: { schema: IRSchemaObject }) => { + const typeofItems: Array< + | 'string' + | 'number' + | 'bigint' + | 'boolean' + | 'symbol' + | 'undefined' + | 'object' + | 'function' + > = []; + + const obj = (schema.items ?? []).map((item) => { + const typeOfItemConst = typeof item.const; + + if (!typeofItems.includes(typeOfItemConst)) { + typeofItems.push(typeOfItemConst); + } + + let key; + if (item.title) { + key = item.title; + } else if (typeOfItemConst === 'number') { + key = `_${item.const}`; + } else if (typeOfItemConst === 'boolean') { + const valid = typeOfItemConst ? 'true' : 'false'; + key = valid.toLocaleUpperCase(); + } else { + let valid = ensureValidTypeScriptJavaScriptIdentifier( + item.const as string, + ); + if (!valid) { + // TODO: parser - abstract empty string handling + valid = 'empty_string'; + } + key = valid.toLocaleUpperCase(); + } + return { + comments: parseSchemaJsDoc({ schema: item }), + key, + value: item.const, + }; + }); + + return { + obj, + typeofItems, + }; +}; + +const addTypeEnum = ({ + $ref, + schema, + options, +}: { + $ref: string; + options: SchemaToTypeOptions; + schema: SchemaWithType<'enum'>; +}) => { + const identifier = options.file.identifier({ + $ref, + create: true, + namespace: 'type', + }); + + // TODO: parser - this is the old parser behavior where we would NOT + // print nested enum identifiers if they already exist. This is a + // blocker for referencing these identifiers within the file as + // we cannot guarantee just because they have a duplicate identifier, + // they have a duplicate value. + if (!identifier.created && options.enums !== 'typescript+namespace') { + return; + } + + const node = compiler.typeAliasDeclaration({ + comment: parseSchemaJsDoc({ schema }), + exportType: true, + name: identifier.name || '', + type: schemaToType({ + options, + schema: { + ...schema, + type: undefined, + }, + }), + }); + return node; +}; + +const addTypeScriptEnum = ({ + $ref, + schema, + options, +}: { + $ref: string; + options: SchemaToTypeOptions; + schema: SchemaWithType<'enum'>; +}) => { + const identifier = options.file.identifier({ + $ref, + create: true, + namespace: 'value', + }); + + // TODO: parser - this is the old parser behavior where we would NOT + // print nested enum identifiers if they already exist. This is a + // blocker for referencing these identifiers within the file as + // we cannot guarantee just because they have a duplicate identifier, + // they have a duplicate value. + if (!identifier.created && options.enums !== 'typescript+namespace') { + return; + } + + const enumObject = schemaToEnumObject({ schema }); + + // TypeScript enums support only string and number values so we need to fallback to types + if ( + enumObject.typeofItems.filter( + (type) => type !== 'number' && type !== 'string', + ).length + ) { + const node = addTypeEnum({ + $ref, + options, + schema, + }); + return node; + } + + const node = compiler.enumDeclaration({ + leadingComment: parseSchemaJsDoc({ schema }), + name: identifier.name || '', + obj: enumObject.obj, + }); + return node; +}; + +const arrayTypeToIdentifier = ({ + namespace, + schema, + options, +}: { + namespace: Array; + options: SchemaToTypeOptions; + schema: SchemaWithType<'array'>; +}) => { + if (!schema.items) { + return compiler.typeArrayNode( + compiler.keywordTypeNode({ + keyword: 'unknown', + }), + ); + } + + schema = deduplicateSchema({ schema }); + + // at least one item is guaranteed + const itemTypes = schema.items!.map((item) => + schemaToType({ + namespace, + options, + schema: item, + }), + ); + + if (itemTypes.length === 1) { + return compiler.typeArrayNode(itemTypes[0]); + } + + if (schema.logicalOperator === 'and') { + return compiler.typeArrayNode( + compiler.typeIntersectionNode({ types: itemTypes }), + ); + } + + return compiler.typeArrayNode(compiler.typeUnionNode({ types: itemTypes })); +}; + +const booleanTypeToIdentifier = ({ + schema, +}: { + schema: SchemaWithType<'boolean'>; +}) => { + if (schema.const !== undefined) { + return compiler.literalTypeNode({ + literal: compiler.ots.boolean(schema.const as boolean), + }); + } + + return compiler.keywordTypeNode({ + keyword: 'boolean', + }); +}; + +const enumTypeToIdentifier = ({ + $ref, + namespace, + schema, + options, +}: { + $ref?: string; + namespace: Array; + options: SchemaToTypeOptions; + schema: SchemaWithType<'enum'>; +}): ts.TypeNode => { + // TODO: parser - add option to inline enums + if ($ref) { + const isRefComponent = isRefOpenApiComponent($ref); + + // when enums are disabled (default), emit only reusable components + // as types, otherwise the output would be broken if we skipped all enums + if (!options.enums && isRefComponent) { + const typeNode = addTypeEnum({ + $ref, + options, + schema, + }); + if (typeNode) { + options.file.add(typeNode); + } + } + + if (options.enums === 'javascript') { + const typeNode = addTypeEnum({ + $ref, + options, + schema, + }); + if (typeNode) { + options.file.add(typeNode); + } + + const objectNode = addJavaScriptEnum({ + $ref, + options, + schema, + }); + if (objectNode) { + options.file.add(objectNode); + } + } + + if (options.enums === 'typescript') { + const enumNode = addTypeScriptEnum({ + $ref, + options, + schema, + }); + if (enumNode) { + options.file.add(enumNode); + } + } + + if (options.enums === 'typescript+namespace') { + const enumNode = addTypeScriptEnum({ + $ref, + options, + schema, + }); + if (enumNode) { + if (isRefComponent) { + options.file.add(enumNode); + } else { + // emit enum inside TypeScript namespace + namespace.push(enumNode); + } + } + } + } + + const type = schemaToType({ + options, + schema: { + ...schema, + type: undefined, + }, + }); + return type; +}; + +const numberTypeToIdentifier = ({ + schema, +}: { + schema: SchemaWithType<'number'>; +}) => { + if (schema.const !== undefined) { + return compiler.literalTypeNode({ + literal: compiler.ots.number(schema.const as number), + }); + } + + return compiler.keywordTypeNode({ + keyword: 'number', + }); +}; + +const objectTypeToIdentifier = ({ + namespace, + schema, + options, +}: { + namespace: Array; + options: SchemaToTypeOptions; + schema: SchemaWithType<'object'>; +}) => { + let indexProperty: Property | undefined; + const schemaProperties: Array = []; + const indexPropertyItems: Array = []; + const required = schema.required ?? []; + let hasOptionalProperties = false; + + for (const name in schema.properties) { + const property = schema.properties[name]; + const isRequired = required.includes(name); + schemaProperties.push({ + comment: parseSchemaJsDoc({ schema: property }), + isReadOnly: property.accessScope === 'read', + isRequired, + name, + type: schemaToType({ + $ref: `${irRef}${name}`, + namespace, + options, + schema: property, + }), + }); + indexPropertyItems.push(property); + + if (!isRequired) { + hasOptionalProperties = true; + } + } + + if (schema.additionalProperties) { + indexPropertyItems.unshift(schema.additionalProperties); + + if (hasOptionalProperties) { + indexPropertyItems.push({ + type: 'void', + }); + } + + indexProperty = { + isRequired: true, + name: 'key', + type: schemaToType({ + namespace, + options, + schema: + indexPropertyItems.length === 1 + ? indexPropertyItems[0] + : { + items: indexPropertyItems, + logicalOperator: 'or', + }, + }), + }; + } + + return compiler.typeInterfaceNode({ + indexProperty, + properties: schemaProperties, + useLegacyResolution: false, + }); +}; + +const stringTypeToIdentifier = ({ + schema, + options, +}: { + options: SchemaToTypeOptions; + schema: SchemaWithType<'string'>; +}) => { + if (schema.const !== undefined) { + return compiler.literalTypeNode({ + literal: compiler.stringLiteral({ text: schema.const as string }), + }); + } + + if (schema.format) { + if (schema.format === 'binary') { + return compiler.typeUnionNode({ + types: [ + compiler.typeReferenceNode({ + typeName: 'Blob', + }), + compiler.typeReferenceNode({ + typeName: 'File', + }), + ], + }); + } + + if (schema.format === 'date-time' || schema.format === 'date') { + // TODO: parser - add ability to skip type transformers + if (options.useTransformersDate) { + return compiler.typeReferenceNode({ typeName: 'Date' }); + } + } + } + + return compiler.keywordTypeNode({ + keyword: 'string', + }); +}; + +const tupleTypeToIdentifier = ({ + namespace, + schema, + options, +}: { + namespace: Array; + options: SchemaToTypeOptions; + schema: SchemaWithType<'tuple'>; +}) => { + const itemTypes: Array = []; + + for (const item of schema.items ?? []) { + itemTypes.push( + schemaToType({ + namespace, + options, + schema: item, + }), + ); + } + + return compiler.typeTupleNode({ + types: itemTypes, + }); +}; + +const schemaTypeToIdentifier = ({ + $ref, + namespace, + schema, + options, +}: { + $ref?: string; + namespace: Array; + options: SchemaToTypeOptions; + schema: IRSchemaObject; +}): ts.TypeNode => { + switch (schema.type as Required['type']) { + case 'array': + return arrayTypeToIdentifier({ + namespace, + options, + schema: schema as SchemaWithType<'array'>, + }); + case 'boolean': + return booleanTypeToIdentifier({ + schema: schema as SchemaWithType<'boolean'>, + }); + case 'enum': + return enumTypeToIdentifier({ + $ref, + namespace, + options, + schema: schema as SchemaWithType<'enum'>, + }); + case 'null': + return compiler.literalTypeNode({ + literal: compiler.null(), + }); + case 'number': + return numberTypeToIdentifier({ + schema: schema as SchemaWithType<'number'>, + }); + case 'object': + return objectTypeToIdentifier({ + namespace, + options, + schema: schema as SchemaWithType<'object'>, + }); + case 'string': + return stringTypeToIdentifier({ + options, + schema: schema as SchemaWithType<'string'>, + }); + case 'tuple': + return tupleTypeToIdentifier({ + namespace, + options, + schema: schema as SchemaWithType<'tuple'>, + }); + case 'unknown': + return compiler.keywordTypeNode({ + keyword: 'unknown', + }); + case 'void': + return compiler.keywordTypeNode({ + keyword: 'undefined', + }); + } +}; + +export const schemaToType = ({ + $ref, + namespace = [], + schema, + options, +}: { + $ref?: string; + namespace?: Array; + options: SchemaToTypeOptions; + schema: IRSchemaObject; +}): ts.TypeNode => { + let type: ts.TypeNode | undefined; + + if (schema.$ref) { + const identifier = options.file.identifier({ + $ref: schema.$ref, + create: true, + namespace: 'type', + }); + type = compiler.typeReferenceNode({ + typeName: identifier.name || '', + }); + } else if (schema.type) { + type = schemaTypeToIdentifier({ + $ref, + namespace, + options, + schema, + }); + } else if (schema.items) { + schema = deduplicateSchema({ schema }); + if (schema.items) { + const itemTypes = schema.items.map((item) => + schemaToType({ + namespace, + options, + schema: item, + }), + ); + type = + schema.logicalOperator === 'and' + ? compiler.typeIntersectionNode({ types: itemTypes }) + : compiler.typeUnionNode({ types: itemTypes }); + } else { + type = schemaToType({ + namespace, + options, + schema, + }); + } + } else { + // catch-all fallback for failed schemas + type = schemaTypeToIdentifier({ + namespace, + options, + schema: { + type: 'unknown', + }, + }); + } + + // emit nodes only if $ref points to a reusable component + if ($ref && isRefOpenApiComponent($ref)) { + // emit namespace if it has any members + if (namespace.length) { + const identifier = options.file.identifier({ + $ref, + create: true, + namespace: 'value', + }); + const node = compiler.namespaceDeclaration({ + name: identifier.name || '', + statements: namespace, + }); + options.file.add(node); + } + + // enum handler emits its own artifacts + if (schema.type !== 'enum') { + const identifier = options.file.identifier({ + $ref, + create: true, + namespace: 'type', + }); + const node = compiler.typeAliasDeclaration({ + comment: parseSchemaJsDoc({ schema }), + exportType: true, + name: identifier.name || '', + type, + }); + options.file.add(node); + } + } + + return type; +}; + +export const componentsToType = ({ + context, + options, +}: { + context: IRContext; + options: SchemaToTypeOptions; +}) => { + if (context.ir.components) { + for (const name in context.ir.components.schemas) { + const schema = context.ir.components.schemas[name]; + + schemaToType({ + $ref: `#/components/schemas/${name}`, + options, + schema, + }); + } + + for (const name in context.ir.components.parameters) { + const parameter = context.ir.components.parameters[name]; + + schemaToType({ + $ref: `#/components/parameters/${name}`, + options, + schema: parameter.schema, + }); + } + } +}; -- 2.51.2 From 5514de46a8c913ddc40f07d0142c80266e9837cd Mon Sep 17 00:00:00 2001 From: Jacob Cohen Date: Wed, 13 Nov 2024 23:02:36 -0500 Subject: [PATCH 02/13] feat: add fastify plugin --- .changeset/gorgeous-cups-search.md | 5 + .../openapi-ts-fastify/openapi-ts.config.ts | 10 + examples/openapi-ts-fastify/package.json | 20 + .../openapi-ts-fastify/src/gen/fastify.gen.ts | 46 + examples/openapi-ts-fastify/src/gen/index.ts | 3 + .../src/gen/services.gen.ts | 60 + .../openapi-ts-fastify/src/gen/types.gen.ts | 46 + examples/openapi-ts-fastify/src/handlers.ts | 14 + examples/openapi-ts-fastify/src/index.ts | 10 + examples/openapi-ts-fastify/src/server.ts | 23 + examples/openapi-ts-fastify/test/pets.test.ts | 31 + examples/openapi-ts-fastify/tsconfig.json | 13 + packages/openapi-ts/package.json | 1 + .../plugins/@tanstack/query-core/plugin.ts | 1 + .../openapi-ts/src/plugins/fastify/config.ts | 20 + .../openapi-ts/src/plugins/fastify/index.ts | 2 + .../openapi-ts/src/plugins/fastify/plugin.ts | 182 ++ .../openapi-ts/src/plugins/fastify/types.d.ts | 17 + packages/openapi-ts/src/plugins/index.ts | 6 +- packages/openapi-ts/src/plugins/types.d.ts | 1 + .../openapi-ts/src/plugins/utils/types.ts | 33 +- .../3.0.x/plugins/fastify/fastify.gen.ts | 1473 ++++++++++++++++ .../3.0.x/plugins/fastify/index.ts | 3 + .../3.0.x/plugins/fastify/services.gen.ts | 382 +++++ .../3.0.x/plugins/fastify/types.gen.ts | 1470 ++++++++++++++++ .../3.1.x/plugins/fastify/fastify.gen.ts | 1477 +++++++++++++++++ .../3.1.x/plugins/fastify/index.ts | 3 + .../3.1.x/plugins/fastify/services.gen.ts | 382 +++++ .../3.1.x/plugins/fastify/types.gen.ts | 1474 ++++++++++++++++ packages/openapi-ts/test/plugins.spec.ts | 7 + pnpm-lock.yaml | 571 ++++++- 31 files changed, 7743 insertions(+), 43 deletions(-) create mode 100644 .changeset/gorgeous-cups-search.md create mode 100644 examples/openapi-ts-fastify/openapi-ts.config.ts create mode 100644 examples/openapi-ts-fastify/package.json create mode 100644 examples/openapi-ts-fastify/src/gen/fastify.gen.ts create mode 100644 examples/openapi-ts-fastify/src/gen/index.ts create mode 100644 examples/openapi-ts-fastify/src/gen/services.gen.ts create mode 100644 examples/openapi-ts-fastify/src/gen/types.gen.ts create mode 100644 examples/openapi-ts-fastify/src/handlers.ts create mode 100644 examples/openapi-ts-fastify/src/index.ts create mode 100644 examples/openapi-ts-fastify/src/server.ts create mode 100644 examples/openapi-ts-fastify/test/pets.test.ts create mode 100644 examples/openapi-ts-fastify/tsconfig.json create mode 100644 packages/openapi-ts/src/plugins/fastify/config.ts create mode 100644 packages/openapi-ts/src/plugins/fastify/index.ts create mode 100644 packages/openapi-ts/src/plugins/fastify/plugin.ts create mode 100644 packages/openapi-ts/src/plugins/fastify/types.d.ts create mode 100644 packages/openapi-ts/test/__snapshots__/3.0.x/plugins/fastify/fastify.gen.ts create mode 100644 packages/openapi-ts/test/__snapshots__/3.0.x/plugins/fastify/index.ts create mode 100644 packages/openapi-ts/test/__snapshots__/3.0.x/plugins/fastify/services.gen.ts create mode 100644 packages/openapi-ts/test/__snapshots__/3.0.x/plugins/fastify/types.gen.ts create mode 100644 packages/openapi-ts/test/__snapshots__/3.1.x/plugins/fastify/fastify.gen.ts create mode 100644 packages/openapi-ts/test/__snapshots__/3.1.x/plugins/fastify/index.ts create mode 100644 packages/openapi-ts/test/__snapshots__/3.1.x/plugins/fastify/services.gen.ts create mode 100644 packages/openapi-ts/test/__snapshots__/3.1.x/plugins/fastify/types.gen.ts diff --git a/.changeset/gorgeous-cups-search.md b/.changeset/gorgeous-cups-search.md new file mode 100644 index 000000000..3a26359c3 --- /dev/null +++ b/.changeset/gorgeous-cups-search.md @@ -0,0 +1,5 @@ +--- +'@hey-api/openapi-ts': minor +--- + +feat: add fastify-openapi-glue plugin diff --git a/examples/openapi-ts-fastify/openapi-ts.config.ts b/examples/openapi-ts-fastify/openapi-ts.config.ts new file mode 100644 index 000000000..268779158 --- /dev/null +++ b/examples/openapi-ts-fastify/openapi-ts.config.ts @@ -0,0 +1,10 @@ +import { defineConfig } from '@hey-api/openapi-ts'; + +export default defineConfig({ + client: '@hey-api/client-fetch', + experimentalParser: true, + input: + 'https://gist.githubusercontent.com/seriousme/55bd4c8ba2e598e416bb5543dcd362dc/raw/cf0b86ba37bb54bf1a6bf047c0ecf2a0ce4c62e0/petstore-v3.1.json', + output: './src/gen', + plugins: ['fastify'], +}); diff --git a/examples/openapi-ts-fastify/package.json b/examples/openapi-ts-fastify/package.json new file mode 100644 index 000000000..877466ea9 --- /dev/null +++ b/examples/openapi-ts-fastify/package.json @@ -0,0 +1,20 @@ +{ + "name": "@example/openapi-ts-fastify", + "private": true, + "version": "0.0.1", + "type": "module", + "scripts": { + "openapi-ts": "openapi-ts", + "typecheck": "tsc --noEmit", + "test": "vitest" + }, + "dependencies": { + "@hey-api/openapi-ts": "workspace:*", + "fastify": "5.0.0", + "fastify-openapi-glue": "4.7.1" + }, + "devDependencies": { + "@hey-api/client-fetch": "workspace:*", + "vitest": "2.1.5" + } +} diff --git a/examples/openapi-ts-fastify/src/gen/fastify.gen.ts b/examples/openapi-ts-fastify/src/gen/fastify.gen.ts new file mode 100644 index 000000000..f548242ab --- /dev/null +++ b/examples/openapi-ts-fastify/src/gen/fastify.gen.ts @@ -0,0 +1,46 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { RouteHandler } from 'fastify'; + +export type Pet = { + id: number; + name: string; + tag?: string; +}; + +export type Pets = Array; + +export type Error = { + code: number; + message: string; +}; + +export type RouteHandlers = { + createPets: RouteHandler<{ + Reply: { + 201: unknown; + }; + }>; + listPets: RouteHandler<{ + Querystring?: { + /** + * How many items to return at one time (max 100) + */ + limit?: number; + }; + Reply: { + 200: Pets; + }; + }>; + showPetById: RouteHandler<{ + Params: { + /** + * The id of the pet to retrieve + */ + petId: string; + }; + Reply: { + 200: Pet; + }; + }>; +}; diff --git a/examples/openapi-ts-fastify/src/gen/index.ts b/examples/openapi-ts-fastify/src/gen/index.ts new file mode 100644 index 000000000..7311eb12c --- /dev/null +++ b/examples/openapi-ts-fastify/src/gen/index.ts @@ -0,0 +1,3 @@ +// This file is auto-generated by @hey-api/openapi-ts +export * from './services.gen'; +export * from './types.gen'; diff --git a/examples/openapi-ts-fastify/src/gen/services.gen.ts b/examples/openapi-ts-fastify/src/gen/services.gen.ts new file mode 100644 index 000000000..40d260228 --- /dev/null +++ b/examples/openapi-ts-fastify/src/gen/services.gen.ts @@ -0,0 +1,60 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { + createClient, + createConfig, + type Options, +} from '@hey-api/client-fetch'; + +import type { + CreatePetsError, + ListPetsData, + ListPetsError, + ListPetsResponse, + ShowPetByIdData, + ShowPetByIdError, + ShowPetByIdResponse, +} from './types.gen'; + +export const client = createClient(createConfig()); + +/** + * List all pets + */ +export const listPets = ( + options?: Options, +) => + (options?.client ?? client).get< + ListPetsResponse, + ListPetsError, + ThrowOnError + >({ + ...options, + url: '/pets', + }); + +/** + * Create a pet + */ +export const createPets = ( + options?: Options, +) => + (options?.client ?? client).post({ + ...options, + url: '/pets', + }); + +/** + * Info for a specific pet + */ +export const showPetById = ( + options: Options, +) => + (options?.client ?? client).get< + ShowPetByIdResponse, + ShowPetByIdError, + ThrowOnError + >({ + ...options, + url: '/pets/{petId}', + }); diff --git a/examples/openapi-ts-fastify/src/gen/types.gen.ts b/examples/openapi-ts-fastify/src/gen/types.gen.ts new file mode 100644 index 000000000..8e0f71e19 --- /dev/null +++ b/examples/openapi-ts-fastify/src/gen/types.gen.ts @@ -0,0 +1,46 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export type Pet = { + id: number; + name: string; + tag?: string; +}; + +export type Pets = Array; + +export type Error = { + code: number; + message: string; +}; + +export type ListPetsData = { + body?: never; + path?: never; + query?: { + /** + * How many items to return at one time (max 100) + */ + limit?: number; + }; +}; + +export type ListPetsError = Error; + +export type ListPetsResponse = Pets; + +export type CreatePetsError = Error; + +export type ShowPetByIdData = { + body?: never; + path: { + /** + * The id of the pet to retrieve + */ + petId: string; + }; + query?: never; +}; + +export type ShowPetByIdError = Error; + +export type ShowPetByIdResponse = Pet; diff --git a/examples/openapi-ts-fastify/src/handlers.ts b/examples/openapi-ts-fastify/src/handlers.ts new file mode 100644 index 000000000..fbb509ae7 --- /dev/null +++ b/examples/openapi-ts-fastify/src/handlers.ts @@ -0,0 +1,14 @@ +import type { Pet, RouteHandlers } from './gen/fastify.gen'; + +export const serviceHandlers: Pick = { + showPetById(request, reply) { + const { + params: { petId }, + } = request; + const pet: Pet = { + id: Number(petId), + name: 'petname', + }; + reply.code(200).send(pet); + }, +}; diff --git a/examples/openapi-ts-fastify/src/index.ts b/examples/openapi-ts-fastify/src/index.ts new file mode 100644 index 000000000..fd9b664a1 --- /dev/null +++ b/examples/openapi-ts-fastify/src/index.ts @@ -0,0 +1,10 @@ +import { buildServer } from './server'; + +const fastify = buildServer(); + +fastify.listen({ port: 3000 }, function (err) { + if (err) { + fastify.log.error(err); + process.exit(1); + } +}); diff --git a/examples/openapi-ts-fastify/src/server.ts b/examples/openapi-ts-fastify/src/server.ts new file mode 100644 index 000000000..bc8ea90b5 --- /dev/null +++ b/examples/openapi-ts-fastify/src/server.ts @@ -0,0 +1,23 @@ +import Fastify from 'fastify'; +import glue from 'fastify-openapi-glue'; + +import { serviceHandlers } from './handlers'; + +export const buildServer = () => { + const fastify = Fastify(); + + const specification = fetch( + 'https://gist.githubusercontent.com/seriousme/55bd4c8ba2e598e416bb5543dcd362dc/raw/cf0b86ba37bb54bf1a6bf047c0ecf2a0ce4c62e0/petstore-v3.1.json', + ) + .then((reply) => reply.json()) + .then((data) => data); + console.log(specification); + + fastify.register(glue, { + prefix: 'v3', + serviceHandlers, + specification, + }); + + return fastify; +}; diff --git a/examples/openapi-ts-fastify/test/pets.test.ts b/examples/openapi-ts-fastify/test/pets.test.ts new file mode 100644 index 000000000..68a6c1b11 --- /dev/null +++ b/examples/openapi-ts-fastify/test/pets.test.ts @@ -0,0 +1,31 @@ +import { type FastifyInstance } from 'fastify'; +import { client, showPetById } from 'src/gen'; +import { buildServer } from 'src/server'; +import { afterAll, beforeAll, describe, expect, test } from 'vitest'; + +describe('/pet/findByTags', () => { + let server: FastifyInstance; + + beforeAll(async () => { + server = buildServer(); + await server.listen(); + + // @ts-ignore + const baseUrl = `http://localhost:${server.server.address().port}/v3`; + client.setConfig({ baseUrl }); + }); + + afterAll(async () => { + await Promise.all([server.close()]); + }); + + test('showPetById', async () => { + const result = await showPetById({ + client, + path: { + petId: '123', + }, + }); + expect(result.response.status).toBe(200); + }); +}); diff --git a/examples/openapi-ts-fastify/tsconfig.json b/examples/openapi-ts-fastify/tsconfig.json new file mode 100644 index 000000000..aa0dd8f77 --- /dev/null +++ b/examples/openapi-ts-fastify/tsconfig.json @@ -0,0 +1,13 @@ +{ + "include": ["src/**/*", "test/**/*"], + "compilerOptions": { + "lib": ["es2023"], + "target": "es2022", + "module": "ESNext", + "moduleResolution": "Bundler", + "strict": true, + "esModuleInterop": true, + "skipLibCheck": true, + "baseUrl": "." + } +} diff --git a/packages/openapi-ts/package.json b/packages/openapi-ts/package.json index 23d59c976..ff38b15b8 100644 --- a/packages/openapi-ts/package.json +++ b/packages/openapi-ts/package.json @@ -110,6 +110,7 @@ "cross-spawn": "7.0.3", "eslint": "9.6.0", "express": "4.21.0", + "fastify": "5.0.0", "glob": "10.4.3", "node-fetch": "3.3.2", "prettier": "3.3.2", diff --git a/packages/openapi-ts/src/plugins/@tanstack/query-core/plugin.ts b/packages/openapi-ts/src/plugins/@tanstack/query-core/plugin.ts index 7e6844b86..7e6dbfd02 100644 --- a/packages/openapi-ts/src/plugins/@tanstack/query-core/plugin.ts +++ b/packages/openapi-ts/src/plugins/@tanstack/query-core/plugin.ts @@ -35,6 +35,7 @@ import { } from '../../@hey-api/services/plugin-legacy'; import { typesId } from '../../@hey-api/types/plugin'; import type { PluginHandler } from '../../types'; +import { schemaToType, type SchemaToTypeOptions } from '../../utils/types'; import type { Config as AngularQueryConfig } from '../angular-query-experimental'; import type { Config as ReactQueryConfig } from '../react-query'; import type { Config as SolidQueryConfig } from '../solid-query'; diff --git a/packages/openapi-ts/src/plugins/fastify/config.ts b/packages/openapi-ts/src/plugins/fastify/config.ts new file mode 100644 index 000000000..57d73d84c --- /dev/null +++ b/packages/openapi-ts/src/plugins/fastify/config.ts @@ -0,0 +1,20 @@ +import type { DefineConfig, PluginConfig } from '../types'; +import { handler } from './plugin'; +import type { Config } from './types'; + +export const defaultConfig: PluginConfig = { + _dependencies: ['@hey-api/services'], + _handler: handler, + _handlerLegacy: () => {}, + name: 'fastify', + operationId: true, + output: 'fastify', +}; + +/** + * Type helper for the Fastify plugin, returns {@link PluginConfig} object + */ +export const defineConfig: DefineConfig = (config) => ({ + ...defaultConfig, + ...config, +}); diff --git a/packages/openapi-ts/src/plugins/fastify/index.ts b/packages/openapi-ts/src/plugins/fastify/index.ts new file mode 100644 index 000000000..3a85a1be8 --- /dev/null +++ b/packages/openapi-ts/src/plugins/fastify/index.ts @@ -0,0 +1,2 @@ +export { defaultConfig, defineConfig } from './config'; +export type { Config } from './types'; diff --git a/packages/openapi-ts/src/plugins/fastify/plugin.ts b/packages/openapi-ts/src/plugins/fastify/plugin.ts new file mode 100644 index 000000000..fd1fb1946 --- /dev/null +++ b/packages/openapi-ts/src/plugins/fastify/plugin.ts @@ -0,0 +1,182 @@ +import ts from 'typescript'; + +import { compiler, type Property } from '../../compiler'; +import type { IRContext } from '../../ir/context'; +import type { + IROperationObject, + IRParameterObject, + IRPathItemObject, + IRPathsObject, +} from '../../ir/ir'; +import { irParametersToIrSchema } from '../../ir/schema'; +import type { PluginHandler } from '../types'; +import { + componentsToType, + schemaToType, + type SchemaToTypeOptions, +} from '../utils/types'; +import type { Config } from './types'; + +const FILE_ID = 'fastify'; +const ROUTE_HANDLER_NAME = 'RouteHandler'; +const OPERATIONS_IDENTIFIER = 'RouteHandlers'; +const ROUTE_PROPERTY_NAME = { + BODY: 'Body', + HEADER: 'Headers', + PATH: 'Params', + QUERY: 'Querystring', + RESPONSE: 'Reply', +}; +const NUMERIC_CODE_REGEX = /\b[0-9]{3}\b/; + +const parameterToProperty = ({ + options, + parameter, + name, +}: { + name: string; + options: SchemaToTypeOptions; + parameter: Record; +}): Property => { + const schema = irParametersToIrSchema({ + parameters: parameter, + }); + return { + isRequired: !!schema.required, + name, + type: schemaToType({ options, schema }), + }; +}; + +const operationToProperty = ({ + operation, + options, +}: { + operation: IROperationObject; + options: SchemaToTypeOptions; +}): Property => { + const operationProperties: Array = []; + + if (operation.body) { + operationProperties.push({ + isRequired: operation.body.required, + name: ROUTE_PROPERTY_NAME.BODY, + type: schemaToType({ + options, + schema: operation.body.schema, + }), + }); + } + + if (operation.parameters) { + if (operation.parameters.header) { + operationProperties.push( + parameterToProperty({ + name: ROUTE_PROPERTY_NAME.HEADER, + options, + parameter: operation.parameters.header, + }), + ); + } + + if (operation.parameters.query) { + operationProperties.push( + parameterToProperty({ + name: ROUTE_PROPERTY_NAME.QUERY, + options, + parameter: operation.parameters.query, + }), + ); + } + + if (operation.parameters.path) { + operationProperties.push( + parameterToProperty({ + name: ROUTE_PROPERTY_NAME.PATH, + options, + parameter: operation.parameters.path, + }), + ); + } + } + + if (operation.responses) { + const responseProperties: Array = []; + for (const code in operation.responses) { + if (code === 'default') continue; + const response = operation.responses[code]; + responseProperties.push({ + name: NUMERIC_CODE_REGEX.test(code) + ? ts.factory.createNumericLiteral(code) + : code, + type: schemaToType({ + options, + schema: response?.schema ?? {}, + }), + }); + } + operationProperties.push({ + name: ROUTE_PROPERTY_NAME.RESPONSE, + type: compiler.typeInterfaceNode({ + properties: responseProperties, + useLegacyResolution: false, + }), + }); + } + + const operationType = compiler.typeInterfaceNode({ + properties: operationProperties, + useLegacyResolution: false, + }); + const property: Property = { + name: operation.id, + type: compiler.typeNode(ROUTE_HANDLER_NAME, [operationType]), + }; + return property; +}; + +const pathsToType = ({ + context, + options, +}: { + context: IRContext; + options: SchemaToTypeOptions; +}): ts.Node => { + const operationsProperties = []; + for (const path in context.ir.paths) { + const pathItem = context.ir.paths[path as keyof IRPathsObject]; + for (const method in pathItem) { + const operation = pathItem[method as keyof IRPathItemObject]; + if (operation) { + const operationProperty = operationToProperty({ operation, options }); + operationsProperties.push(operationProperty); + } + } + } + + const identifier = context.file({ id: FILE_ID })!.identifier({ + $ref: OPERATIONS_IDENTIFIER, + create: true, + namespace: 'type', + }); + const paths = compiler.typeAliasDeclaration({ + exportType: true, + name: identifier.name || '', + type: compiler.typeInterfaceNode({ + properties: operationsProperties, + useLegacyResolution: false, + }), + }); + return paths; +}; + +export const handler: PluginHandler = ({ context, plugin }) => { + const file = context.createFile({ id: FILE_ID, path: plugin.output }); + const options: SchemaToTypeOptions = { file }; + file.import({ asType: true, module: 'fastify', name: ROUTE_HANDLER_NAME }); + componentsToType({ + context, + options, + }); + file.add(pathsToType({ context, options })); +}; diff --git a/packages/openapi-ts/src/plugins/fastify/types.d.ts b/packages/openapi-ts/src/plugins/fastify/types.d.ts new file mode 100644 index 000000000..0af8eb49b --- /dev/null +++ b/packages/openapi-ts/src/plugins/fastify/types.d.ts @@ -0,0 +1,17 @@ +import type { PluginName } from '../types'; + +export interface Config extends PluginName<'fastify'> { + // TODO: parser - rename operationId option to something like inferId?: boolean + /** + * Use operation ID to generate operation names? + * @default true + */ + operationId?: boolean; + /** + * Name of the generated file. + * @default 'fastify' + */ + output?: string; +} + +export interface UserConfig extends Omit {} diff --git a/packages/openapi-ts/src/plugins/index.ts b/packages/openapi-ts/src/plugins/index.ts index 95af42bd0..fbcb68897 100644 --- a/packages/openapi-ts/src/plugins/index.ts +++ b/packages/openapi-ts/src/plugins/index.ts @@ -34,6 +34,7 @@ import { type Config as TanStackVueQuery, defaultConfig as tanStackVueQuery, } from './@tanstack/vue-query'; +import { type Config as Fastify, defaultConfig as fastify } from './fastify'; import type { DefaultPluginConfigsMap, PluginConfig, @@ -53,7 +54,8 @@ export type UserPlugins = | UserConfig | UserConfig | UserConfig - | UserConfig; + | UserConfig + | UserConfig; // | UserConfig export type ClientPlugins = @@ -66,6 +68,7 @@ export type ClientPlugins = | PluginConfig | PluginConfig | PluginConfig + | PluginConfig | PluginConfig; export const defaultPluginConfigs: DefaultPluginConfigsMap = { @@ -78,5 +81,6 @@ export const defaultPluginConfigs: DefaultPluginConfigsMap = { '@tanstack/solid-query': tanStackSolidQuery, '@tanstack/svelte-query': tanStackSvelteQuery, '@tanstack/vue-query': tanStackVueQuery, + fastify, zod, }; diff --git a/packages/openapi-ts/src/plugins/types.d.ts b/packages/openapi-ts/src/plugins/types.d.ts index e69901f63..83f15bca9 100644 --- a/packages/openapi-ts/src/plugins/types.d.ts +++ b/packages/openapi-ts/src/plugins/types.d.ts @@ -33,6 +33,7 @@ export type PluginNames = | '@tanstack/solid-query' | '@tanstack/svelte-query' | '@tanstack/vue-query' + | 'fastify' | 'zod'; export interface PluginName { diff --git a/packages/openapi-ts/src/plugins/utils/types.ts b/packages/openapi-ts/src/plugins/utils/types.ts index b6cdc1709..b703d41cd 100644 --- a/packages/openapi-ts/src/plugins/utils/types.ts +++ b/packages/openapi-ts/src/plugins/utils/types.ts @@ -139,7 +139,11 @@ const addTypeEnum = ({ // blocker for referencing these identifiers within the file as // we cannot guarantee just because they have a duplicate identifier, // they have a duplicate value. - if (!identifier.created && options.enums !== 'typescript+namespace') { + if ( + !identifier.created && + !isRefOpenApiComponent($ref) && + options.enums !== 'typescript+namespace' + ) { return; } @@ -376,7 +380,7 @@ const objectTypeToIdentifier = ({ }) => { let indexProperty: Property | undefined; const schemaProperties: Array = []; - const indexPropertyItems: Array = []; + let indexPropertyItems: Array = []; const required = schema.required ?? []; let hasOptionalProperties = false; @@ -402,12 +406,19 @@ const objectTypeToIdentifier = ({ } } - if (schema.additionalProperties) { - indexPropertyItems.unshift(schema.additionalProperties); + if ( + schema.additionalProperties && + (schema.additionalProperties.type !== 'never' || !indexPropertyItems.length) + ) { + if (schema.additionalProperties.type === 'never') { + indexPropertyItems = [schema.additionalProperties]; + } else { + indexPropertyItems.unshift(schema.additionalProperties); + } if (hasOptionalProperties) { indexPropertyItems.push({ - type: 'void', + type: 'undefined', }); } @@ -530,6 +541,8 @@ const schemaTypeToIdentifier = ({ options, schema: schema as SchemaWithType<'enum'>, }); + case 'never': + return compiler.keywordTypeNode({ keyword: 'never' }); case 'null': return compiler.literalTypeNode({ literal: compiler.null(), @@ -555,13 +568,15 @@ const schemaTypeToIdentifier = ({ options, schema: schema as SchemaWithType<'tuple'>, }); + case 'undefined': + return compiler.keywordTypeNode({ keyword: 'undefined' }); case 'unknown': return compiler.keywordTypeNode({ keyword: 'unknown', }); case 'void': return compiler.keywordTypeNode({ - keyword: 'undefined', + keyword: 'void', }); } }; @@ -673,9 +688,10 @@ export const componentsToType = ({ if (context.ir.components) { for (const name in context.ir.components.schemas) { const schema = context.ir.components.schemas[name]; + const $ref = `#/components/schemas/${name}`; schemaToType({ - $ref: `#/components/schemas/${name}`, + $ref, options, schema, }); @@ -683,9 +699,10 @@ export const componentsToType = ({ for (const name in context.ir.components.parameters) { const parameter = context.ir.components.parameters[name]; + const $ref = `#/components/parameters/${name}`; schemaToType({ - $ref: `#/components/parameters/${name}`, + $ref, options, schema: parameter.schema, }); diff --git a/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/fastify/fastify.gen.ts b/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/fastify/fastify.gen.ts new file mode 100644 index 000000000..ab34859ed --- /dev/null +++ b/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/fastify/fastify.gen.ts @@ -0,0 +1,1473 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { RouteHandler } from 'fastify'; + +/** + * Model with number-only name + */ +export type _400 = string; + +/** + * Testing multiline comments in string: First line + * Second line + * + * Fourth line + */ +export type camelCaseCommentWithBreaks = number; + +/** + * Testing multiline comments in string: First line + * Second line + * + * Fourth line + */ +export type CommentWithBreaks = number; + +/** + * Testing backticks in string: `backticks` and ```multiple backticks``` should work + */ +export type CommentWithBackticks = number; + +/** + * Testing backticks and quotes in string: `backticks`, 'quotes', "double quotes" and ```multiple backticks``` should work + */ +export type CommentWithBackticksAndQuotes = number; + +/** + * Testing slashes in string: \backwards\\\ and /forwards/// should work + */ +export type CommentWithSlashes = number; + +/** + * Testing expression placeholders in string: ${expression} should work + */ +export type CommentWithExpressionPlaceholders = number; + +/** + * Testing quotes in string: 'single quote''' and "double quotes""" should work + */ +export type CommentWithQuotes = number; + +/** + * Testing reserved characters in string: * inline * and ** inline ** should work + */ +export type CommentWithReservedCharacters = number; + +/** + * This is a simple number + */ +export type SimpleInteger = number; + +/** + * This is a simple boolean + */ +export type SimpleBoolean = boolean; + +/** + * This is a simple string + */ +export type SimpleString = string; + +/** + * A string with non-ascii (unicode) characters valid in typescript identifiers (æøåÆØÅöÔèÈ字符串) + */ +export type NonAsciiStringæøåÆØÅöôêÊ字符串 = string; + +/** + * This is a simple file + */ +export type SimpleFile = Blob | File; + +/** + * This is a simple reference + */ +export type SimpleReference = ModelWithString; + +/** + * This is a simple string + */ +export type SimpleStringWithPattern = string | null; + +/** + * This is a simple enum with strings + */ +export type EnumWithStrings = 'Success' | 'Warning' | 'Error' | "'Single Quote'" | '"Double Quotes"' | 'Non-ascii: øæåôöØÆÅÔÖ字符串'; + +export type EnumWithReplacedCharacters = "'Single Quote'" | '"Double Quotes"' | 'øæåôöØÆÅÔÖ字符串' | 3.1 | ''; + +/** + * This is a simple enum with numbers + */ +export type EnumWithNumbers = 1 | 2 | 3 | 1.1 | 1.2 | 1.3 | 100 | 200 | 300 | -100 | -200 | -300 | -1.1 | -1.2 | -1.3; + +/** + * Success=1,Warning=2,Error=3 + */ +export type EnumFromDescription = number; + +/** + * This is a simple enum with numbers + */ +export type EnumWithExtensions = 200 | 400 | 500; + +export type EnumWithXEnumNames = 0 | 1 | 2; + +/** + * This is a simple array with numbers + */ +export type ArrayWithNumbers = Array; + +/** + * This is a simple array with booleans + */ +export type ArrayWithBooleans = Array; + +/** + * This is a simple array with strings + */ +export type ArrayWithStrings = Array; + +/** + * This is a simple array with references + */ +export type ArrayWithReferences = Array; + +/** + * This is a simple array containing an array + */ +export type ArrayWithArray = Array>; + +/** + * This is a simple array with properties + */ +export type ArrayWithProperties = Array<{ + '16x16'?: camelCaseCommentWithBreaks; + bar?: string; +}>; + +/** + * This is a simple array with any of properties + */ +export type ArrayWithAnyOfProperties = Array<{ + foo?: string; +} | { + bar?: string; +}>; + +export type AnyOfAnyAndNull = { + data?: unknown; +}; + +/** + * This is a simple array with any of properties + */ +export type AnyOfArrays = { + results?: Array<{ + foo?: string; + } | { + bar?: string; + }>; +}; + +/** + * This is a string dictionary + */ +export type DictionaryWithString = { + [key: string]: string; +}; + +export type DictionaryWithPropertiesAndAdditionalProperties = { + foo?: number; + bar?: boolean; + [key: string]: string | number | boolean | undefined; +}; + +/** + * This is a string reference + */ +export type DictionaryWithReference = { + [key: string]: ModelWithString; +}; + +/** + * This is a complex dictionary + */ +export type DictionaryWithArray = { + [key: string]: Array; +}; + +/** + * This is a string dictionary + */ +export type DictionaryWithDictionary = { + [key: string]: { + [key: string]: string; + }; +}; + +/** + * This is a complex dictionary + */ +export type DictionaryWithProperties = { + [key: string]: { + foo?: string; + bar?: string; + }; +}; + +/** + * This is a model with one number property + */ +export type ModelWithInteger = { + /** + * This is a simple number property + */ + prop?: number; +}; + +/** + * This is a model with one boolean property + */ +export type ModelWithBoolean = { + /** + * This is a simple boolean property + */ + prop?: boolean; +}; + +/** + * This is a model with one string property + */ +export type ModelWithString = { + /** + * This is a simple string property + */ + prop?: string; +}; + +/** + * This is a model with one string property + */ +export type ModelWithStringError = { + /** + * This is a simple string property + */ + prop?: string; +}; + +/** + * `Comment` or `VoiceComment`. The JSON object for adding voice comments to tickets is different. See [Adding voice comments to tickets](/documentation/ticketing/managing-tickets/adding-voice-comments-to-tickets) + */ +export type Model_From_Zendesk = string; + +/** + * This is a model with one string property + */ +export type ModelWithNullableString = { + /** + * This is a simple string property + */ + nullableProp1?: string | null; + /** + * This is a simple string property + */ + nullableRequiredProp1: string | null; + /** + * This is a simple string property + */ + nullableProp2?: string | null; + /** + * This is a simple string property + */ + nullableRequiredProp2: string | null; + /** + * This is a simple enum with strings + */ + 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; +}; + +/** + * This is a model with one enum + */ +export type ModelWithEnum = { + /** + * This is a simple enum with strings + */ + 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; + /** + * These are the HTTP error code enums + */ + statusCode?: '100' | '200 FOO' | '300 FOO_BAR' | '400 foo-bar' | '500 foo.bar' | '600 foo&bar'; + /** + * Simple boolean enum + */ + bool?: true; +}; + +/** + * This is a model with one enum with escaped name + */ +export type ModelWithEnumWithHyphen = { + 'foo-bar-baz-qux'?: '3.0'; +}; + +/** + * This is a model with one enum + */ +export type ModelWithEnumFromDescription = { + /** + * Success=1,Warning=2,Error=3 + */ + test?: number; +}; + +/** + * This is a model with nested enums + */ +export type ModelWithNestedEnums = { + dictionaryWithEnum?: { + [key: string]: 'Success' | 'Warning' | 'Error'; + }; + dictionaryWithEnumFromDescription?: { + [key: string]: number; + }; + arrayWithEnum?: Array<'Success' | 'Warning' | 'Error'>; + arrayWithDescription?: Array; + /** + * This is a simple enum with strings + */ + 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; +}; + +/** + * This is a model with one property containing a reference + */ +export type ModelWithReference = { + prop?: ModelWithProperties; +}; + +/** + * This is a model with one property containing an array + */ +export type ModelWithArrayReadOnlyAndWriteOnly = { + prop?: Array; + propWithFile?: Array; + propWithNumber?: Array; +}; + +/** + * This is a model with one property containing an array + */ +export type ModelWithArray = { + prop?: Array; + propWithFile?: Array; + propWithNumber?: Array; +}; + +/** + * This is a model with one property containing a dictionary + */ +export type ModelWithDictionary = { + prop?: { + [key: string]: string; + }; +}; + +/** + * This is a deprecated model with a deprecated property + * @deprecated + */ +export type DeprecatedModel = { + /** + * This is a deprecated property + * @deprecated + */ + prop?: string; +}; + +/** + * This is a model with one property containing a circular reference + */ +export type ModelWithCircularReference = { + prop?: ModelWithCircularReference; +}; + +/** + * This is a model with one property with a 'one of' relationship + */ +export type CompositionWithOneOf = { + propA?: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; +}; + +/** + * This is a model with one property with a 'one of' relationship where the options are not $ref + */ +export type CompositionWithOneOfAnonymous = { + propA?: { + propA?: string; + } | string | number; +}; + +/** + * Circle + */ +export type ModelCircle = { + kind: string; + radius?: number; +}; + +/** + * Square + */ +export type ModelSquare = { + kind: string; + sideLength?: number; +}; + +/** + * This is a model with one property with a 'one of' relationship where the options are not $ref + */ +export type CompositionWithOneOfDiscriminator = ({ + kind?: 'circle'; +} & ModelCircle) | ({ + kind?: 'square'; +} & ModelSquare); + +/** + * This is a model with one property with a 'any of' relationship + */ +export type CompositionWithAnyOf = { + propA?: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; +}; + +/** + * This is a model with one property with a 'any of' relationship where the options are not $ref + */ +export type CompositionWithAnyOfAnonymous = { + propA?: { + propA?: string; + } | string | number; +}; + +/** + * This is a model with nested 'any of' property with a type null + */ +export type CompositionWithNestedAnyAndTypeNull = { + propA?: Array | Array; +}; + +export type _3e_num_1Период = 'Bird' | 'Dog'; + +export type ConstValue = 'ConstValue'; + +/** + * This is a model with one property with a 'any of' relationship where the options are not $ref + */ +export type CompositionWithNestedAnyOfAndNull = { + propA?: Array<_3e_num_1Период | ConstValue> | null; +}; + +/** + * This is a model with one property with a 'one of' relationship + */ +export type CompositionWithOneOfAndNullable = { + propA?: { + boolean?: boolean; + } | ModelWithEnum | ModelWithArray | ModelWithDictionary | null; +}; + +/** + * This is a model that contains a simple dictionary within composition + */ +export type CompositionWithOneOfAndSimpleDictionary = { + propA?: boolean | { + [key: string]: number; + }; +}; + +/** + * This is a model that contains a dictionary of simple arrays within composition + */ +export type CompositionWithOneOfAndSimpleArrayDictionary = { + propA?: boolean | { + [key: string]: Array; + }; +}; + +/** + * This is a model that contains a dictionary of complex arrays (composited) within composition + */ +export type CompositionWithOneOfAndComplexArrayDictionary = { + propA?: boolean | { + [key: string]: Array; + }; +}; + +/** + * This is a model with one property with a 'all of' relationship + */ +export type CompositionWithAllOfAndNullable = { + propA?: ({ + boolean?: boolean; + } & ModelWithEnum & ModelWithArray & ModelWithDictionary) | null; +}; + +/** + * This is a model with one property with a 'any of' relationship + */ +export type CompositionWithAnyOfAndNullable = { + propA?: { + boolean?: boolean; + } | ModelWithEnum | ModelWithArray | ModelWithDictionary | null; +}; + +/** + * This is a base model with two simple optional properties + */ +export type CompositionBaseModel = { + firstName?: string; + lastname?: string; +}; + +/** + * This is a model that extends the base model + */ +export type CompositionExtendedModel = CompositionBaseModel & { + age: number; + firstName: string; + lastname: string; +}; + +/** + * This is a model with one nested property + */ +export type ModelWithProperties = { + required: string; + readonly requiredAndReadOnly: string; + requiredAndNullable: string | null; + string?: string; + number?: number; + boolean?: boolean; + reference?: ModelWithString; + 'property with space'?: string; + default?: string; + try?: string; + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; +}; + +/** + * This is a model with one nested property + */ +export type ModelWithNestedProperties = { + readonly first: { + readonly second: { + readonly third: string | null; + } | null; + } | null; +}; + +/** + * This is a model with duplicated properties + */ +export type ModelWithDuplicateProperties = { + prop?: ModelWithString; +}; + +/** + * This is a model with ordered properties + */ +export type ModelWithOrderedProperties = { + zebra?: string; + apple?: string; + hawaii?: string; +}; + +/** + * This is a model with duplicated imports + */ +export type ModelWithDuplicateImports = { + propA?: ModelWithString; + propB?: ModelWithString; + propC?: ModelWithString; +}; + +/** + * This is a model that extends another model + */ +export type ModelThatExtends = ModelWithString & { + propExtendsA?: string; + propExtendsB?: ModelWithString; +}; + +/** + * This is a model that extends another model + */ +export type ModelThatExtendsExtends = ModelWithString & ModelThatExtends & { + propExtendsC?: string; + propExtendsD?: ModelWithString; +}; + +/** + * This is a model that contains a some patterns + */ +export type ModelWithPattern = { + key: string; + name: string; + readonly enabled?: boolean; + readonly modified?: string; + id?: string; + text?: string; + patternWithSingleQuotes?: string; + patternWithNewline?: string; + patternWithBacktick?: string; +}; + +export type File = { + readonly id?: string; + readonly updated_at?: string; + readonly created_at?: string; + mime: string; + readonly file?: string; +}; + +export type _default = { + name?: string; +}; + +export type Pageable = { + page?: number; + size?: number; + sort?: Array; +}; + +/** + * This is a free-form object without additionalProperties. + */ +export type FreeFormObjectWithoutAdditionalProperties = {}; + +/** + * This is a free-form object with additionalProperties: true. + */ +export type FreeFormObjectWithAdditionalPropertiesEqTrue = { + [key: string]: unknown; +}; + +/** + * This is a free-form object with additionalProperties: {}. + */ +export type FreeFormObjectWithAdditionalPropertiesEqEmptyObject = {}; + +export type ModelWithConst = { + String?: 'String'; + number?: 0; + null?: unknown; + withType?: 'Some string'; +}; + +/** + * This is a model with one property and additionalProperties: true + */ +export type ModelWithAdditionalPropertiesEqTrue = { + /** + * This is a simple string property + */ + prop?: string; + [key: string]: unknown | string | undefined; +}; + +export type NestedAnyOfArraysNullable = { + nullableArray?: Array | null; +}; + +export type CompositionWithOneOfAndProperties = ({ + foo: SimpleParameter; +} | { + bar: NonAsciiStringæøåÆØÅöôêÊ字符串; +}) & { + baz: number | null; + qux: number; +}; + +/** + * An object that can be null + */ +export type NullableObject = { + foo?: string; +} | null; + +/** + * Some % character + */ +export type CharactersInDescription = string; + +export type ModelWithNullableObject = { + data?: NullableObject; +}; + +export type ModelWithOneOfEnum = { + foo: 'Bar'; +} | { + foo: 'Baz'; +} | { + foo: 'Qux'; +} | { + content: string; + foo: 'Quux'; +} | { + content: [ + string, + string + ]; + foo: 'Corge'; +}; + +export type ModelWithNestedArrayEnumsDataFoo = 'foo' | 'bar'; + +export type ModelWithNestedArrayEnumsDataBar = 'baz' | 'qux'; + +export type ModelWithNestedArrayEnumsData = { + foo?: Array; + bar?: Array; +}; + +export type ModelWithNestedArrayEnums = { + array_strings?: Array; + data?: ModelWithNestedArrayEnumsData; +}; + +export type ModelWithNestedCompositionEnums = { + foo?: ModelWithNestedArrayEnumsDataFoo; +}; + +export type ModelWithReadOnlyAndWriteOnly = { + foo: string; + readonly bar: string; + baz: string; +}; + +export type ModelWithConstantSizeArray = [ + number, + number +]; + +export type ModelWithAnyOfConstantSizeArray = [ + number | string, + number | string, + number | string +]; + +export type ModelWithPrefixItemsConstantSizeArray = Array; + +export type ModelWithAnyOfConstantSizeArrayNullable = [ + number | null | string, + number | null | string, + number | null | string +]; + +export type ModelWithAnyOfConstantSizeArrayWithNSizeAndOptions = [ + number | _import, + number | _import +]; + +export type ModelWithAnyOfConstantSizeArrayAndIntersect = [ + number & string, + number & string +]; + +export type ModelWithNumericEnumUnion = { + /** + * Период + */ + value?: -10 | -1 | 0 | 1 | 3 | 6 | 12; +}; + +/** + * Some description with `back ticks` + */ +export type ModelWithBackticksInDescription = { + /** + * The template `that` should be used for parsing and importing the contents of the CSV file. + * + *

There is one placeholder currently supported:

  • ${x} - refers to the n-th column in the CSV file, e.g. ${1}, ${2}, ...)

Example of a correct JSON template:

+ *
+     * [
+     * {
+     * "resourceType": "Asset",
+     * "identifier": {
+     * "name": "${1}",
+     * "domain": {
+     * "name": "${2}",
+     * "community": {
+     * "name": "Some Community"
+     * }
+     * }
+     * },
+     * "attributes" : {
+     * "00000000-0000-0000-0000-000000003115" : [ {
+     * "value" : "${3}"
+     * } ],
+     * "00000000-0000-0000-0000-000000000222" : [ {
+     * "value" : "${4}"
+     * } ]
+     * }
+     * }
+     * ]
+     * 
+ */ + template?: string; +}; + +export type ModelWithOneOfAndProperties = (SimpleParameter | NonAsciiStringæøåÆØÅöôêÊ字符串) & { + baz: number | null; + qux: number; +}; + +/** + * Model used to test deduplication strategy (unused) + */ +export type ParameterSimpleParameterUnused = string; + +/** + * Model used to test deduplication strategy + */ +export type PostServiceWithEmptyTagResponse = string; + +/** + * Model used to test deduplication strategy + */ +export type PostServiceWithEmptyTagResponse2 = string; + +/** + * Model used to test deduplication strategy + */ +export type DeleteFooData = string; + +/** + * Model used to test deduplication strategy + */ +export type DeleteFooData2 = string; + +/** + * Model with restricted keyword name + */ +export type _import = string; + +export type SchemaWithFormRestrictedKeys = { + description?: string; + 'x-enum-descriptions'?: string; + 'x-enum-varnames'?: string; + 'x-enumNames'?: string; + title?: string; + object?: { + description?: string; + 'x-enum-descriptions'?: string; + 'x-enum-varnames'?: string; + 'x-enumNames'?: string; + title?: string; + }; + array?: Array<{ + description?: string; + 'x-enum-descriptions'?: string; + 'x-enum-varnames'?: string; + 'x-enumNames'?: string; + title?: string; + }>; +}; + +/** + * This schema was giving PascalCase transformations a hard time + */ +export type io_k8s_apimachinery_pkg_apis_meta_v1_DeleteOptions = { + /** + * Must be fulfilled before a deletion is carried out. If not possible, a 409 Conflict status will be returned. + */ + preconditions?: io_k8s_apimachinery_pkg_apis_meta_v1_Preconditions; +}; + +/** + * This schema was giving PascalCase transformations a hard time + */ +export type io_k8s_apimachinery_pkg_apis_meta_v1_Preconditions = { + /** + * Specifies the target ResourceVersion + */ + resourceVersion?: string; + /** + * Specifies the target UID. + */ + uid?: string; +}; + +export type AdditionalPropertiesUnknownIssue = { + [key: string]: string | number; +}; + +export type AdditionalPropertiesUnknownIssue2 = { + [key: string]: string | number; +}; + +export type AdditionalPropertiesUnknownIssue3 = string & { + entries: { + [key: string]: AdditionalPropertiesUnknownIssue; + }; +}; + +export type AdditionalPropertiesIntegerIssue = { + value: number; + [key: string]: number; +}; + +export type OneOfAllOfIssue = ((ConstValue | Generic_Schema_Duplicate_Issue_1_System_Boolean_) & _3e_num_1Период) | Generic_Schema_Duplicate_Issue_1_System_String_; + +export type Generic_Schema_Duplicate_Issue_1_System_Boolean_ = { + item?: boolean; + error?: string | null; + readonly hasError?: boolean; + data?: { + [key: string]: never; + }; +}; + +export type Generic_Schema_Duplicate_Issue_1_System_String_ = { + item?: string | null; + error?: string | null; + readonly hasError?: boolean; +}; + +/** + * This is a reusable parameter + */ +export type SimpleParameter = string; + +/** + * Parameter with illegal characters + */ +export type x_Foo_Bar = ModelWithString; + +export type RouteHandlers = { + export: RouteHandler<{}>; + import: RouteHandler<{ + Body: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; + Reply: { + 200: Model_From_Zendesk; + }; + }>; + apiVVersionOdataControllerCount: RouteHandler<{ + Reply: { + 200: Model_From_Zendesk; + }; + }>; + getApiVbyApiVersionSimpleOperation: RouteHandler<{ + Params: { + /** + * foo in method + */ + foo_param: string; + }; + Reply: { + 200: number; + }; + }>; + deleteCallWithoutParametersAndResponse: RouteHandler<{}>; + getCallWithoutParametersAndResponse: RouteHandler<{}>; + headCallWithoutParametersAndResponse: RouteHandler<{}>; + optionsCallWithoutParametersAndResponse: RouteHandler<{}>; + patchCallWithoutParametersAndResponse: RouteHandler<{}>; + postCallWithoutParametersAndResponse: RouteHandler<{}>; + putCallWithoutParametersAndResponse: RouteHandler<{}>; + deleteFoo: RouteHandler<{ + Headers: { + /** + * Parameter with illegal characters + */ + 'x-Foo-Bar': ModelWithString; + }; + Params: { + /** + * foo in method + */ + foo_param: string; + /** + * bar in method + */ + BarParam: string; + }; + }>; + callWithDescriptions: RouteHandler<{ + Querystring?: { + /** + * Testing multiline comments in string: First line + * Second line + * + * Fourth line + */ + parameterWithBreaks?: string; + /** + * Testing backticks in string: `backticks` and ```multiple backticks``` should work + */ + parameterWithBackticks?: string; + /** + * Testing slashes in string: \backwards\\\ and /forwards/// should work + */ + parameterWithSlashes?: string; + /** + * Testing expression placeholders in string: ${expression} should work + */ + parameterWithExpressionPlaceholders?: string; + /** + * Testing quotes in string: 'single quote''' and "double quotes""" should work + */ + parameterWithQuotes?: string; + /** + * Testing reserved characters in string: * inline * and ** inline ** should work + */ + parameterWithReservedCharacters?: string; + }; + }>; + deprecatedCall: RouteHandler<{ + Headers: { + /** + * This parameter is deprecated + * @deprecated + */ + parameter: DeprecatedModel | null; + }; + }>; + callWithParameters: RouteHandler<{ + Body: {} | null; + Headers: { + /** + * This is the parameter that goes into the header + */ + parameterHeader: string | null; + }; + Querystring: { + foo_ref_enum?: ModelWithNestedArrayEnumsDataFoo; + foo_all_of_enum: ModelWithNestedArrayEnumsDataFoo; + /** + * This is the parameter that goes into the query params + */ + cursor: string | null; + }; + Params: { + /** + * This is the parameter that goes into the path + */ + parameterPath: string | null; + /** + * api-version should be required in standalone clients + */ + 'api-version': string | null; + }; + }>; + callWithWeirdParameterNames: RouteHandler<{ + Body: ModelWithString | null; + Headers: { + /** + * This is the parameter that goes into the request header + */ + 'parameter.header': string | null; + }; + Querystring: { + /** + * This is the parameter with a reserved keyword + */ + default?: string; + /** + * This is the parameter that goes into the request query params + */ + 'parameter-query': string | null; + }; + Params: { + /** + * This is the parameter that goes into the path + */ + 'parameter.path.1'?: string; + /** + * This is the parameter that goes into the path + */ + 'parameter-path-2'?: string; + /** + * This is the parameter that goes into the path + */ + 'PARAMETER-PATH-3'?: string; + /** + * api-version should be required in standalone clients + */ + 'api-version': string | null; + }; + }>; + getCallWithOptionalParam: RouteHandler<{ + Body: ModelWithOneOfEnum; + Querystring?: { + /** + * This is an optional parameter + */ + page?: number; + }; + }>; + postCallWithOptionalParam: RouteHandler<{ + Body: { + offset?: number | null; + }; + Querystring: { + /** + * This is a required parameter + */ + parameter: Pageable; + }; + Reply: { + 200: number; + 204: void; + }; + }>; + postApiVbyApiVersionRequestBody: RouteHandler<{ + Body: ModelWithString; + Querystring?: { + /** + * This is a reusable parameter + */ + parameter?: string; + }; + }>; + postApiVbyApiVersionFormData: RouteHandler<{ + Body: ModelWithString; + Querystring?: { + /** + * This is a reusable parameter + */ + parameter?: string; + }; + }>; + callWithDefaultParameters: RouteHandler<{ + Querystring?: { + /** + * This is a simple string with default value + */ + parameterString?: string | null; + /** + * This is a simple number with default value + */ + parameterNumber?: number | null; + /** + * This is a simple boolean with default value + */ + parameterBoolean?: boolean | null; + /** + * This is a simple enum with default value + */ + parameterEnum?: 'Success' | 'Warning' | 'Error'; + /** + * This is a simple model with default value + */ + parameterModel?: ModelWithString | null; + }; + }>; + callWithDefaultOptionalParameters: RouteHandler<{ + Querystring?: { + /** + * This is a simple string that is optional with default value + */ + parameterString?: string; + /** + * This is a simple number that is optional with default value + */ + parameterNumber?: number; + /** + * This is a simple boolean that is optional with default value + */ + parameterBoolean?: boolean; + /** + * This is a simple enum that is optional with default value + */ + parameterEnum?: 'Success' | 'Warning' | 'Error'; + /** + * This is a simple model that is optional with default value + */ + parameterModel?: ModelWithString; + }; + }>; + callToTestOrderOfParams: RouteHandler<{ + Querystring: { + /** + * This is a optional string with default + */ + parameterOptionalStringWithDefault?: string; + /** + * This is a optional string with empty default + */ + parameterOptionalStringWithEmptyDefault?: string; + /** + * This is a optional string with no default + */ + parameterOptionalStringWithNoDefault?: string; + /** + * This is a string with default + */ + parameterStringWithDefault: string; + /** + * This is a string with empty default + */ + parameterStringWithEmptyDefault: string; + /** + * This is a string with no default + */ + parameterStringWithNoDefault: string; + /** + * This is a string that can be null with no default + */ + parameterStringNullableWithNoDefault?: string | null; + /** + * This is a string that can be null with default + */ + parameterStringNullableWithDefault?: string | null; + }; + }>; + duplicateName: RouteHandler<{}>; + duplicateName2: RouteHandler<{}>; + duplicateName3: RouteHandler<{}>; + duplicateName4: RouteHandler<{}>; + callWithNoContentResponse: RouteHandler<{ + Reply: { + 204: void; + }; + }>; + callWithResponseAndNoContentResponse: RouteHandler<{ + Reply: { + 200: number; + 204: void; + }; + }>; + dummyA: RouteHandler<{ + Reply: { + 200: _400; + }; + }>; + dummyB: RouteHandler<{ + Reply: { + 204: void; + }; + }>; + callWithResponse: RouteHandler<{ + Reply: {}; + }>; + callWithDuplicateResponses: RouteHandler<{ + Reply: { + 200: ModelWithBoolean & ModelWithInteger; + 201: ModelWithString; + 202: ModelWithString; + 500: ModelWithStringError; + 501: ModelWithStringError; + 502: ModelWithStringError; + '4XX': DictionaryWithArray; + }; + }>; + callWithResponses: RouteHandler<{ + Reply: { + 200: { + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; + readonly value?: Array; + }; + 201: ModelThatExtends; + 202: ModelThatExtendsExtends; + 500: ModelWithStringError; + 501: ModelWithStringError; + 502: ModelWithStringError; + }; + }>; + collectionFormat: RouteHandler<{ + Querystring: { + /** + * This is an array parameter that is sent as csv format (comma-separated values) + */ + parameterArrayCSV: Array | null; + /** + * This is an array parameter that is sent as ssv format (space-separated values) + */ + parameterArraySSV: Array | null; + /** + * This is an array parameter that is sent as tsv format (tab-separated values) + */ + parameterArrayTSV: Array | null; + /** + * This is an array parameter that is sent as pipes format (pipe-separated values) + */ + parameterArrayPipes: Array | null; + /** + * This is an array parameter that is sent as multi format (multiple parameter instances) + */ + parameterArrayMulti: Array | null; + }; + }>; + types: RouteHandler<{ + Querystring: { + /** + * This is a number parameter + */ + parameterNumber: number; + /** + * This is a string parameter + */ + parameterString: string | null; + /** + * This is a boolean parameter + */ + parameterBoolean: boolean | null; + /** + * This is an object parameter + */ + parameterObject: {} | null; + /** + * This is an array parameter + */ + parameterArray: Array | null; + /** + * This is a dictionary parameter + */ + parameterDictionary: {} | null; + /** + * This is an enum parameter + */ + parameterEnum: 'Success' | 'Warning' | 'Error'; + }; + Params?: { + /** + * This is a number parameter + */ + id?: number; + }; + Reply: { + 200: number; + 201: string; + 202: boolean; + 203: {}; + }; + }>; + uploadFile: RouteHandler<{ + Body: Blob | File; + Params: { + /** + * api-version should be required in standalone clients + */ + 'api-version': string | null; + }; + Reply: { + 200: boolean; + }; + }>; + fileResponse: RouteHandler<{ + Params: { + id: string; + /** + * api-version should be required in standalone clients + */ + 'api-version': string; + }; + Reply: { + 200: Blob | File; + }; + }>; + complexTypes: RouteHandler<{ + Querystring: { + /** + * Parameter containing object + */ + parameterObject: { + first?: { + second?: { + third?: string; + }; + }; + }; + /** + * Parameter containing reference + */ + parameterReference: ModelWithString; + }; + Reply: { + 200: Array; + 400: unknown; + 500: unknown; + }; + }>; + multipartResponse: RouteHandler<{ + Reply: { + 200: { + file?: Blob | File; + metadata?: { + foo?: string; + bar?: string; + }; + }; + }; + }>; + multipartRequest: RouteHandler<{ + Body: { + content?: Blob | File; + data?: ModelWithString | null; + }; + }>; + complexParams: RouteHandler<{ + Body: { + readonly key: string | null; + name: string | null; + enabled?: boolean; + type: 'Monkey' | 'Horse' | 'Bird'; + listOfModels?: Array | null; + listOfStrings?: Array | null; + parameters: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; + readonly user?: { + readonly id?: number; + readonly name?: string | null; + }; + }; + Params: { + id: number; + /** + * api-version should be required in standalone clients + */ + 'api-version': string; + }; + Reply: { + 200: ModelWithString; + }; + }>; + callWithResultFromHeader: RouteHandler<{ + Reply: { + 200: unknown; + 400: unknown; + 500: unknown; + }; + }>; + testErrorCode: RouteHandler<{ + Querystring: { + /** + * Status code to return + */ + status: number; + }; + Reply: { + 200: unknown; + 500: unknown; + 501: unknown; + 502: unknown; + 503: unknown; + }; + }>; + nonAsciiæøåÆøÅöôêÊ字符串: RouteHandler<{ + Querystring: { + /** + * Dummy input param + */ + nonAsciiParamæøåÆØÅöôêÊ: number; + }; + Reply: { + 200: Array; + }; + }>; + putWithFormUrlEncoded: RouteHandler<{ + Body: ArrayWithStrings; + }>; +}; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/fastify/index.ts b/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/fastify/index.ts new file mode 100644 index 000000000..e3705920c --- /dev/null +++ b/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/fastify/index.ts @@ -0,0 +1,3 @@ +// This file is auto-generated by @hey-api/openapi-ts +export * from './types.gen'; +export * from './services.gen'; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/fastify/services.gen.ts b/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/fastify/services.gen.ts new file mode 100644 index 000000000..c79ed1e8c --- /dev/null +++ b/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/fastify/services.gen.ts @@ -0,0 +1,382 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { createClient, createConfig, type Options, formDataBodySerializer, urlSearchParamsBodySerializer } from '@hey-api/client-fetch'; +import type { ImportData, ImportResponse, ApiVversionOdataControllerCountResponse, GetApiVbyApiVersionSimpleOperationData, GetApiVbyApiVersionSimpleOperationError, GetApiVbyApiVersionSimpleOperationResponse, DeleteFooData3, CallWithDescriptionsData, DeprecatedCallData, CallWithParametersData, CallWithWeirdParameterNamesData, GetCallWithOptionalParamData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponse, PostApiVbyApiVersionRequestBodyData, PostApiVbyApiVersionFormDataData, CallWithDefaultParametersData, CallWithDefaultOptionalParametersData, CallToTestOrderOfParamsData, CallWithNoContentResponseResponse, CallWithResponseAndNoContentResponseResponse, DummyAResponse, DummyBResponse, CallWithResponseResponse, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithResponsesError, CallWithResponsesResponse, CollectionFormatData, TypesData, TypesResponse, UploadFileData, UploadFileResponse, FileResponseData, FileResponseResponse, ComplexTypesData, ComplexTypesResponse, MultipartResponseResponse, MultipartRequestData, ComplexParamsData, ComplexParamsResponse, TestErrorCodeData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PutWithFormUrlEncodedData } from './types.gen'; + +export const client = createClient(createConfig()); + +export const export_ = (options?: Options) => { + return (options?.client ?? client).get({ + ...options, + url: '/api/v{api-version}/no-tag' + }); +}; + +export const import_ = (options: Options) => { + return (options?.client ?? client).post({ + ...options, + headers: { + 'Content-Type': 'application/json', + ...options?.headers + }, + url: '/api/v{api-version}/no-tag' + }); +}; + +export const apiVVersionOdataControllerCount = (options?: Options) => { + return (options?.client ?? client).get({ + ...options, + url: '/api/v{api-version}/simple/$count' + }); +}; + +export const getApiVbyApiVersionSimpleOperation = (options: Options) => { + return (options?.client ?? client).get({ + ...options, + url: '/api/v{api-version}/simple:operation' + }); +}; + +export const deleteCallWithoutParametersAndResponse = (options?: Options) => { + return (options?.client ?? client).delete({ + ...options, + url: '/api/v{api-version}/simple' + }); +}; + +export const getCallWithoutParametersAndResponse = (options?: Options) => { + return (options?.client ?? client).get({ + ...options, + url: '/api/v{api-version}/simple' + }); +}; + +export const headCallWithoutParametersAndResponse = (options?: Options) => { + return (options?.client ?? client).head({ + ...options, + url: '/api/v{api-version}/simple' + }); +}; + +export const optionsCallWithoutParametersAndResponse = (options?: Options) => { + return (options?.client ?? client).options({ + ...options, + url: '/api/v{api-version}/simple' + }); +}; + +export const patchCallWithoutParametersAndResponse = (options?: Options) => { + return (options?.client ?? client).patch({ + ...options, + url: '/api/v{api-version}/simple' + }); +}; + +export const postCallWithoutParametersAndResponse = (options?: Options) => { + return (options?.client ?? client).post({ + ...options, + url: '/api/v{api-version}/simple' + }); +}; + +export const putCallWithoutParametersAndResponse = (options?: Options) => { + return (options?.client ?? client).put({ + ...options, + url: '/api/v{api-version}/simple' + }); +}; + +export const deleteFoo = (options: Options) => { + return (options?.client ?? client).delete({ + ...options, + url: '/api/v{api-version}/foo/{foo_param}/bar/{BarParam}' + }); +}; + +export const callWithDescriptions = (options?: Options) => { + return (options?.client ?? client).post({ + ...options, + url: '/api/v{api-version}/descriptions' + }); +}; + +/** + * @deprecated + */ +export const deprecatedCall = (options: Options) => { + return (options?.client ?? client).post({ + ...options, + url: '/api/v{api-version}/parameters/deprecated' + }); +}; + +export const callWithParameters = (options: Options) => { + return (options?.client ?? client).post({ + ...options, + headers: { + 'Content-Type': 'application/json', + ...options?.headers + }, + url: '/api/v{api-version}/parameters/{parameterPath}' + }); +}; + +export const callWithWeirdParameterNames = (options: Options) => { + return (options?.client ?? client).post({ + ...options, + headers: { + 'Content-Type': 'application/json', + ...options?.headers + }, + url: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}' + }); +}; + +export const getCallWithOptionalParam = (options: Options) => { + return (options?.client ?? client).get({ + ...options, + headers: { + 'Content-Type': 'application/json', + ...options?.headers + }, + url: '/api/v{api-version}/parameters' + }); +}; + +export const postCallWithOptionalParam = (options: Options) => { + return (options?.client ?? client).post({ + ...options, + headers: { + 'Content-Type': 'application/json', + ...options?.headers + }, + url: '/api/v{api-version}/parameters' + }); +}; + +export const postApiVbyApiVersionRequestBody = (options?: Options) => { + return (options?.client ?? client).post({ + ...options, + headers: { + 'Content-Type': 'application/json', + ...options?.headers + }, + url: '/api/v{api-version}/requestBody' + }); +}; + +export const postApiVbyApiVersionFormData = (options?: Options) => { + return (options?.client ?? client).post({ + ...options, + ...formDataBodySerializer, + headers: { + 'Content-Type': null, + ...options?.headers + }, + url: '/api/v{api-version}/formData' + }); +}; + +export const callWithDefaultParameters = (options?: Options) => { + return (options?.client ?? client).get({ + ...options, + url: '/api/v{api-version}/defaults' + }); +}; + +export const callWithDefaultOptionalParameters = (options?: Options) => { + return (options?.client ?? client).post({ + ...options, + url: '/api/v{api-version}/defaults' + }); +}; + +export const callToTestOrderOfParams = (options: Options) => { + return (options?.client ?? client).put({ + ...options, + url: '/api/v{api-version}/defaults' + }); +}; + +export const duplicateName = (options?: Options) => { + return (options?.client ?? client).delete({ + ...options, + url: '/api/v{api-version}/duplicate' + }); +}; + +export const duplicateName2 = (options?: Options) => { + return (options?.client ?? client).get({ + ...options, + url: '/api/v{api-version}/duplicate' + }); +}; + +export const duplicateName3 = (options?: Options) => { + return (options?.client ?? client).post({ + ...options, + url: '/api/v{api-version}/duplicate' + }); +}; + +export const duplicateName4 = (options?: Options) => { + return (options?.client ?? client).put({ + ...options, + url: '/api/v{api-version}/duplicate' + }); +}; + +export const callWithNoContentResponse = (options?: Options) => { + return (options?.client ?? client).get({ + ...options, + url: '/api/v{api-version}/no-content' + }); +}; + +export const callWithResponseAndNoContentResponse = (options?: Options) => { + return (options?.client ?? client).get({ + ...options, + url: '/api/v{api-version}/multiple-tags/response-and-no-content' + }); +}; + +export const dummyA = (options?: Options) => { + return (options?.client ?? client).get({ + ...options, + url: '/api/v{api-version}/multiple-tags/a' + }); +}; + +export const dummyB = (options?: Options) => { + return (options?.client ?? client).get({ + ...options, + url: '/api/v{api-version}/multiple-tags/b' + }); +}; + +export const callWithResponse = (options?: Options) => { + return (options?.client ?? client).get({ + ...options, + url: '/api/v{api-version}/response' + }); +}; + +export const callWithDuplicateResponses = (options?: Options) => { + return (options?.client ?? client).post({ + ...options, + url: '/api/v{api-version}/response' + }); +}; + +export const callWithResponses = (options?: Options) => { + return (options?.client ?? client).put({ + ...options, + url: '/api/v{api-version}/response' + }); +}; + +export const collectionFormat = (options: Options) => { + return (options?.client ?? client).get({ + ...options, + url: '/api/v{api-version}/collectionFormat' + }); +}; + +export const types = (options: Options) => { + return (options?.client ?? client).get({ + ...options, + url: '/api/v{api-version}/types' + }); +}; + +export const uploadFile = (options: Options) => { + return (options?.client ?? client).post({ + ...options, + ...urlSearchParamsBodySerializer, + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + ...options?.headers + }, + url: '/api/v{api-version}/upload' + }); +}; + +export const fileResponse = (options: Options) => { + return (options?.client ?? client).get({ + ...options, + url: '/api/v{api-version}/file/{id}' + }); +}; + +export const complexTypes = (options: Options) => { + return (options?.client ?? client).get({ + ...options, + url: '/api/v{api-version}/complex' + }); +}; + +export const multipartResponse = (options?: Options) => { + return (options?.client ?? client).get({ + ...options, + url: '/api/v{api-version}/multipart' + }); +}; + +export const multipartRequest = (options?: Options) => { + return (options?.client ?? client).post({ + ...options, + ...formDataBodySerializer, + headers: { + 'Content-Type': null, + ...options?.headers + }, + url: '/api/v{api-version}/multipart' + }); +}; + +export const complexParams = (options: Options) => { + return (options?.client ?? client).put({ + ...options, + headers: { + 'Content-Type': 'application/json-patch+json', + ...options?.headers + }, + url: '/api/v{api-version}/complex/{id}' + }); +}; + +export const callWithResultFromHeader = (options?: Options) => { + return (options?.client ?? client).post({ + ...options, + url: '/api/v{api-version}/header' + }); +}; + +export const testErrorCode = (options: Options) => { + return (options?.client ?? client).post({ + ...options, + url: '/api/v{api-version}/error' + }); +}; + +export const nonAsciiæøåÆøÅöôêÊ字符串 = (options: Options) => { + return (options?.client ?? client).post({ + ...options, + url: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串' + }); +}; + +/** + * Login User + */ +export const putWithFormUrlEncoded = (options: Options) => { + return (options?.client ?? client).put({ + ...options, + ...urlSearchParamsBodySerializer, + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + ...options?.headers + }, + url: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串' + }); +}; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/fastify/types.gen.ts b/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/fastify/types.gen.ts new file mode 100644 index 000000000..b914fd963 --- /dev/null +++ b/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/fastify/types.gen.ts @@ -0,0 +1,1470 @@ +// This file is auto-generated by @hey-api/openapi-ts + +/** + * Model with number-only name + */ +export type _400 = string; + +/** + * Testing multiline comments in string: First line + * Second line + * + * Fourth line + */ +export type camelCaseCommentWithBreaks = number; + +/** + * Testing multiline comments in string: First line + * Second line + * + * Fourth line + */ +export type CommentWithBreaks = number; + +/** + * Testing backticks in string: `backticks` and ```multiple backticks``` should work + */ +export type CommentWithBackticks = number; + +/** + * Testing backticks and quotes in string: `backticks`, 'quotes', "double quotes" and ```multiple backticks``` should work + */ +export type CommentWithBackticksAndQuotes = number; + +/** + * Testing slashes in string: \backwards\\\ and /forwards/// should work + */ +export type CommentWithSlashes = number; + +/** + * Testing expression placeholders in string: ${expression} should work + */ +export type CommentWithExpressionPlaceholders = number; + +/** + * Testing quotes in string: 'single quote''' and "double quotes""" should work + */ +export type CommentWithQuotes = number; + +/** + * Testing reserved characters in string: * inline * and ** inline ** should work + */ +export type CommentWithReservedCharacters = number; + +/** + * This is a simple number + */ +export type SimpleInteger = number; + +/** + * This is a simple boolean + */ +export type SimpleBoolean = boolean; + +/** + * This is a simple string + */ +export type SimpleString = string; + +/** + * A string with non-ascii (unicode) characters valid in typescript identifiers (æøåÆØÅöÔèÈ字符串) + */ +export type NonAsciiStringæøåÆØÅöôêÊ字符串 = string; + +/** + * This is a simple file + */ +export type SimpleFile = Blob | File; + +/** + * This is a simple reference + */ +export type SimpleReference = ModelWithString; + +/** + * This is a simple string + */ +export type SimpleStringWithPattern = string | null; + +/** + * This is a simple enum with strings + */ +export type EnumWithStrings = 'Success' | 'Warning' | 'Error' | "'Single Quote'" | '"Double Quotes"' | 'Non-ascii: øæåôöØÆÅÔÖ字符串'; + +export type EnumWithReplacedCharacters = "'Single Quote'" | '"Double Quotes"' | 'øæåôöØÆÅÔÖ字符串' | 3.1 | ''; + +/** + * This is a simple enum with numbers + */ +export type EnumWithNumbers = 1 | 2 | 3 | 1.1 | 1.2 | 1.3 | 100 | 200 | 300 | -100 | -200 | -300 | -1.1 | -1.2 | -1.3; + +/** + * Success=1,Warning=2,Error=3 + */ +export type EnumFromDescription = number; + +/** + * This is a simple enum with numbers + */ +export type EnumWithExtensions = 200 | 400 | 500; + +export type EnumWithXEnumNames = 0 | 1 | 2; + +/** + * This is a simple array with numbers + */ +export type ArrayWithNumbers = Array; + +/** + * This is a simple array with booleans + */ +export type ArrayWithBooleans = Array; + +/** + * This is a simple array with strings + */ +export type ArrayWithStrings = Array; + +/** + * This is a simple array with references + */ +export type ArrayWithReferences = Array; + +/** + * This is a simple array containing an array + */ +export type ArrayWithArray = Array>; + +/** + * This is a simple array with properties + */ +export type ArrayWithProperties = Array<{ + '16x16'?: camelCaseCommentWithBreaks; + bar?: string; +}>; + +/** + * This is a simple array with any of properties + */ +export type ArrayWithAnyOfProperties = Array<{ + foo?: string; +} | { + bar?: string; +}>; + +export type AnyOfAnyAndNull = { + data?: unknown; +}; + +/** + * This is a simple array with any of properties + */ +export type AnyOfArrays = { + results?: Array<{ + foo?: string; + } | { + bar?: string; + }>; +}; + +/** + * This is a string dictionary + */ +export type DictionaryWithString = { + [key: string]: string; +}; + +export type DictionaryWithPropertiesAndAdditionalProperties = { + foo?: number; + bar?: boolean; + [key: string]: string | number | boolean | undefined; +}; + +/** + * This is a string reference + */ +export type DictionaryWithReference = { + [key: string]: ModelWithString; +}; + +/** + * This is a complex dictionary + */ +export type DictionaryWithArray = { + [key: string]: Array; +}; + +/** + * This is a string dictionary + */ +export type DictionaryWithDictionary = { + [key: string]: { + [key: string]: string; + }; +}; + +/** + * This is a complex dictionary + */ +export type DictionaryWithProperties = { + [key: string]: { + foo?: string; + bar?: string; + }; +}; + +/** + * This is a model with one number property + */ +export type ModelWithInteger = { + /** + * This is a simple number property + */ + prop?: number; +}; + +/** + * This is a model with one boolean property + */ +export type ModelWithBoolean = { + /** + * This is a simple boolean property + */ + prop?: boolean; +}; + +/** + * This is a model with one string property + */ +export type ModelWithString = { + /** + * This is a simple string property + */ + prop?: string; +}; + +/** + * This is a model with one string property + */ +export type ModelWithStringError = { + /** + * This is a simple string property + */ + prop?: string; +}; + +/** + * `Comment` or `VoiceComment`. The JSON object for adding voice comments to tickets is different. See [Adding voice comments to tickets](/documentation/ticketing/managing-tickets/adding-voice-comments-to-tickets) + */ +export type Model_From_Zendesk = string; + +/** + * This is a model with one string property + */ +export type ModelWithNullableString = { + /** + * This is a simple string property + */ + nullableProp1?: string | null; + /** + * This is a simple string property + */ + nullableRequiredProp1: string | null; + /** + * This is a simple string property + */ + nullableProp2?: string | null; + /** + * This is a simple string property + */ + nullableRequiredProp2: string | null; + /** + * This is a simple enum with strings + */ + 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; +}; + +/** + * This is a model with one enum + */ +export type ModelWithEnum = { + /** + * This is a simple enum with strings + */ + 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; + /** + * These are the HTTP error code enums + */ + statusCode?: '100' | '200 FOO' | '300 FOO_BAR' | '400 foo-bar' | '500 foo.bar' | '600 foo&bar'; + /** + * Simple boolean enum + */ + bool?: true; +}; + +/** + * This is a model with one enum with escaped name + */ +export type ModelWithEnumWithHyphen = { + 'foo-bar-baz-qux'?: '3.0'; +}; + +/** + * This is a model with one enum + */ +export type ModelWithEnumFromDescription = { + /** + * Success=1,Warning=2,Error=3 + */ + test?: number; +}; + +/** + * This is a model with nested enums + */ +export type ModelWithNestedEnums = { + dictionaryWithEnum?: { + [key: string]: 'Success' | 'Warning' | 'Error'; + }; + dictionaryWithEnumFromDescription?: { + [key: string]: number; + }; + arrayWithEnum?: Array<'Success' | 'Warning' | 'Error'>; + arrayWithDescription?: Array; + /** + * This is a simple enum with strings + */ + 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; +}; + +/** + * This is a model with one property containing a reference + */ +export type ModelWithReference = { + prop?: ModelWithProperties; +}; + +/** + * This is a model with one property containing an array + */ +export type ModelWithArrayReadOnlyAndWriteOnly = { + prop?: Array; + propWithFile?: Array; + propWithNumber?: Array; +}; + +/** + * This is a model with one property containing an array + */ +export type ModelWithArray = { + prop?: Array; + propWithFile?: Array; + propWithNumber?: Array; +}; + +/** + * This is a model with one property containing a dictionary + */ +export type ModelWithDictionary = { + prop?: { + [key: string]: string; + }; +}; + +/** + * This is a deprecated model with a deprecated property + * @deprecated + */ +export type DeprecatedModel = { + /** + * This is a deprecated property + * @deprecated + */ + prop?: string; +}; + +/** + * This is a model with one property containing a circular reference + */ +export type ModelWithCircularReference = { + prop?: ModelWithCircularReference; +}; + +/** + * This is a model with one property with a 'one of' relationship + */ +export type CompositionWithOneOf = { + propA?: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; +}; + +/** + * This is a model with one property with a 'one of' relationship where the options are not $ref + */ +export type CompositionWithOneOfAnonymous = { + propA?: { + propA?: string; + } | string | number; +}; + +/** + * Circle + */ +export type ModelCircle = { + kind: string; + radius?: number; +}; + +/** + * Square + */ +export type ModelSquare = { + kind: string; + sideLength?: number; +}; + +/** + * This is a model with one property with a 'one of' relationship where the options are not $ref + */ +export type CompositionWithOneOfDiscriminator = ({ + kind?: 'circle'; +} & ModelCircle) | ({ + kind?: 'square'; +} & ModelSquare); + +/** + * This is a model with one property with a 'any of' relationship + */ +export type CompositionWithAnyOf = { + propA?: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; +}; + +/** + * This is a model with one property with a 'any of' relationship where the options are not $ref + */ +export type CompositionWithAnyOfAnonymous = { + propA?: { + propA?: string; + } | string | number; +}; + +/** + * This is a model with nested 'any of' property with a type null + */ +export type CompositionWithNestedAnyAndTypeNull = { + propA?: Array | Array; +}; + +export type _3e_num_1Период = 'Bird' | 'Dog'; + +export type ConstValue = 'ConstValue'; + +/** + * This is a model with one property with a 'any of' relationship where the options are not $ref + */ +export type CompositionWithNestedAnyOfAndNull = { + propA?: Array<_3e_num_1Период | ConstValue> | null; +}; + +/** + * This is a model with one property with a 'one of' relationship + */ +export type CompositionWithOneOfAndNullable = { + propA?: { + boolean?: boolean; + } | ModelWithEnum | ModelWithArray | ModelWithDictionary | null; +}; + +/** + * This is a model that contains a simple dictionary within composition + */ +export type CompositionWithOneOfAndSimpleDictionary = { + propA?: boolean | { + [key: string]: number; + }; +}; + +/** + * This is a model that contains a dictionary of simple arrays within composition + */ +export type CompositionWithOneOfAndSimpleArrayDictionary = { + propA?: boolean | { + [key: string]: Array; + }; +}; + +/** + * This is a model that contains a dictionary of complex arrays (composited) within composition + */ +export type CompositionWithOneOfAndComplexArrayDictionary = { + propA?: boolean | { + [key: string]: Array; + }; +}; + +/** + * This is a model with one property with a 'all of' relationship + */ +export type CompositionWithAllOfAndNullable = { + propA?: ({ + boolean?: boolean; + } & ModelWithEnum & ModelWithArray & ModelWithDictionary) | null; +}; + +/** + * This is a model with one property with a 'any of' relationship + */ +export type CompositionWithAnyOfAndNullable = { + propA?: { + boolean?: boolean; + } | ModelWithEnum | ModelWithArray | ModelWithDictionary | null; +}; + +/** + * This is a base model with two simple optional properties + */ +export type CompositionBaseModel = { + firstName?: string; + lastname?: string; +}; + +/** + * This is a model that extends the base model + */ +export type CompositionExtendedModel = CompositionBaseModel & { + age: number; + firstName: string; + lastname: string; +}; + +/** + * This is a model with one nested property + */ +export type ModelWithProperties = { + required: string; + readonly requiredAndReadOnly: string; + requiredAndNullable: string | null; + string?: string; + number?: number; + boolean?: boolean; + reference?: ModelWithString; + 'property with space'?: string; + default?: string; + try?: string; + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; +}; + +/** + * This is a model with one nested property + */ +export type ModelWithNestedProperties = { + readonly first: { + readonly second: { + readonly third: string | null; + } | null; + } | null; +}; + +/** + * This is a model with duplicated properties + */ +export type ModelWithDuplicateProperties = { + prop?: ModelWithString; +}; + +/** + * This is a model with ordered properties + */ +export type ModelWithOrderedProperties = { + zebra?: string; + apple?: string; + hawaii?: string; +}; + +/** + * This is a model with duplicated imports + */ +export type ModelWithDuplicateImports = { + propA?: ModelWithString; + propB?: ModelWithString; + propC?: ModelWithString; +}; + +/** + * This is a model that extends another model + */ +export type ModelThatExtends = ModelWithString & { + propExtendsA?: string; + propExtendsB?: ModelWithString; +}; + +/** + * This is a model that extends another model + */ +export type ModelThatExtendsExtends = ModelWithString & ModelThatExtends & { + propExtendsC?: string; + propExtendsD?: ModelWithString; +}; + +/** + * This is a model that contains a some patterns + */ +export type ModelWithPattern = { + key: string; + name: string; + readonly enabled?: boolean; + readonly modified?: string; + id?: string; + text?: string; + patternWithSingleQuotes?: string; + patternWithNewline?: string; + patternWithBacktick?: string; +}; + +export type File = { + readonly id?: string; + readonly updated_at?: string; + readonly created_at?: string; + mime: string; + readonly file?: string; +}; + +export type _default = { + name?: string; +}; + +export type Pageable = { + page?: number; + size?: number; + sort?: Array; +}; + +/** + * This is a free-form object without additionalProperties. + */ +export type FreeFormObjectWithoutAdditionalProperties = {}; + +/** + * This is a free-form object with additionalProperties: true. + */ +export type FreeFormObjectWithAdditionalPropertiesEqTrue = { + [key: string]: unknown; +}; + +/** + * This is a free-form object with additionalProperties: {}. + */ +export type FreeFormObjectWithAdditionalPropertiesEqEmptyObject = {}; + +export type ModelWithConst = { + String?: 'String'; + number?: 0; + null?: unknown; + withType?: 'Some string'; +}; + +/** + * This is a model with one property and additionalProperties: true + */ +export type ModelWithAdditionalPropertiesEqTrue = { + /** + * This is a simple string property + */ + prop?: string; + [key: string]: unknown | string | undefined; +}; + +export type NestedAnyOfArraysNullable = { + nullableArray?: Array | null; +}; + +export type CompositionWithOneOfAndProperties = ({ + foo: SimpleParameter; +} | { + bar: NonAsciiStringæøåÆØÅöôêÊ字符串; +}) & { + baz: number | null; + qux: number; +}; + +/** + * An object that can be null + */ +export type NullableObject = { + foo?: string; +} | null; + +/** + * Some % character + */ +export type CharactersInDescription = string; + +export type ModelWithNullableObject = { + data?: NullableObject; +}; + +export type ModelWithOneOfEnum = { + foo: 'Bar'; +} | { + foo: 'Baz'; +} | { + foo: 'Qux'; +} | { + content: string; + foo: 'Quux'; +} | { + content: [ + string, + string + ]; + foo: 'Corge'; +}; + +export type ModelWithNestedArrayEnumsDataFoo = 'foo' | 'bar'; + +export type ModelWithNestedArrayEnumsDataBar = 'baz' | 'qux'; + +export type ModelWithNestedArrayEnumsData = { + foo?: Array; + bar?: Array; +}; + +export type ModelWithNestedArrayEnums = { + array_strings?: Array; + data?: ModelWithNestedArrayEnumsData; +}; + +export type ModelWithNestedCompositionEnums = { + foo?: ModelWithNestedArrayEnumsDataFoo; +}; + +export type ModelWithReadOnlyAndWriteOnly = { + foo: string; + readonly bar: string; + baz: string; +}; + +export type ModelWithConstantSizeArray = [ + number, + number +]; + +export type ModelWithAnyOfConstantSizeArray = [ + number | string, + number | string, + number | string +]; + +export type ModelWithPrefixItemsConstantSizeArray = Array; + +export type ModelWithAnyOfConstantSizeArrayNullable = [ + number | null | string, + number | null | string, + number | null | string +]; + +export type ModelWithAnyOfConstantSizeArrayWithNSizeAndOptions = [ + number | _import, + number | _import +]; + +export type ModelWithAnyOfConstantSizeArrayAndIntersect = [ + number & string, + number & string +]; + +export type ModelWithNumericEnumUnion = { + /** + * Период + */ + value?: -10 | -1 | 0 | 1 | 3 | 6 | 12; +}; + +/** + * Some description with `back ticks` + */ +export type ModelWithBackticksInDescription = { + /** + * The template `that` should be used for parsing and importing the contents of the CSV file. + * + *

There is one placeholder currently supported:

  • ${x} - refers to the n-th column in the CSV file, e.g. ${1}, ${2}, ...)

Example of a correct JSON template:

+ *
+     * [
+     * {
+     * "resourceType": "Asset",
+     * "identifier": {
+     * "name": "${1}",
+     * "domain": {
+     * "name": "${2}",
+     * "community": {
+     * "name": "Some Community"
+     * }
+     * }
+     * },
+     * "attributes" : {
+     * "00000000-0000-0000-0000-000000003115" : [ {
+     * "value" : "${3}"
+     * } ],
+     * "00000000-0000-0000-0000-000000000222" : [ {
+     * "value" : "${4}"
+     * } ]
+     * }
+     * }
+     * ]
+     * 
+ */ + template?: string; +}; + +export type ModelWithOneOfAndProperties = (SimpleParameter | NonAsciiStringæøåÆØÅöôêÊ字符串) & { + baz: number | null; + qux: number; +}; + +/** + * Model used to test deduplication strategy (unused) + */ +export type ParameterSimpleParameterUnused = string; + +/** + * Model used to test deduplication strategy + */ +export type PostServiceWithEmptyTagResponse = string; + +/** + * Model used to test deduplication strategy + */ +export type PostServiceWithEmptyTagResponse2 = string; + +/** + * Model used to test deduplication strategy + */ +export type DeleteFooData = string; + +/** + * Model used to test deduplication strategy + */ +export type DeleteFooData2 = string; + +/** + * Model with restricted keyword name + */ +export type _import = string; + +export type SchemaWithFormRestrictedKeys = { + description?: string; + 'x-enum-descriptions'?: string; + 'x-enum-varnames'?: string; + 'x-enumNames'?: string; + title?: string; + object?: { + description?: string; + 'x-enum-descriptions'?: string; + 'x-enum-varnames'?: string; + 'x-enumNames'?: string; + title?: string; + }; + array?: Array<{ + description?: string; + 'x-enum-descriptions'?: string; + 'x-enum-varnames'?: string; + 'x-enumNames'?: string; + title?: string; + }>; +}; + +/** + * This schema was giving PascalCase transformations a hard time + */ +export type io_k8s_apimachinery_pkg_apis_meta_v1_DeleteOptions = { + /** + * Must be fulfilled before a deletion is carried out. If not possible, a 409 Conflict status will be returned. + */ + preconditions?: io_k8s_apimachinery_pkg_apis_meta_v1_Preconditions; +}; + +/** + * This schema was giving PascalCase transformations a hard time + */ +export type io_k8s_apimachinery_pkg_apis_meta_v1_Preconditions = { + /** + * Specifies the target ResourceVersion + */ + resourceVersion?: string; + /** + * Specifies the target UID. + */ + uid?: string; +}; + +export type AdditionalPropertiesUnknownIssue = { + [key: string]: string | number; +}; + +export type AdditionalPropertiesUnknownIssue2 = { + [key: string]: string | number; +}; + +export type AdditionalPropertiesUnknownIssue3 = string & { + entries: { + [key: string]: AdditionalPropertiesUnknownIssue; + }; +}; + +export type AdditionalPropertiesIntegerIssue = { + value: number; + [key: string]: number; +}; + +export type OneOfAllOfIssue = ((ConstValue | Generic_Schema_Duplicate_Issue_1_System_Boolean_) & _3e_num_1Период) | Generic_Schema_Duplicate_Issue_1_System_String_; + +export type Generic_Schema_Duplicate_Issue_1_System_Boolean_ = { + item?: boolean; + error?: string | null; + readonly hasError?: boolean; + data?: { + [key: string]: never; + }; +}; + +export type Generic_Schema_Duplicate_Issue_1_System_String_ = { + item?: string | null; + error?: string | null; + readonly hasError?: boolean; +}; + +/** + * This is a reusable parameter + */ +export type SimpleParameter = string; + +/** + * Parameter with illegal characters + */ +export type x_Foo_Bar = ModelWithString; + +export type ImportData = { + body: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; +}; + +export type ImportResponse = Model_From_Zendesk | ModelWithReadOnlyAndWriteOnly; + +export type ApiVversionOdataControllerCountResponse = Model_From_Zendesk; + +export type GetApiVbyApiVersionSimpleOperationData = { + body?: never; + path: { + /** + * foo in method + */ + foo_param: string; + }; + query?: never; +}; + +export type GetApiVbyApiVersionSimpleOperationError = ModelWithBoolean; + +export type GetApiVbyApiVersionSimpleOperationResponse = number; + +export type DeleteFooData3 = { + body?: never; + headers: { + /** + * Parameter with illegal characters + */ + 'x-Foo-Bar': ModelWithString; + }; + path: { + /** + * foo in method + */ + foo_param: string; + /** + * bar in method + */ + BarParam: string; + }; + query?: never; +}; + +export type CallWithDescriptionsData = { + body?: never; + path?: never; + query?: { + /** + * Testing multiline comments in string: First line + * Second line + * + * Fourth line + */ + parameterWithBreaks?: string; + /** + * Testing backticks in string: `backticks` and ```multiple backticks``` should work + */ + parameterWithBackticks?: string; + /** + * Testing slashes in string: \backwards\\\ and /forwards/// should work + */ + parameterWithSlashes?: string; + /** + * Testing expression placeholders in string: ${expression} should work + */ + parameterWithExpressionPlaceholders?: string; + /** + * Testing quotes in string: 'single quote''' and "double quotes""" should work + */ + parameterWithQuotes?: string; + /** + * Testing reserved characters in string: * inline * and ** inline ** should work + */ + parameterWithReservedCharacters?: string; + }; +}; + +export type DeprecatedCallData = { + body?: never; + headers: { + /** + * This parameter is deprecated + * @deprecated + */ + parameter: DeprecatedModel | null; + }; + path?: never; + query?: never; +}; + +export type CallWithParametersData = { + /** + * This is the parameter that goes into the body + */ + body: {} | null; + headers: { + /** + * This is the parameter that goes into the header + */ + parameterHeader: string | null; + }; + path: { + /** + * This is the parameter that goes into the path + */ + parameterPath: string | null; + /** + * api-version should be required in standalone clients + */ + 'api-version': string | null; + }; + query: { + foo_ref_enum?: ModelWithNestedArrayEnumsDataFoo; + foo_all_of_enum: ModelWithNestedArrayEnumsDataFoo; + /** + * This is the parameter that goes into the query params + */ + cursor: string | null; + }; +}; + +export type CallWithWeirdParameterNamesData = { + /** + * This is the parameter that goes into the body + */ + body: ModelWithString | null; + headers: { + /** + * This is the parameter that goes into the request header + */ + 'parameter.header': string | null; + }; + path: { + /** + * This is the parameter that goes into the path + */ + 'parameter.path.1'?: string; + /** + * This is the parameter that goes into the path + */ + 'parameter-path-2'?: string; + /** + * This is the parameter that goes into the path + */ + 'PARAMETER-PATH-3'?: string; + /** + * api-version should be required in standalone clients + */ + 'api-version': string | null; + }; + query: { + /** + * This is the parameter with a reserved keyword + */ + default?: string; + /** + * This is the parameter that goes into the request query params + */ + 'parameter-query': string | null; + }; +}; + +export type GetCallWithOptionalParamData = { + /** + * This is a required parameter + */ + body: ModelWithOneOfEnum; + path?: never; + query?: { + /** + * This is an optional parameter + */ + page?: number; + }; +}; + +export type PostCallWithOptionalParamData = { + /** + * This is an optional parameter + */ + body?: { + offset?: number | null; + }; + path?: never; + query: { + /** + * This is a required parameter + */ + parameter: Pageable; + }; +}; + +export type PostCallWithOptionalParamResponse = number | void; + +export type PostApiVbyApiVersionRequestBodyData = { + /** + * A reusable request body + */ + body?: ModelWithString; + path?: never; + query?: { + /** + * This is a reusable parameter + */ + parameter?: string; + }; +}; + +export type PostApiVbyApiVersionFormDataData = { + /** + * A reusable request body + */ + body?: ModelWithString; + path?: never; + query?: { + /** + * This is a reusable parameter + */ + parameter?: string; + }; +}; + +export type CallWithDefaultParametersData = { + body?: never; + path?: never; + query?: { + /** + * This is a simple string with default value + */ + parameterString?: string | null; + /** + * This is a simple number with default value + */ + parameterNumber?: number | null; + /** + * This is a simple boolean with default value + */ + parameterBoolean?: boolean | null; + /** + * This is a simple enum with default value + */ + parameterEnum?: 'Success' | 'Warning' | 'Error'; + /** + * This is a simple model with default value + */ + parameterModel?: ModelWithString | null; + }; +}; + +export type CallWithDefaultOptionalParametersData = { + body?: never; + path?: never; + query?: { + /** + * This is a simple string that is optional with default value + */ + parameterString?: string; + /** + * This is a simple number that is optional with default value + */ + parameterNumber?: number; + /** + * This is a simple boolean that is optional with default value + */ + parameterBoolean?: boolean; + /** + * This is a simple enum that is optional with default value + */ + parameterEnum?: 'Success' | 'Warning' | 'Error'; + /** + * This is a simple model that is optional with default value + */ + parameterModel?: ModelWithString; + }; +}; + +export type CallToTestOrderOfParamsData = { + body?: never; + path?: never; + query: { + /** + * This is a optional string with default + */ + parameterOptionalStringWithDefault?: string; + /** + * This is a optional string with empty default + */ + parameterOptionalStringWithEmptyDefault?: string; + /** + * This is a optional string with no default + */ + parameterOptionalStringWithNoDefault?: string; + /** + * This is a string with default + */ + parameterStringWithDefault: string; + /** + * This is a string with empty default + */ + parameterStringWithEmptyDefault: string; + /** + * This is a string with no default + */ + parameterStringWithNoDefault: string; + /** + * This is a string that can be null with no default + */ + parameterStringNullableWithNoDefault?: string | null; + /** + * This is a string that can be null with default + */ + parameterStringNullableWithDefault?: string | null; + }; +}; + +export type CallWithNoContentResponseResponse = void; + +export type CallWithResponseAndNoContentResponseResponse = number | void; + +export type DummyAResponse = _400; + +export type DummyBResponse = void; + +export type CallWithResponseResponse = _import; + +export type CallWithDuplicateResponsesError = ModelWithStringError | DictionaryWithArray | ModelWithBoolean; + +export type CallWithDuplicateResponsesResponse = (ModelWithBoolean & ModelWithInteger) | ModelWithString; + +export type CallWithResponsesError = ModelWithStringError; + +export type CallWithResponsesResponse = { + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; + readonly value?: Array; +} | ModelThatExtends | ModelThatExtendsExtends; + +export type CollectionFormatData = { + body?: never; + path?: never; + query: { + /** + * This is an array parameter that is sent as csv format (comma-separated values) + */ + parameterArrayCSV: Array | null; + /** + * This is an array parameter that is sent as ssv format (space-separated values) + */ + parameterArraySSV: Array | null; + /** + * This is an array parameter that is sent as tsv format (tab-separated values) + */ + parameterArrayTSV: Array | null; + /** + * This is an array parameter that is sent as pipes format (pipe-separated values) + */ + parameterArrayPipes: Array | null; + /** + * This is an array parameter that is sent as multi format (multiple parameter instances) + */ + parameterArrayMulti: Array | null; + }; +}; + +export type TypesData = { + body?: never; + path?: { + /** + * This is a number parameter + */ + id?: number; + }; + query: { + /** + * This is a number parameter + */ + parameterNumber: number; + /** + * This is a string parameter + */ + parameterString: string | null; + /** + * This is a boolean parameter + */ + parameterBoolean: boolean | null; + /** + * This is an object parameter + */ + parameterObject: {} | null; + /** + * This is an array parameter + */ + parameterArray: Array | null; + /** + * This is a dictionary parameter + */ + parameterDictionary: {} | null; + /** + * This is an enum parameter + */ + parameterEnum: 'Success' | 'Warning' | 'Error'; + }; +}; + +export type TypesResponse = number | string | boolean | {}; + +export type UploadFileData = { + body: Blob | File; + path: { + /** + * api-version should be required in standalone clients + */ + 'api-version': string | null; + }; + query?: never; +}; + +export type UploadFileResponse = boolean; + +export type FileResponseData = { + body?: never; + path: { + id: string; + /** + * api-version should be required in standalone clients + */ + 'api-version': string; + }; + query?: never; +}; + +export type FileResponseResponse = Blob | File; + +export type ComplexTypesData = { + body?: never; + path?: never; + query: { + /** + * Parameter containing object + */ + parameterObject: { + first?: { + second?: { + third?: string; + }; + }; + }; + /** + * Parameter containing reference + */ + parameterReference: ModelWithString; + }; +}; + +export type ComplexTypesResponse = Array; + +export type MultipartResponseResponse = { + file?: Blob | File; + metadata?: { + foo?: string; + bar?: string; + }; +}; + +export type MultipartRequestData = { + body?: { + content?: Blob | File; + data?: ModelWithString | null; + }; +}; + +export type ComplexParamsData = { + body?: { + readonly key: string | null; + name: string | null; + enabled?: boolean; + type: 'Monkey' | 'Horse' | 'Bird'; + listOfModels?: Array | null; + listOfStrings?: Array | null; + parameters: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; + readonly user?: { + readonly id?: number; + readonly name?: string | null; + }; + }; + path: { + id: number; + /** + * api-version should be required in standalone clients + */ + 'api-version': string; + }; + query?: never; +}; + +export type ComplexParamsResponse = ModelWithString; + +export type TestErrorCodeData = { + body?: never; + path?: never; + query: { + /** + * Status code to return + */ + status: number; + }; +}; + +export type NonAsciiæøåÆøÅöôêÊ字符串Data = { + body?: never; + path?: never; + query: { + /** + * Dummy input param + */ + nonAsciiParamæøåÆØÅöôêÊ: number; + }; +}; + +export type NonAsciiæøåÆøÅöôêÊ字符串Response = Array; + +export type PutWithFormUrlEncodedData = { + body: ArrayWithStrings; +}; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/fastify/fastify.gen.ts b/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/fastify/fastify.gen.ts new file mode 100644 index 000000000..b44c6b530 --- /dev/null +++ b/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/fastify/fastify.gen.ts @@ -0,0 +1,1477 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { RouteHandler } from 'fastify'; + +/** + * Model with number-only name + */ +export type _400 = string; + +/** + * Testing multiline comments in string: First line + * Second line + * + * Fourth line + */ +export type camelCaseCommentWithBreaks = number; + +/** + * Testing multiline comments in string: First line + * Second line + * + * Fourth line + */ +export type CommentWithBreaks = number; + +/** + * Testing backticks in string: `backticks` and ```multiple backticks``` should work + */ +export type CommentWithBackticks = number; + +/** + * Testing backticks and quotes in string: `backticks`, 'quotes', "double quotes" and ```multiple backticks``` should work + */ +export type CommentWithBackticksAndQuotes = number; + +/** + * Testing slashes in string: \backwards\\\ and /forwards/// should work + */ +export type CommentWithSlashes = number; + +/** + * Testing expression placeholders in string: ${expression} should work + */ +export type CommentWithExpressionPlaceholders = number; + +/** + * Testing quotes in string: 'single quote''' and "double quotes""" should work + */ +export type CommentWithQuotes = number; + +/** + * Testing reserved characters in string: * inline * and ** inline ** should work + */ +export type CommentWithReservedCharacters = number; + +/** + * This is a simple number + */ +export type SimpleInteger = number; + +/** + * This is a simple boolean + */ +export type SimpleBoolean = boolean; + +/** + * This is a simple string + */ +export type SimpleString = string; + +/** + * A string with non-ascii (unicode) characters valid in typescript identifiers (æøåÆØÅöÔèÈ字符串) + */ +export type NonAsciiStringæøåÆØÅöôêÊ字符串 = string; + +/** + * This is a simple file + */ +export type SimpleFile = Blob | File; + +/** + * This is a simple reference + */ +export type SimpleReference = ModelWithString; + +/** + * This is a simple string + */ +export type SimpleStringWithPattern = string | null; + +/** + * This is a simple enum with strings + */ +export type EnumWithStrings = 'Success' | 'Warning' | 'Error' | "'Single Quote'" | '"Double Quotes"' | 'Non-ascii: øæåôöØÆÅÔÖ字符串'; + +export type EnumWithReplacedCharacters = "'Single Quote'" | '"Double Quotes"' | 'øæåôöØÆÅÔÖ字符串' | 3.1 | ''; + +/** + * This is a simple enum with numbers + */ +export type EnumWithNumbers = 1 | 2 | 3 | 1.1 | 1.2 | 1.3 | 100 | 200 | 300 | -100 | -200 | -300 | -1.1 | -1.2 | -1.3; + +/** + * Success=1,Warning=2,Error=3 + */ +export type EnumFromDescription = number; + +/** + * This is a simple enum with numbers + */ +export type EnumWithExtensions = 200 | 400 | 500; + +export type EnumWithXEnumNames = 0 | 1 | 2; + +/** + * This is a simple array with numbers + */ +export type ArrayWithNumbers = Array; + +/** + * This is a simple array with booleans + */ +export type ArrayWithBooleans = Array; + +/** + * This is a simple array with strings + */ +export type ArrayWithStrings = Array; + +/** + * This is a simple array with references + */ +export type ArrayWithReferences = Array; + +/** + * This is a simple array containing an array + */ +export type ArrayWithArray = Array>; + +/** + * This is a simple array with properties + */ +export type ArrayWithProperties = Array<{ + '16x16'?: camelCaseCommentWithBreaks; + bar?: string; +}>; + +/** + * This is a simple array with any of properties + */ +export type ArrayWithAnyOfProperties = Array<{ + foo?: string; +} | { + bar?: string; +}>; + +export type AnyOfAnyAndNull = { + data?: unknown | null; +}; + +/** + * This is a simple array with any of properties + */ +export type AnyOfArrays = { + results?: Array<{ + foo?: string; + } | { + bar?: string; + }>; +}; + +/** + * This is a string dictionary + */ +export type DictionaryWithString = { + [key: string]: string; +}; + +export type DictionaryWithPropertiesAndAdditionalProperties = { + foo?: number; + bar?: boolean; + [key: string]: string | number | boolean | undefined; +}; + +/** + * This is a string reference + */ +export type DictionaryWithReference = { + [key: string]: ModelWithString; +}; + +/** + * This is a complex dictionary + */ +export type DictionaryWithArray = { + [key: string]: Array; +}; + +/** + * This is a string dictionary + */ +export type DictionaryWithDictionary = { + [key: string]: { + [key: string]: string; + }; +}; + +/** + * This is a complex dictionary + */ +export type DictionaryWithProperties = { + [key: string]: { + foo?: string; + bar?: string; + }; +}; + +/** + * This is a model with one number property + */ +export type ModelWithInteger = { + /** + * This is a simple number property + */ + prop?: number; +}; + +/** + * This is a model with one boolean property + */ +export type ModelWithBoolean = { + /** + * This is a simple boolean property + */ + prop?: boolean; +}; + +/** + * This is a model with one string property + */ +export type ModelWithString = { + /** + * This is a simple string property + */ + prop?: string; +}; + +/** + * This is a model with one string property + */ +export type ModelWithStringError = { + /** + * This is a simple string property + */ + prop?: string; +}; + +/** + * `Comment` or `VoiceComment`. The JSON object for adding voice comments to tickets is different. See [Adding voice comments to tickets](/documentation/ticketing/managing-tickets/adding-voice-comments-to-tickets) + */ +export type Model_From_Zendesk = string; + +/** + * This is a model with one string property + */ +export type ModelWithNullableString = { + /** + * This is a simple string property + */ + nullableProp1?: string | null; + /** + * This is a simple string property + */ + nullableRequiredProp1: string | null; + /** + * This is a simple string property + */ + nullableProp2?: string | null; + /** + * This is a simple string property + */ + nullableRequiredProp2: string | null; + /** + * This is a simple enum with strings + */ + 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; +}; + +/** + * This is a model with one enum + */ +export type ModelWithEnum = { + /** + * This is a simple enum with strings + */ + 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; + /** + * These are the HTTP error code enums + */ + statusCode?: '100' | '200 FOO' | '300 FOO_BAR' | '400 foo-bar' | '500 foo.bar' | '600 foo&bar'; + /** + * Simple boolean enum + */ + bool?: true; +}; + +/** + * This is a model with one enum with escaped name + */ +export type ModelWithEnumWithHyphen = { + 'foo-bar-baz-qux'?: '3.0'; +}; + +/** + * This is a model with one enum + */ +export type ModelWithEnumFromDescription = { + /** + * Success=1,Warning=2,Error=3 + */ + test?: number; +}; + +/** + * This is a model with nested enums + */ +export type ModelWithNestedEnums = { + dictionaryWithEnum?: { + [key: string]: 'Success' | 'Warning' | 'Error'; + }; + dictionaryWithEnumFromDescription?: { + [key: string]: number; + }; + arrayWithEnum?: Array<'Success' | 'Warning' | 'Error'>; + arrayWithDescription?: Array; + /** + * This is a simple enum with strings + */ + 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; +}; + +/** + * This is a model with one property containing a reference + */ +export type ModelWithReference = { + prop?: ModelWithProperties; +}; + +/** + * This is a model with one property containing an array + */ +export type ModelWithArrayReadOnlyAndWriteOnly = { + prop?: Array; + propWithFile?: Array; + propWithNumber?: Array; +}; + +/** + * This is a model with one property containing an array + */ +export type ModelWithArray = { + prop?: Array; + propWithFile?: Array; + propWithNumber?: Array; +}; + +/** + * This is a model with one property containing a dictionary + */ +export type ModelWithDictionary = { + prop?: { + [key: string]: string; + }; +}; + +/** + * This is a deprecated model with a deprecated property + * @deprecated + */ +export type DeprecatedModel = { + /** + * This is a deprecated property + * @deprecated + */ + prop?: string; +}; + +/** + * This is a model with one property containing a circular reference + */ +export type ModelWithCircularReference = { + prop?: ModelWithCircularReference; +}; + +/** + * This is a model with one property with a 'one of' relationship + */ +export type CompositionWithOneOf = { + propA?: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; +}; + +/** + * This is a model with one property with a 'one of' relationship where the options are not $ref + */ +export type CompositionWithOneOfAnonymous = { + propA?: { + propA?: string; + } | string | number; +}; + +/** + * Circle + */ +export type ModelCircle = { + kind: string; + radius?: number; +}; + +/** + * Square + */ +export type ModelSquare = { + kind: string; + sideLength?: number; +}; + +/** + * This is a model with one property with a 'one of' relationship where the options are not $ref + */ +export type CompositionWithOneOfDiscriminator = ({ + kind?: 'circle'; +} & ModelCircle) | ({ + kind?: 'square'; +} & ModelSquare); + +/** + * This is a model with one property with a 'any of' relationship + */ +export type CompositionWithAnyOf = { + propA?: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; +}; + +/** + * This is a model with one property with a 'any of' relationship where the options are not $ref + */ +export type CompositionWithAnyOfAnonymous = { + propA?: { + propA?: string; + } | string | number; +}; + +/** + * This is a model with nested 'any of' property with a type null + */ +export type CompositionWithNestedAnyAndTypeNull = { + propA?: Array | Array; +}; + +export type _3e_num_1Период = 'Bird' | 'Dog'; + +export type ConstValue = 'ConstValue'; + +/** + * This is a model with one property with a 'any of' relationship where the options are not $ref + */ +export type CompositionWithNestedAnyOfAndNull = { + propA?: Array<_3e_num_1Период | ConstValue> | null; +}; + +/** + * This is a model with one property with a 'one of' relationship + */ +export type CompositionWithOneOfAndNullable = { + propA?: { + boolean?: boolean; + } | ModelWithEnum | ModelWithArray | ModelWithDictionary | null; +}; + +/** + * This is a model that contains a simple dictionary within composition + */ +export type CompositionWithOneOfAndSimpleDictionary = { + propA?: boolean | { + [key: string]: number; + }; +}; + +/** + * This is a model that contains a dictionary of simple arrays within composition + */ +export type CompositionWithOneOfAndSimpleArrayDictionary = { + propA?: boolean | { + [key: string]: Array; + }; +}; + +/** + * This is a model that contains a dictionary of complex arrays (composited) within composition + */ +export type CompositionWithOneOfAndComplexArrayDictionary = { + propA?: boolean | { + [key: string]: Array; + }; +}; + +/** + * This is a model with one property with a 'all of' relationship + */ +export type CompositionWithAllOfAndNullable = { + propA?: ({ + boolean?: boolean; + } & ModelWithEnum & ModelWithArray & ModelWithDictionary) | null; +}; + +/** + * This is a model with one property with a 'any of' relationship + */ +export type CompositionWithAnyOfAndNullable = { + propA?: { + boolean?: boolean; + } | ModelWithEnum | ModelWithArray | ModelWithDictionary | null; +}; + +/** + * This is a base model with two simple optional properties + */ +export type CompositionBaseModel = { + firstName?: string; + lastname?: string; +}; + +/** + * This is a model that extends the base model + */ +export type CompositionExtendedModel = CompositionBaseModel & { + age: number; + firstName: string; + lastname: string; +}; + +/** + * This is a model with one nested property + */ +export type ModelWithProperties = { + required: string; + readonly requiredAndReadOnly: string; + requiredAndNullable: string | null; + string?: string; + number?: number; + boolean?: boolean; + reference?: ModelWithString; + 'property with space'?: string; + default?: string; + try?: string; + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; +}; + +/** + * This is a model with one nested property + */ +export type ModelWithNestedProperties = { + readonly first: { + readonly second: { + readonly third: string | null; + } | null; + } | null; +}; + +/** + * This is a model with duplicated properties + */ +export type ModelWithDuplicateProperties = { + prop?: ModelWithString; +}; + +/** + * This is a model with ordered properties + */ +export type ModelWithOrderedProperties = { + zebra?: string; + apple?: string; + hawaii?: string; +}; + +/** + * This is a model with duplicated imports + */ +export type ModelWithDuplicateImports = { + propA?: ModelWithString; + propB?: ModelWithString; + propC?: ModelWithString; +}; + +/** + * This is a model that extends another model + */ +export type ModelThatExtends = ModelWithString & { + propExtendsA?: string; + propExtendsB?: ModelWithString; +}; + +/** + * This is a model that extends another model + */ +export type ModelThatExtendsExtends = ModelWithString & ModelThatExtends & { + propExtendsC?: string; + propExtendsD?: ModelWithString; +}; + +/** + * This is a model that contains a some patterns + */ +export type ModelWithPattern = { + key: string; + name: string; + readonly enabled?: boolean; + readonly modified?: string; + id?: string; + text?: string; + patternWithSingleQuotes?: string; + patternWithNewline?: string; + patternWithBacktick?: string; +}; + +export type File = { + readonly id?: string; + readonly updated_at?: string; + readonly created_at?: string; + mime: string; + readonly file?: string; +}; + +export type _default = { + name?: string; +}; + +export type Pageable = { + page?: number; + size?: number; + sort?: Array; +}; + +/** + * This is a free-form object without additionalProperties. + */ +export type FreeFormObjectWithoutAdditionalProperties = {}; + +/** + * This is a free-form object with additionalProperties: true. + */ +export type FreeFormObjectWithAdditionalPropertiesEqTrue = { + [key: string]: unknown; +}; + +/** + * This is a free-form object with additionalProperties: {}. + */ +export type FreeFormObjectWithAdditionalPropertiesEqEmptyObject = {}; + +export type ModelWithConst = { + String?: 'String'; + number?: 0; + null?: null; + withType?: 'Some string'; +}; + +/** + * This is a model with one property and additionalProperties: true + */ +export type ModelWithAdditionalPropertiesEqTrue = { + /** + * This is a simple string property + */ + prop?: string; + [key: string]: unknown | string | undefined; +}; + +export type NestedAnyOfArraysNullable = { + nullableArray?: Array | null; +}; + +export type CompositionWithOneOfAndProperties = ({ + foo: SimpleParameter; +} | { + bar: NonAsciiStringæøåÆØÅöôêÊ字符串; +}) & { + baz: number | null; + qux: number; +}; + +/** + * An object that can be null + */ +export type NullableObject = { + foo?: string; +} | null; + +/** + * Some % character + */ +export type CharactersInDescription = string; + +export type ModelWithNullableObject = { + data?: NullableObject; +}; + +export type ModelWithOneOfEnum = { + foo: 'Bar'; +} | { + foo: 'Baz'; +} | { + foo: 'Qux'; +} | { + content: string; + foo: 'Quux'; +} | { + content: [ + string, + string + ]; + foo: 'Corge'; +}; + +export type ModelWithNestedArrayEnumsDataFoo = 'foo' | 'bar'; + +export type ModelWithNestedArrayEnumsDataBar = 'baz' | 'qux'; + +export type ModelWithNestedArrayEnumsData = { + foo?: Array; + bar?: Array; +}; + +export type ModelWithNestedArrayEnums = { + array_strings?: Array; + data?: ModelWithNestedArrayEnumsData; +}; + +export type ModelWithNestedCompositionEnums = { + foo?: ModelWithNestedArrayEnumsDataFoo; +}; + +export type ModelWithReadOnlyAndWriteOnly = { + foo: string; + readonly bar: string; + baz: string; +}; + +export type ModelWithConstantSizeArray = [ + number, + number +]; + +export type ModelWithAnyOfConstantSizeArray = [ + number | string, + number | string, + number | string +]; + +export type ModelWithPrefixItemsConstantSizeArray = [ + ModelWithInteger, + number | string, + string +]; + +export type ModelWithAnyOfConstantSizeArrayNullable = [ + number | null | string, + number | null | string, + number | null | string +]; + +export type ModelWithAnyOfConstantSizeArrayWithNSizeAndOptions = [ + number | _import, + number | _import +]; + +export type ModelWithAnyOfConstantSizeArrayAndIntersect = [ + number & string, + number & string +]; + +export type ModelWithNumericEnumUnion = { + /** + * Период + */ + value?: -10 | -1 | 0 | 1 | 3 | 6 | 12; +}; + +/** + * Some description with `back ticks` + */ +export type ModelWithBackticksInDescription = { + /** + * The template `that` should be used for parsing and importing the contents of the CSV file. + * + *

There is one placeholder currently supported:

  • ${x} - refers to the n-th column in the CSV file, e.g. ${1}, ${2}, ...)

Example of a correct JSON template:

+ *
+     * [
+     * {
+     * "resourceType": "Asset",
+     * "identifier": {
+     * "name": "${1}",
+     * "domain": {
+     * "name": "${2}",
+     * "community": {
+     * "name": "Some Community"
+     * }
+     * }
+     * },
+     * "attributes" : {
+     * "00000000-0000-0000-0000-000000003115" : [ {
+     * "value" : "${3}"
+     * } ],
+     * "00000000-0000-0000-0000-000000000222" : [ {
+     * "value" : "${4}"
+     * } ]
+     * }
+     * }
+     * ]
+     * 
+ */ + template?: string; +}; + +export type ModelWithOneOfAndProperties = (SimpleParameter | NonAsciiStringæøåÆØÅöôêÊ字符串) & { + baz: number | null; + qux: number; +}; + +/** + * Model used to test deduplication strategy (unused) + */ +export type ParameterSimpleParameterUnused = string; + +/** + * Model used to test deduplication strategy + */ +export type PostServiceWithEmptyTagResponse = string; + +/** + * Model used to test deduplication strategy + */ +export type PostServiceWithEmptyTagResponse2 = string; + +/** + * Model used to test deduplication strategy + */ +export type DeleteFooData = string; + +/** + * Model used to test deduplication strategy + */ +export type DeleteFooData2 = string; + +/** + * Model with restricted keyword name + */ +export type _import = string; + +export type SchemaWithFormRestrictedKeys = { + description?: string; + 'x-enum-descriptions'?: string; + 'x-enum-varnames'?: string; + 'x-enumNames'?: string; + title?: string; + object?: { + description?: string; + 'x-enum-descriptions'?: string; + 'x-enum-varnames'?: string; + 'x-enumNames'?: string; + title?: string; + }; + array?: Array<{ + description?: string; + 'x-enum-descriptions'?: string; + 'x-enum-varnames'?: string; + 'x-enumNames'?: string; + title?: string; + }>; +}; + +/** + * This schema was giving PascalCase transformations a hard time + */ +export type io_k8s_apimachinery_pkg_apis_meta_v1_DeleteOptions = { + /** + * Must be fulfilled before a deletion is carried out. If not possible, a 409 Conflict status will be returned. + */ + preconditions?: io_k8s_apimachinery_pkg_apis_meta_v1_Preconditions; +}; + +/** + * This schema was giving PascalCase transformations a hard time + */ +export type io_k8s_apimachinery_pkg_apis_meta_v1_Preconditions = { + /** + * Specifies the target ResourceVersion + */ + resourceVersion?: string; + /** + * Specifies the target UID. + */ + uid?: string; +}; + +export type AdditionalPropertiesUnknownIssue = { + [key: string]: string | number; +}; + +export type AdditionalPropertiesUnknownIssue2 = { + [key: string]: string | number; +}; + +export type AdditionalPropertiesUnknownIssue3 = string & { + entries: { + [key: string]: AdditionalPropertiesUnknownIssue; + }; +}; + +export type AdditionalPropertiesIntegerIssue = { + value: number; + [key: string]: number; +}; + +export type OneOfAllOfIssue = ((ConstValue | Generic_Schema_Duplicate_Issue_1_System_Boolean_) & _3e_num_1Период) | Generic_Schema_Duplicate_Issue_1_System_String_; + +export type Generic_Schema_Duplicate_Issue_1_System_Boolean_ = { + item?: boolean; + error?: string | null; + readonly hasError?: boolean; + data?: { + [key: string]: never; + }; +}; + +export type Generic_Schema_Duplicate_Issue_1_System_String_ = { + item?: string | null; + error?: string | null; + readonly hasError?: boolean; +}; + +/** + * This is a reusable parameter + */ +export type SimpleParameter = string; + +/** + * Parameter with illegal characters + */ +export type x_Foo_Bar = ModelWithString; + +export type RouteHandlers = { + export: RouteHandler<{}>; + import: RouteHandler<{ + Body: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; + Reply: { + 200: Model_From_Zendesk; + }; + }>; + apiVVersionOdataControllerCount: RouteHandler<{ + Reply: { + 200: Model_From_Zendesk; + }; + }>; + getApiVbyApiVersionSimpleOperation: RouteHandler<{ + Params: { + /** + * foo in method + */ + foo_param: unknown; + }; + Reply: { + 200: number; + }; + }>; + deleteCallWithoutParametersAndResponse: RouteHandler<{}>; + getCallWithoutParametersAndResponse: RouteHandler<{}>; + headCallWithoutParametersAndResponse: RouteHandler<{}>; + optionsCallWithoutParametersAndResponse: RouteHandler<{}>; + patchCallWithoutParametersAndResponse: RouteHandler<{}>; + postCallWithoutParametersAndResponse: RouteHandler<{}>; + putCallWithoutParametersAndResponse: RouteHandler<{}>; + deleteFoo: RouteHandler<{ + Headers: { + /** + * Parameter with illegal characters + */ + 'x-Foo-Bar': ModelWithString; + }; + Params: { + /** + * foo in method + */ + foo_param: string; + /** + * bar in method + */ + BarParam: string; + }; + }>; + callWithDescriptions: RouteHandler<{ + Querystring?: { + /** + * Testing multiline comments in string: First line + * Second line + * + * Fourth line + */ + parameterWithBreaks?: string; + /** + * Testing backticks in string: `backticks` and ```multiple backticks``` should work + */ + parameterWithBackticks?: string; + /** + * Testing slashes in string: \backwards\\\ and /forwards/// should work + */ + parameterWithSlashes?: string; + /** + * Testing expression placeholders in string: ${expression} should work + */ + parameterWithExpressionPlaceholders?: string; + /** + * Testing quotes in string: 'single quote''' and "double quotes""" should work + */ + parameterWithQuotes?: string; + /** + * Testing reserved characters in string: * inline * and ** inline ** should work + */ + parameterWithReservedCharacters?: string; + }; + }>; + deprecatedCall: RouteHandler<{ + Headers: { + /** + * This parameter is deprecated + * @deprecated + */ + parameter: DeprecatedModel | null; + }; + }>; + callWithParameters: RouteHandler<{ + Body: {} | null; + Headers: { + /** + * This is the parameter that goes into the header + */ + parameterHeader: string | null; + }; + Querystring: { + foo_ref_enum?: ModelWithNestedArrayEnumsDataFoo; + foo_all_of_enum: ModelWithNestedArrayEnumsDataFoo; + /** + * This is the parameter that goes into the query params + */ + cursor: string | null; + }; + Params: { + /** + * This is the parameter that goes into the path + */ + parameterPath: string | null; + /** + * api-version should be required in standalone clients + */ + 'api-version': string | null; + }; + }>; + callWithWeirdParameterNames: RouteHandler<{ + Body: ModelWithString | null; + Headers: { + /** + * This is the parameter that goes into the request header + */ + 'parameter.header': string | null; + }; + Querystring: { + /** + * This is the parameter with a reserved keyword + */ + default?: string; + /** + * This is the parameter that goes into the request query params + */ + 'parameter-query': string | null; + }; + Params: { + /** + * This is the parameter that goes into the path + */ + 'parameter.path.1'?: string; + /** + * This is the parameter that goes into the path + */ + 'parameter-path-2'?: string; + /** + * This is the parameter that goes into the path + */ + 'PARAMETER-PATH-3'?: string; + /** + * api-version should be required in standalone clients + */ + 'api-version': string | null; + }; + }>; + getCallWithOptionalParam: RouteHandler<{ + Body: ModelWithOneOfEnum; + Querystring?: { + /** + * This is an optional parameter + */ + page?: number; + }; + }>; + postCallWithOptionalParam: RouteHandler<{ + Body: { + offset?: number | null; + }; + Querystring: { + /** + * This is a required parameter + */ + parameter: Pageable; + }; + Reply: { + 200: number; + 204: void; + }; + }>; + postApiVbyApiVersionRequestBody: RouteHandler<{ + Body: ModelWithString; + Querystring?: { + /** + * This is a reusable parameter + */ + parameter?: string; + }; + }>; + postApiVbyApiVersionFormData: RouteHandler<{ + Body: ModelWithString; + Querystring?: { + /** + * This is a reusable parameter + */ + parameter?: string; + }; + }>; + callWithDefaultParameters: RouteHandler<{ + Querystring?: { + /** + * This is a simple string with default value + */ + parameterString?: string | null; + /** + * This is a simple number with default value + */ + parameterNumber?: number | null; + /** + * This is a simple boolean with default value + */ + parameterBoolean?: boolean | null; + /** + * This is a simple enum with default value + */ + parameterEnum?: 'Success' | 'Warning' | 'Error'; + /** + * This is a simple model with default value + */ + parameterModel?: ModelWithString | null; + }; + }>; + callWithDefaultOptionalParameters: RouteHandler<{ + Querystring?: { + /** + * This is a simple string that is optional with default value + */ + parameterString?: string; + /** + * This is a simple number that is optional with default value + */ + parameterNumber?: number; + /** + * This is a simple boolean that is optional with default value + */ + parameterBoolean?: boolean; + /** + * This is a simple enum that is optional with default value + */ + parameterEnum?: 'Success' | 'Warning' | 'Error'; + /** + * This is a simple model that is optional with default value + */ + parameterModel?: ModelWithString; + }; + }>; + callToTestOrderOfParams: RouteHandler<{ + Querystring: { + /** + * This is a optional string with default + */ + parameterOptionalStringWithDefault?: string; + /** + * This is a optional string with empty default + */ + parameterOptionalStringWithEmptyDefault?: string; + /** + * This is a optional string with no default + */ + parameterOptionalStringWithNoDefault?: string; + /** + * This is a string with default + */ + parameterStringWithDefault: string; + /** + * This is a string with empty default + */ + parameterStringWithEmptyDefault: string; + /** + * This is a string with no default + */ + parameterStringWithNoDefault: string; + /** + * This is a string that can be null with no default + */ + parameterStringNullableWithNoDefault?: string | null; + /** + * This is a string that can be null with default + */ + parameterStringNullableWithDefault?: string | null; + }; + }>; + duplicateName: RouteHandler<{}>; + duplicateName2: RouteHandler<{}>; + duplicateName3: RouteHandler<{}>; + duplicateName4: RouteHandler<{}>; + callWithNoContentResponse: RouteHandler<{ + Reply: { + 204: void; + }; + }>; + callWithResponseAndNoContentResponse: RouteHandler<{ + Reply: { + 200: number; + 204: void; + }; + }>; + dummyA: RouteHandler<{ + Reply: { + 200: _400; + }; + }>; + dummyB: RouteHandler<{ + Reply: { + 204: void; + }; + }>; + callWithResponse: RouteHandler<{ + Reply: {}; + }>; + callWithDuplicateResponses: RouteHandler<{ + Reply: { + 200: ModelWithBoolean & ModelWithInteger; + 201: ModelWithString; + 202: ModelWithString; + 500: ModelWithStringError; + 501: ModelWithStringError; + 502: ModelWithStringError; + '4XX': DictionaryWithArray; + }; + }>; + callWithResponses: RouteHandler<{ + Reply: { + 200: { + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; + readonly value?: Array; + }; + 201: ModelThatExtends; + 202: ModelThatExtendsExtends; + 500: ModelWithStringError; + 501: ModelWithStringError; + 502: ModelWithStringError; + }; + }>; + collectionFormat: RouteHandler<{ + Querystring: { + /** + * This is an array parameter that is sent as csv format (comma-separated values) + */ + parameterArrayCSV: Array | null; + /** + * This is an array parameter that is sent as ssv format (space-separated values) + */ + parameterArraySSV: Array | null; + /** + * This is an array parameter that is sent as tsv format (tab-separated values) + */ + parameterArrayTSV: Array | null; + /** + * This is an array parameter that is sent as pipes format (pipe-separated values) + */ + parameterArrayPipes: Array | null; + /** + * This is an array parameter that is sent as multi format (multiple parameter instances) + */ + parameterArrayMulti: Array | null; + }; + }>; + types: RouteHandler<{ + Querystring: { + /** + * This is a number parameter + */ + parameterNumber: number; + /** + * This is a string parameter + */ + parameterString: string | null; + /** + * This is a boolean parameter + */ + parameterBoolean: boolean | null; + /** + * This is an object parameter + */ + parameterObject: {} | null; + /** + * This is an array parameter + */ + parameterArray: Array | null; + /** + * This is a dictionary parameter + */ + parameterDictionary: {} | null; + /** + * This is an enum parameter + */ + parameterEnum: 'Success' | 'Warning' | 'Error' | null; + }; + Params?: { + /** + * This is a number parameter + */ + id?: number; + }; + Reply: { + 200: number; + 201: string; + 202: boolean; + 203: {}; + }; + }>; + uploadFile: RouteHandler<{ + Body: Blob | File; + Params: { + /** + * api-version should be required in standalone clients + */ + 'api-version': string | null; + }; + Reply: { + 200: boolean; + }; + }>; + fileResponse: RouteHandler<{ + Params: { + id: string; + /** + * api-version should be required in standalone clients + */ + 'api-version': string; + }; + Reply: { + 200: Blob | File; + }; + }>; + complexTypes: RouteHandler<{ + Querystring: { + /** + * Parameter containing object + */ + parameterObject: { + first?: { + second?: { + third?: string; + }; + }; + }; + /** + * Parameter containing reference + */ + parameterReference: ModelWithString; + }; + Reply: { + 200: Array; + 400: unknown; + 500: unknown; + }; + }>; + multipartResponse: RouteHandler<{ + Reply: { + 200: { + file?: Blob | File; + metadata?: { + foo?: string; + bar?: string; + }; + }; + }; + }>; + multipartRequest: RouteHandler<{ + Body: { + content?: Blob | File; + data?: ModelWithString | null; + }; + }>; + complexParams: RouteHandler<{ + Body: { + readonly key: string | null; + name: string | null; + enabled?: boolean; + type: 'Monkey' | 'Horse' | 'Bird'; + listOfModels?: Array | null; + listOfStrings?: Array | null; + parameters: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; + readonly user?: { + readonly id?: number; + readonly name?: string | null; + }; + }; + Params: { + id: number; + /** + * api-version should be required in standalone clients + */ + 'api-version': string; + }; + Reply: { + 200: ModelWithString; + }; + }>; + callWithResultFromHeader: RouteHandler<{ + Reply: { + 200: unknown; + 400: unknown; + 500: unknown; + }; + }>; + testErrorCode: RouteHandler<{ + Querystring: { + /** + * Status code to return + */ + status: number; + }; + Reply: { + 200: unknown; + 500: unknown; + 501: unknown; + 502: unknown; + 503: unknown; + }; + }>; + nonAsciiæøåÆøÅöôêÊ字符串: RouteHandler<{ + Querystring: { + /** + * Dummy input param + */ + nonAsciiParamæøåÆØÅöôêÊ: number; + }; + Reply: { + 200: Array; + }; + }>; + putWithFormUrlEncoded: RouteHandler<{ + Body: ArrayWithStrings; + }>; +}; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/fastify/index.ts b/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/fastify/index.ts new file mode 100644 index 000000000..e3705920c --- /dev/null +++ b/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/fastify/index.ts @@ -0,0 +1,3 @@ +// This file is auto-generated by @hey-api/openapi-ts +export * from './types.gen'; +export * from './services.gen'; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/fastify/services.gen.ts b/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/fastify/services.gen.ts new file mode 100644 index 000000000..c79ed1e8c --- /dev/null +++ b/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/fastify/services.gen.ts @@ -0,0 +1,382 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { createClient, createConfig, type Options, formDataBodySerializer, urlSearchParamsBodySerializer } from '@hey-api/client-fetch'; +import type { ImportData, ImportResponse, ApiVversionOdataControllerCountResponse, GetApiVbyApiVersionSimpleOperationData, GetApiVbyApiVersionSimpleOperationError, GetApiVbyApiVersionSimpleOperationResponse, DeleteFooData3, CallWithDescriptionsData, DeprecatedCallData, CallWithParametersData, CallWithWeirdParameterNamesData, GetCallWithOptionalParamData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponse, PostApiVbyApiVersionRequestBodyData, PostApiVbyApiVersionFormDataData, CallWithDefaultParametersData, CallWithDefaultOptionalParametersData, CallToTestOrderOfParamsData, CallWithNoContentResponseResponse, CallWithResponseAndNoContentResponseResponse, DummyAResponse, DummyBResponse, CallWithResponseResponse, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithResponsesError, CallWithResponsesResponse, CollectionFormatData, TypesData, TypesResponse, UploadFileData, UploadFileResponse, FileResponseData, FileResponseResponse, ComplexTypesData, ComplexTypesResponse, MultipartResponseResponse, MultipartRequestData, ComplexParamsData, ComplexParamsResponse, TestErrorCodeData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PutWithFormUrlEncodedData } from './types.gen'; + +export const client = createClient(createConfig()); + +export const export_ = (options?: Options) => { + return (options?.client ?? client).get({ + ...options, + url: '/api/v{api-version}/no-tag' + }); +}; + +export const import_ = (options: Options) => { + return (options?.client ?? client).post({ + ...options, + headers: { + 'Content-Type': 'application/json', + ...options?.headers + }, + url: '/api/v{api-version}/no-tag' + }); +}; + +export const apiVVersionOdataControllerCount = (options?: Options) => { + return (options?.client ?? client).get({ + ...options, + url: '/api/v{api-version}/simple/$count' + }); +}; + +export const getApiVbyApiVersionSimpleOperation = (options: Options) => { + return (options?.client ?? client).get({ + ...options, + url: '/api/v{api-version}/simple:operation' + }); +}; + +export const deleteCallWithoutParametersAndResponse = (options?: Options) => { + return (options?.client ?? client).delete({ + ...options, + url: '/api/v{api-version}/simple' + }); +}; + +export const getCallWithoutParametersAndResponse = (options?: Options) => { + return (options?.client ?? client).get({ + ...options, + url: '/api/v{api-version}/simple' + }); +}; + +export const headCallWithoutParametersAndResponse = (options?: Options) => { + return (options?.client ?? client).head({ + ...options, + url: '/api/v{api-version}/simple' + }); +}; + +export const optionsCallWithoutParametersAndResponse = (options?: Options) => { + return (options?.client ?? client).options({ + ...options, + url: '/api/v{api-version}/simple' + }); +}; + +export const patchCallWithoutParametersAndResponse = (options?: Options) => { + return (options?.client ?? client).patch({ + ...options, + url: '/api/v{api-version}/simple' + }); +}; + +export const postCallWithoutParametersAndResponse = (options?: Options) => { + return (options?.client ?? client).post({ + ...options, + url: '/api/v{api-version}/simple' + }); +}; + +export const putCallWithoutParametersAndResponse = (options?: Options) => { + return (options?.client ?? client).put({ + ...options, + url: '/api/v{api-version}/simple' + }); +}; + +export const deleteFoo = (options: Options) => { + return (options?.client ?? client).delete({ + ...options, + url: '/api/v{api-version}/foo/{foo_param}/bar/{BarParam}' + }); +}; + +export const callWithDescriptions = (options?: Options) => { + return (options?.client ?? client).post({ + ...options, + url: '/api/v{api-version}/descriptions' + }); +}; + +/** + * @deprecated + */ +export const deprecatedCall = (options: Options) => { + return (options?.client ?? client).post({ + ...options, + url: '/api/v{api-version}/parameters/deprecated' + }); +}; + +export const callWithParameters = (options: Options) => { + return (options?.client ?? client).post({ + ...options, + headers: { + 'Content-Type': 'application/json', + ...options?.headers + }, + url: '/api/v{api-version}/parameters/{parameterPath}' + }); +}; + +export const callWithWeirdParameterNames = (options: Options) => { + return (options?.client ?? client).post({ + ...options, + headers: { + 'Content-Type': 'application/json', + ...options?.headers + }, + url: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}' + }); +}; + +export const getCallWithOptionalParam = (options: Options) => { + return (options?.client ?? client).get({ + ...options, + headers: { + 'Content-Type': 'application/json', + ...options?.headers + }, + url: '/api/v{api-version}/parameters' + }); +}; + +export const postCallWithOptionalParam = (options: Options) => { + return (options?.client ?? client).post({ + ...options, + headers: { + 'Content-Type': 'application/json', + ...options?.headers + }, + url: '/api/v{api-version}/parameters' + }); +}; + +export const postApiVbyApiVersionRequestBody = (options?: Options) => { + return (options?.client ?? client).post({ + ...options, + headers: { + 'Content-Type': 'application/json', + ...options?.headers + }, + url: '/api/v{api-version}/requestBody' + }); +}; + +export const postApiVbyApiVersionFormData = (options?: Options) => { + return (options?.client ?? client).post({ + ...options, + ...formDataBodySerializer, + headers: { + 'Content-Type': null, + ...options?.headers + }, + url: '/api/v{api-version}/formData' + }); +}; + +export const callWithDefaultParameters = (options?: Options) => { + return (options?.client ?? client).get({ + ...options, + url: '/api/v{api-version}/defaults' + }); +}; + +export const callWithDefaultOptionalParameters = (options?: Options) => { + return (options?.client ?? client).post({ + ...options, + url: '/api/v{api-version}/defaults' + }); +}; + +export const callToTestOrderOfParams = (options: Options) => { + return (options?.client ?? client).put({ + ...options, + url: '/api/v{api-version}/defaults' + }); +}; + +export const duplicateName = (options?: Options) => { + return (options?.client ?? client).delete({ + ...options, + url: '/api/v{api-version}/duplicate' + }); +}; + +export const duplicateName2 = (options?: Options) => { + return (options?.client ?? client).get({ + ...options, + url: '/api/v{api-version}/duplicate' + }); +}; + +export const duplicateName3 = (options?: Options) => { + return (options?.client ?? client).post({ + ...options, + url: '/api/v{api-version}/duplicate' + }); +}; + +export const duplicateName4 = (options?: Options) => { + return (options?.client ?? client).put({ + ...options, + url: '/api/v{api-version}/duplicate' + }); +}; + +export const callWithNoContentResponse = (options?: Options) => { + return (options?.client ?? client).get({ + ...options, + url: '/api/v{api-version}/no-content' + }); +}; + +export const callWithResponseAndNoContentResponse = (options?: Options) => { + return (options?.client ?? client).get({ + ...options, + url: '/api/v{api-version}/multiple-tags/response-and-no-content' + }); +}; + +export const dummyA = (options?: Options) => { + return (options?.client ?? client).get({ + ...options, + url: '/api/v{api-version}/multiple-tags/a' + }); +}; + +export const dummyB = (options?: Options) => { + return (options?.client ?? client).get({ + ...options, + url: '/api/v{api-version}/multiple-tags/b' + }); +}; + +export const callWithResponse = (options?: Options) => { + return (options?.client ?? client).get({ + ...options, + url: '/api/v{api-version}/response' + }); +}; + +export const callWithDuplicateResponses = (options?: Options) => { + return (options?.client ?? client).post({ + ...options, + url: '/api/v{api-version}/response' + }); +}; + +export const callWithResponses = (options?: Options) => { + return (options?.client ?? client).put({ + ...options, + url: '/api/v{api-version}/response' + }); +}; + +export const collectionFormat = (options: Options) => { + return (options?.client ?? client).get({ + ...options, + url: '/api/v{api-version}/collectionFormat' + }); +}; + +export const types = (options: Options) => { + return (options?.client ?? client).get({ + ...options, + url: '/api/v{api-version}/types' + }); +}; + +export const uploadFile = (options: Options) => { + return (options?.client ?? client).post({ + ...options, + ...urlSearchParamsBodySerializer, + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + ...options?.headers + }, + url: '/api/v{api-version}/upload' + }); +}; + +export const fileResponse = (options: Options) => { + return (options?.client ?? client).get({ + ...options, + url: '/api/v{api-version}/file/{id}' + }); +}; + +export const complexTypes = (options: Options) => { + return (options?.client ?? client).get({ + ...options, + url: '/api/v{api-version}/complex' + }); +}; + +export const multipartResponse = (options?: Options) => { + return (options?.client ?? client).get({ + ...options, + url: '/api/v{api-version}/multipart' + }); +}; + +export const multipartRequest = (options?: Options) => { + return (options?.client ?? client).post({ + ...options, + ...formDataBodySerializer, + headers: { + 'Content-Type': null, + ...options?.headers + }, + url: '/api/v{api-version}/multipart' + }); +}; + +export const complexParams = (options: Options) => { + return (options?.client ?? client).put({ + ...options, + headers: { + 'Content-Type': 'application/json-patch+json', + ...options?.headers + }, + url: '/api/v{api-version}/complex/{id}' + }); +}; + +export const callWithResultFromHeader = (options?: Options) => { + return (options?.client ?? client).post({ + ...options, + url: '/api/v{api-version}/header' + }); +}; + +export const testErrorCode = (options: Options) => { + return (options?.client ?? client).post({ + ...options, + url: '/api/v{api-version}/error' + }); +}; + +export const nonAsciiæøåÆøÅöôêÊ字符串 = (options: Options) => { + return (options?.client ?? client).post({ + ...options, + url: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串' + }); +}; + +/** + * Login User + */ +export const putWithFormUrlEncoded = (options: Options) => { + return (options?.client ?? client).put({ + ...options, + ...urlSearchParamsBodySerializer, + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + ...options?.headers + }, + url: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串' + }); +}; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/fastify/types.gen.ts b/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/fastify/types.gen.ts new file mode 100644 index 000000000..2f6b56c07 --- /dev/null +++ b/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/fastify/types.gen.ts @@ -0,0 +1,1474 @@ +// This file is auto-generated by @hey-api/openapi-ts + +/** + * Model with number-only name + */ +export type _400 = string; + +/** + * Testing multiline comments in string: First line + * Second line + * + * Fourth line + */ +export type camelCaseCommentWithBreaks = number; + +/** + * Testing multiline comments in string: First line + * Second line + * + * Fourth line + */ +export type CommentWithBreaks = number; + +/** + * Testing backticks in string: `backticks` and ```multiple backticks``` should work + */ +export type CommentWithBackticks = number; + +/** + * Testing backticks and quotes in string: `backticks`, 'quotes', "double quotes" and ```multiple backticks``` should work + */ +export type CommentWithBackticksAndQuotes = number; + +/** + * Testing slashes in string: \backwards\\\ and /forwards/// should work + */ +export type CommentWithSlashes = number; + +/** + * Testing expression placeholders in string: ${expression} should work + */ +export type CommentWithExpressionPlaceholders = number; + +/** + * Testing quotes in string: 'single quote''' and "double quotes""" should work + */ +export type CommentWithQuotes = number; + +/** + * Testing reserved characters in string: * inline * and ** inline ** should work + */ +export type CommentWithReservedCharacters = number; + +/** + * This is a simple number + */ +export type SimpleInteger = number; + +/** + * This is a simple boolean + */ +export type SimpleBoolean = boolean; + +/** + * This is a simple string + */ +export type SimpleString = string; + +/** + * A string with non-ascii (unicode) characters valid in typescript identifiers (æøåÆØÅöÔèÈ字符串) + */ +export type NonAsciiStringæøåÆØÅöôêÊ字符串 = string; + +/** + * This is a simple file + */ +export type SimpleFile = Blob | File; + +/** + * This is a simple reference + */ +export type SimpleReference = ModelWithString; + +/** + * This is a simple string + */ +export type SimpleStringWithPattern = string | null; + +/** + * This is a simple enum with strings + */ +export type EnumWithStrings = 'Success' | 'Warning' | 'Error' | "'Single Quote'" | '"Double Quotes"' | 'Non-ascii: øæåôöØÆÅÔÖ字符串'; + +export type EnumWithReplacedCharacters = "'Single Quote'" | '"Double Quotes"' | 'øæåôöØÆÅÔÖ字符串' | 3.1 | ''; + +/** + * This is a simple enum with numbers + */ +export type EnumWithNumbers = 1 | 2 | 3 | 1.1 | 1.2 | 1.3 | 100 | 200 | 300 | -100 | -200 | -300 | -1.1 | -1.2 | -1.3; + +/** + * Success=1,Warning=2,Error=3 + */ +export type EnumFromDescription = number; + +/** + * This is a simple enum with numbers + */ +export type EnumWithExtensions = 200 | 400 | 500; + +export type EnumWithXEnumNames = 0 | 1 | 2; + +/** + * This is a simple array with numbers + */ +export type ArrayWithNumbers = Array; + +/** + * This is a simple array with booleans + */ +export type ArrayWithBooleans = Array; + +/** + * This is a simple array with strings + */ +export type ArrayWithStrings = Array; + +/** + * This is a simple array with references + */ +export type ArrayWithReferences = Array; + +/** + * This is a simple array containing an array + */ +export type ArrayWithArray = Array>; + +/** + * This is a simple array with properties + */ +export type ArrayWithProperties = Array<{ + '16x16'?: camelCaseCommentWithBreaks; + bar?: string; +}>; + +/** + * This is a simple array with any of properties + */ +export type ArrayWithAnyOfProperties = Array<{ + foo?: string; +} | { + bar?: string; +}>; + +export type AnyOfAnyAndNull = { + data?: unknown | null; +}; + +/** + * This is a simple array with any of properties + */ +export type AnyOfArrays = { + results?: Array<{ + foo?: string; + } | { + bar?: string; + }>; +}; + +/** + * This is a string dictionary + */ +export type DictionaryWithString = { + [key: string]: string; +}; + +export type DictionaryWithPropertiesAndAdditionalProperties = { + foo?: number; + bar?: boolean; + [key: string]: string | number | boolean | undefined; +}; + +/** + * This is a string reference + */ +export type DictionaryWithReference = { + [key: string]: ModelWithString; +}; + +/** + * This is a complex dictionary + */ +export type DictionaryWithArray = { + [key: string]: Array; +}; + +/** + * This is a string dictionary + */ +export type DictionaryWithDictionary = { + [key: string]: { + [key: string]: string; + }; +}; + +/** + * This is a complex dictionary + */ +export type DictionaryWithProperties = { + [key: string]: { + foo?: string; + bar?: string; + }; +}; + +/** + * This is a model with one number property + */ +export type ModelWithInteger = { + /** + * This is a simple number property + */ + prop?: number; +}; + +/** + * This is a model with one boolean property + */ +export type ModelWithBoolean = { + /** + * This is a simple boolean property + */ + prop?: boolean; +}; + +/** + * This is a model with one string property + */ +export type ModelWithString = { + /** + * This is a simple string property + */ + prop?: string; +}; + +/** + * This is a model with one string property + */ +export type ModelWithStringError = { + /** + * This is a simple string property + */ + prop?: string; +}; + +/** + * `Comment` or `VoiceComment`. The JSON object for adding voice comments to tickets is different. See [Adding voice comments to tickets](/documentation/ticketing/managing-tickets/adding-voice-comments-to-tickets) + */ +export type Model_From_Zendesk = string; + +/** + * This is a model with one string property + */ +export type ModelWithNullableString = { + /** + * This is a simple string property + */ + nullableProp1?: string | null; + /** + * This is a simple string property + */ + nullableRequiredProp1: string | null; + /** + * This is a simple string property + */ + nullableProp2?: string | null; + /** + * This is a simple string property + */ + nullableRequiredProp2: string | null; + /** + * This is a simple enum with strings + */ + 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; +}; + +/** + * This is a model with one enum + */ +export type ModelWithEnum = { + /** + * This is a simple enum with strings + */ + 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; + /** + * These are the HTTP error code enums + */ + statusCode?: '100' | '200 FOO' | '300 FOO_BAR' | '400 foo-bar' | '500 foo.bar' | '600 foo&bar'; + /** + * Simple boolean enum + */ + bool?: true; +}; + +/** + * This is a model with one enum with escaped name + */ +export type ModelWithEnumWithHyphen = { + 'foo-bar-baz-qux'?: '3.0'; +}; + +/** + * This is a model with one enum + */ +export type ModelWithEnumFromDescription = { + /** + * Success=1,Warning=2,Error=3 + */ + test?: number; +}; + +/** + * This is a model with nested enums + */ +export type ModelWithNestedEnums = { + dictionaryWithEnum?: { + [key: string]: 'Success' | 'Warning' | 'Error'; + }; + dictionaryWithEnumFromDescription?: { + [key: string]: number; + }; + arrayWithEnum?: Array<'Success' | 'Warning' | 'Error'>; + arrayWithDescription?: Array; + /** + * This is a simple enum with strings + */ + 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; +}; + +/** + * This is a model with one property containing a reference + */ +export type ModelWithReference = { + prop?: ModelWithProperties; +}; + +/** + * This is a model with one property containing an array + */ +export type ModelWithArrayReadOnlyAndWriteOnly = { + prop?: Array; + propWithFile?: Array; + propWithNumber?: Array; +}; + +/** + * This is a model with one property containing an array + */ +export type ModelWithArray = { + prop?: Array; + propWithFile?: Array; + propWithNumber?: Array; +}; + +/** + * This is a model with one property containing a dictionary + */ +export type ModelWithDictionary = { + prop?: { + [key: string]: string; + }; +}; + +/** + * This is a deprecated model with a deprecated property + * @deprecated + */ +export type DeprecatedModel = { + /** + * This is a deprecated property + * @deprecated + */ + prop?: string; +}; + +/** + * This is a model with one property containing a circular reference + */ +export type ModelWithCircularReference = { + prop?: ModelWithCircularReference; +}; + +/** + * This is a model with one property with a 'one of' relationship + */ +export type CompositionWithOneOf = { + propA?: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; +}; + +/** + * This is a model with one property with a 'one of' relationship where the options are not $ref + */ +export type CompositionWithOneOfAnonymous = { + propA?: { + propA?: string; + } | string | number; +}; + +/** + * Circle + */ +export type ModelCircle = { + kind: string; + radius?: number; +}; + +/** + * Square + */ +export type ModelSquare = { + kind: string; + sideLength?: number; +}; + +/** + * This is a model with one property with a 'one of' relationship where the options are not $ref + */ +export type CompositionWithOneOfDiscriminator = ({ + kind?: 'circle'; +} & ModelCircle) | ({ + kind?: 'square'; +} & ModelSquare); + +/** + * This is a model with one property with a 'any of' relationship + */ +export type CompositionWithAnyOf = { + propA?: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; +}; + +/** + * This is a model with one property with a 'any of' relationship where the options are not $ref + */ +export type CompositionWithAnyOfAnonymous = { + propA?: { + propA?: string; + } | string | number; +}; + +/** + * This is a model with nested 'any of' property with a type null + */ +export type CompositionWithNestedAnyAndTypeNull = { + propA?: Array | Array; +}; + +export type _3e_num_1Период = 'Bird' | 'Dog'; + +export type ConstValue = 'ConstValue'; + +/** + * This is a model with one property with a 'any of' relationship where the options are not $ref + */ +export type CompositionWithNestedAnyOfAndNull = { + propA?: Array<_3e_num_1Период | ConstValue> | null; +}; + +/** + * This is a model with one property with a 'one of' relationship + */ +export type CompositionWithOneOfAndNullable = { + propA?: { + boolean?: boolean; + } | ModelWithEnum | ModelWithArray | ModelWithDictionary | null; +}; + +/** + * This is a model that contains a simple dictionary within composition + */ +export type CompositionWithOneOfAndSimpleDictionary = { + propA?: boolean | { + [key: string]: number; + }; +}; + +/** + * This is a model that contains a dictionary of simple arrays within composition + */ +export type CompositionWithOneOfAndSimpleArrayDictionary = { + propA?: boolean | { + [key: string]: Array; + }; +}; + +/** + * This is a model that contains a dictionary of complex arrays (composited) within composition + */ +export type CompositionWithOneOfAndComplexArrayDictionary = { + propA?: boolean | { + [key: string]: Array; + }; +}; + +/** + * This is a model with one property with a 'all of' relationship + */ +export type CompositionWithAllOfAndNullable = { + propA?: ({ + boolean?: boolean; + } & ModelWithEnum & ModelWithArray & ModelWithDictionary) | null; +}; + +/** + * This is a model with one property with a 'any of' relationship + */ +export type CompositionWithAnyOfAndNullable = { + propA?: { + boolean?: boolean; + } | ModelWithEnum | ModelWithArray | ModelWithDictionary | null; +}; + +/** + * This is a base model with two simple optional properties + */ +export type CompositionBaseModel = { + firstName?: string; + lastname?: string; +}; + +/** + * This is a model that extends the base model + */ +export type CompositionExtendedModel = CompositionBaseModel & { + age: number; + firstName: string; + lastname: string; +}; + +/** + * This is a model with one nested property + */ +export type ModelWithProperties = { + required: string; + readonly requiredAndReadOnly: string; + requiredAndNullable: string | null; + string?: string; + number?: number; + boolean?: boolean; + reference?: ModelWithString; + 'property with space'?: string; + default?: string; + try?: string; + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; +}; + +/** + * This is a model with one nested property + */ +export type ModelWithNestedProperties = { + readonly first: { + readonly second: { + readonly third: string | null; + } | null; + } | null; +}; + +/** + * This is a model with duplicated properties + */ +export type ModelWithDuplicateProperties = { + prop?: ModelWithString; +}; + +/** + * This is a model with ordered properties + */ +export type ModelWithOrderedProperties = { + zebra?: string; + apple?: string; + hawaii?: string; +}; + +/** + * This is a model with duplicated imports + */ +export type ModelWithDuplicateImports = { + propA?: ModelWithString; + propB?: ModelWithString; + propC?: ModelWithString; +}; + +/** + * This is a model that extends another model + */ +export type ModelThatExtends = ModelWithString & { + propExtendsA?: string; + propExtendsB?: ModelWithString; +}; + +/** + * This is a model that extends another model + */ +export type ModelThatExtendsExtends = ModelWithString & ModelThatExtends & { + propExtendsC?: string; + propExtendsD?: ModelWithString; +}; + +/** + * This is a model that contains a some patterns + */ +export type ModelWithPattern = { + key: string; + name: string; + readonly enabled?: boolean; + readonly modified?: string; + id?: string; + text?: string; + patternWithSingleQuotes?: string; + patternWithNewline?: string; + patternWithBacktick?: string; +}; + +export type File = { + readonly id?: string; + readonly updated_at?: string; + readonly created_at?: string; + mime: string; + readonly file?: string; +}; + +export type _default = { + name?: string; +}; + +export type Pageable = { + page?: number; + size?: number; + sort?: Array; +}; + +/** + * This is a free-form object without additionalProperties. + */ +export type FreeFormObjectWithoutAdditionalProperties = {}; + +/** + * This is a free-form object with additionalProperties: true. + */ +export type FreeFormObjectWithAdditionalPropertiesEqTrue = { + [key: string]: unknown; +}; + +/** + * This is a free-form object with additionalProperties: {}. + */ +export type FreeFormObjectWithAdditionalPropertiesEqEmptyObject = {}; + +export type ModelWithConst = { + String?: 'String'; + number?: 0; + null?: null; + withType?: 'Some string'; +}; + +/** + * This is a model with one property and additionalProperties: true + */ +export type ModelWithAdditionalPropertiesEqTrue = { + /** + * This is a simple string property + */ + prop?: string; + [key: string]: unknown | string | undefined; +}; + +export type NestedAnyOfArraysNullable = { + nullableArray?: Array | null; +}; + +export type CompositionWithOneOfAndProperties = ({ + foo: SimpleParameter; +} | { + bar: NonAsciiStringæøåÆØÅöôêÊ字符串; +}) & { + baz: number | null; + qux: number; +}; + +/** + * An object that can be null + */ +export type NullableObject = { + foo?: string; +} | null; + +/** + * Some % character + */ +export type CharactersInDescription = string; + +export type ModelWithNullableObject = { + data?: NullableObject; +}; + +export type ModelWithOneOfEnum = { + foo: 'Bar'; +} | { + foo: 'Baz'; +} | { + foo: 'Qux'; +} | { + content: string; + foo: 'Quux'; +} | { + content: [ + string, + string + ]; + foo: 'Corge'; +}; + +export type ModelWithNestedArrayEnumsDataFoo = 'foo' | 'bar'; + +export type ModelWithNestedArrayEnumsDataBar = 'baz' | 'qux'; + +export type ModelWithNestedArrayEnumsData = { + foo?: Array; + bar?: Array; +}; + +export type ModelWithNestedArrayEnums = { + array_strings?: Array; + data?: ModelWithNestedArrayEnumsData; +}; + +export type ModelWithNestedCompositionEnums = { + foo?: ModelWithNestedArrayEnumsDataFoo; +}; + +export type ModelWithReadOnlyAndWriteOnly = { + foo: string; + readonly bar: string; + baz: string; +}; + +export type ModelWithConstantSizeArray = [ + number, + number +]; + +export type ModelWithAnyOfConstantSizeArray = [ + number | string, + number | string, + number | string +]; + +export type ModelWithPrefixItemsConstantSizeArray = [ + ModelWithInteger, + number | string, + string +]; + +export type ModelWithAnyOfConstantSizeArrayNullable = [ + number | null | string, + number | null | string, + number | null | string +]; + +export type ModelWithAnyOfConstantSizeArrayWithNSizeAndOptions = [ + number | _import, + number | _import +]; + +export type ModelWithAnyOfConstantSizeArrayAndIntersect = [ + number & string, + number & string +]; + +export type ModelWithNumericEnumUnion = { + /** + * Период + */ + value?: -10 | -1 | 0 | 1 | 3 | 6 | 12; +}; + +/** + * Some description with `back ticks` + */ +export type ModelWithBackticksInDescription = { + /** + * The template `that` should be used for parsing and importing the contents of the CSV file. + * + *

There is one placeholder currently supported:

  • ${x} - refers to the n-th column in the CSV file, e.g. ${1}, ${2}, ...)

Example of a correct JSON template:

+ *
+     * [
+     * {
+     * "resourceType": "Asset",
+     * "identifier": {
+     * "name": "${1}",
+     * "domain": {
+     * "name": "${2}",
+     * "community": {
+     * "name": "Some Community"
+     * }
+     * }
+     * },
+     * "attributes" : {
+     * "00000000-0000-0000-0000-000000003115" : [ {
+     * "value" : "${3}"
+     * } ],
+     * "00000000-0000-0000-0000-000000000222" : [ {
+     * "value" : "${4}"
+     * } ]
+     * }
+     * }
+     * ]
+     * 
+ */ + template?: string; +}; + +export type ModelWithOneOfAndProperties = (SimpleParameter | NonAsciiStringæøåÆØÅöôêÊ字符串) & { + baz: number | null; + qux: number; +}; + +/** + * Model used to test deduplication strategy (unused) + */ +export type ParameterSimpleParameterUnused = string; + +/** + * Model used to test deduplication strategy + */ +export type PostServiceWithEmptyTagResponse = string; + +/** + * Model used to test deduplication strategy + */ +export type PostServiceWithEmptyTagResponse2 = string; + +/** + * Model used to test deduplication strategy + */ +export type DeleteFooData = string; + +/** + * Model used to test deduplication strategy + */ +export type DeleteFooData2 = string; + +/** + * Model with restricted keyword name + */ +export type _import = string; + +export type SchemaWithFormRestrictedKeys = { + description?: string; + 'x-enum-descriptions'?: string; + 'x-enum-varnames'?: string; + 'x-enumNames'?: string; + title?: string; + object?: { + description?: string; + 'x-enum-descriptions'?: string; + 'x-enum-varnames'?: string; + 'x-enumNames'?: string; + title?: string; + }; + array?: Array<{ + description?: string; + 'x-enum-descriptions'?: string; + 'x-enum-varnames'?: string; + 'x-enumNames'?: string; + title?: string; + }>; +}; + +/** + * This schema was giving PascalCase transformations a hard time + */ +export type io_k8s_apimachinery_pkg_apis_meta_v1_DeleteOptions = { + /** + * Must be fulfilled before a deletion is carried out. If not possible, a 409 Conflict status will be returned. + */ + preconditions?: io_k8s_apimachinery_pkg_apis_meta_v1_Preconditions; +}; + +/** + * This schema was giving PascalCase transformations a hard time + */ +export type io_k8s_apimachinery_pkg_apis_meta_v1_Preconditions = { + /** + * Specifies the target ResourceVersion + */ + resourceVersion?: string; + /** + * Specifies the target UID. + */ + uid?: string; +}; + +export type AdditionalPropertiesUnknownIssue = { + [key: string]: string | number; +}; + +export type AdditionalPropertiesUnknownIssue2 = { + [key: string]: string | number; +}; + +export type AdditionalPropertiesUnknownIssue3 = string & { + entries: { + [key: string]: AdditionalPropertiesUnknownIssue; + }; +}; + +export type AdditionalPropertiesIntegerIssue = { + value: number; + [key: string]: number; +}; + +export type OneOfAllOfIssue = ((ConstValue | Generic_Schema_Duplicate_Issue_1_System_Boolean_) & _3e_num_1Период) | Generic_Schema_Duplicate_Issue_1_System_String_; + +export type Generic_Schema_Duplicate_Issue_1_System_Boolean_ = { + item?: boolean; + error?: string | null; + readonly hasError?: boolean; + data?: { + [key: string]: never; + }; +}; + +export type Generic_Schema_Duplicate_Issue_1_System_String_ = { + item?: string | null; + error?: string | null; + readonly hasError?: boolean; +}; + +/** + * This is a reusable parameter + */ +export type SimpleParameter = string; + +/** + * Parameter with illegal characters + */ +export type x_Foo_Bar = ModelWithString; + +export type ImportData = { + body: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; +}; + +export type ImportResponse = Model_From_Zendesk | ModelWithReadOnlyAndWriteOnly; + +export type ApiVversionOdataControllerCountResponse = Model_From_Zendesk; + +export type GetApiVbyApiVersionSimpleOperationData = { + body?: never; + path: { + /** + * foo in method + */ + foo_param: string; + }; + query?: never; +}; + +export type GetApiVbyApiVersionSimpleOperationError = ModelWithBoolean; + +export type GetApiVbyApiVersionSimpleOperationResponse = number; + +export type DeleteFooData3 = { + body?: never; + headers: { + /** + * Parameter with illegal characters + */ + 'x-Foo-Bar': ModelWithString; + }; + path: { + /** + * foo in method + */ + foo_param: string; + /** + * bar in method + */ + BarParam: string; + }; + query?: never; +}; + +export type CallWithDescriptionsData = { + body?: never; + path?: never; + query?: { + /** + * Testing multiline comments in string: First line + * Second line + * + * Fourth line + */ + parameterWithBreaks?: string; + /** + * Testing backticks in string: `backticks` and ```multiple backticks``` should work + */ + parameterWithBackticks?: string; + /** + * Testing slashes in string: \backwards\\\ and /forwards/// should work + */ + parameterWithSlashes?: string; + /** + * Testing expression placeholders in string: ${expression} should work + */ + parameterWithExpressionPlaceholders?: string; + /** + * Testing quotes in string: 'single quote''' and "double quotes""" should work + */ + parameterWithQuotes?: string; + /** + * Testing reserved characters in string: * inline * and ** inline ** should work + */ + parameterWithReservedCharacters?: string; + }; +}; + +export type DeprecatedCallData = { + body?: never; + headers: { + /** + * This parameter is deprecated + * @deprecated + */ + parameter: DeprecatedModel | null; + }; + path?: never; + query?: never; +}; + +export type CallWithParametersData = { + /** + * This is the parameter that goes into the body + */ + body: {} | null; + headers: { + /** + * This is the parameter that goes into the header + */ + parameterHeader: string | null; + }; + path: { + /** + * This is the parameter that goes into the path + */ + parameterPath: string | null; + /** + * api-version should be required in standalone clients + */ + 'api-version': string | null; + }; + query: { + foo_ref_enum?: ModelWithNestedArrayEnumsDataFoo; + foo_all_of_enum: ModelWithNestedArrayEnumsDataFoo; + /** + * This is the parameter that goes into the query params + */ + cursor: string | null; + }; +}; + +export type CallWithWeirdParameterNamesData = { + /** + * This is the parameter that goes into the body + */ + body: ModelWithString | null; + headers: { + /** + * This is the parameter that goes into the request header + */ + 'parameter.header': string | null; + }; + path: { + /** + * This is the parameter that goes into the path + */ + 'parameter.path.1'?: string; + /** + * This is the parameter that goes into the path + */ + 'parameter-path-2'?: string; + /** + * This is the parameter that goes into the path + */ + 'PARAMETER-PATH-3'?: string; + /** + * api-version should be required in standalone clients + */ + 'api-version': string | null; + }; + query: { + /** + * This is the parameter with a reserved keyword + */ + default?: string; + /** + * This is the parameter that goes into the request query params + */ + 'parameter-query': string | null; + }; +}; + +export type GetCallWithOptionalParamData = { + /** + * This is a required parameter + */ + body: ModelWithOneOfEnum; + path?: never; + query?: { + /** + * This is an optional parameter + */ + page?: number; + }; +}; + +export type PostCallWithOptionalParamData = { + /** + * This is an optional parameter + */ + body?: { + offset?: number | null; + }; + path?: never; + query: { + /** + * This is a required parameter + */ + parameter: Pageable; + }; +}; + +export type PostCallWithOptionalParamResponse = number | void; + +export type PostApiVbyApiVersionRequestBodyData = { + /** + * A reusable request body + */ + body?: ModelWithString; + path?: never; + query?: { + /** + * This is a reusable parameter + */ + parameter?: string; + }; +}; + +export type PostApiVbyApiVersionFormDataData = { + /** + * A reusable request body + */ + body?: ModelWithString; + path?: never; + query?: { + /** + * This is a reusable parameter + */ + parameter?: string; + }; +}; + +export type CallWithDefaultParametersData = { + body?: never; + path?: never; + query?: { + /** + * This is a simple string with default value + */ + parameterString?: string | null; + /** + * This is a simple number with default value + */ + parameterNumber?: number | null; + /** + * This is a simple boolean with default value + */ + parameterBoolean?: boolean | null; + /** + * This is a simple enum with default value + */ + parameterEnum?: 'Success' | 'Warning' | 'Error'; + /** + * This is a simple model with default value + */ + parameterModel?: ModelWithString | null; + }; +}; + +export type CallWithDefaultOptionalParametersData = { + body?: never; + path?: never; + query?: { + /** + * This is a simple string that is optional with default value + */ + parameterString?: string; + /** + * This is a simple number that is optional with default value + */ + parameterNumber?: number; + /** + * This is a simple boolean that is optional with default value + */ + parameterBoolean?: boolean; + /** + * This is a simple enum that is optional with default value + */ + parameterEnum?: 'Success' | 'Warning' | 'Error'; + /** + * This is a simple model that is optional with default value + */ + parameterModel?: ModelWithString; + }; +}; + +export type CallToTestOrderOfParamsData = { + body?: never; + path?: never; + query: { + /** + * This is a optional string with default + */ + parameterOptionalStringWithDefault?: string; + /** + * This is a optional string with empty default + */ + parameterOptionalStringWithEmptyDefault?: string; + /** + * This is a optional string with no default + */ + parameterOptionalStringWithNoDefault?: string; + /** + * This is a string with default + */ + parameterStringWithDefault: string; + /** + * This is a string with empty default + */ + parameterStringWithEmptyDefault: string; + /** + * This is a string with no default + */ + parameterStringWithNoDefault: string; + /** + * This is a string that can be null with no default + */ + parameterStringNullableWithNoDefault?: string | null; + /** + * This is a string that can be null with default + */ + parameterStringNullableWithDefault?: string | null; + }; +}; + +export type CallWithNoContentResponseResponse = void; + +export type CallWithResponseAndNoContentResponseResponse = number | void; + +export type DummyAResponse = _400; + +export type DummyBResponse = void; + +export type CallWithResponseResponse = _import; + +export type CallWithDuplicateResponsesError = ModelWithStringError | DictionaryWithArray | ModelWithBoolean; + +export type CallWithDuplicateResponsesResponse = (ModelWithBoolean & ModelWithInteger) | ModelWithString; + +export type CallWithResponsesError = ModelWithStringError; + +export type CallWithResponsesResponse = { + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; + readonly value?: Array; +} | ModelThatExtends | ModelThatExtendsExtends; + +export type CollectionFormatData = { + body?: never; + path?: never; + query: { + /** + * This is an array parameter that is sent as csv format (comma-separated values) + */ + parameterArrayCSV: Array | null; + /** + * This is an array parameter that is sent as ssv format (space-separated values) + */ + parameterArraySSV: Array | null; + /** + * This is an array parameter that is sent as tsv format (tab-separated values) + */ + parameterArrayTSV: Array | null; + /** + * This is an array parameter that is sent as pipes format (pipe-separated values) + */ + parameterArrayPipes: Array | null; + /** + * This is an array parameter that is sent as multi format (multiple parameter instances) + */ + parameterArrayMulti: Array | null; + }; +}; + +export type TypesData = { + body?: never; + path?: { + /** + * This is a number parameter + */ + id?: number; + }; + query: { + /** + * This is a number parameter + */ + parameterNumber: number; + /** + * This is a string parameter + */ + parameterString: string | null; + /** + * This is a boolean parameter + */ + parameterBoolean: boolean | null; + /** + * This is an object parameter + */ + parameterObject: {} | null; + /** + * This is an array parameter + */ + parameterArray: Array | null; + /** + * This is a dictionary parameter + */ + parameterDictionary: {} | null; + /** + * This is an enum parameter + */ + parameterEnum: 'Success' | 'Warning' | 'Error' | null; + }; +}; + +export type TypesResponse = number | string | boolean | {}; + +export type UploadFileData = { + body: Blob | File; + path: { + /** + * api-version should be required in standalone clients + */ + 'api-version': string | null; + }; + query?: never; +}; + +export type UploadFileResponse = boolean; + +export type FileResponseData = { + body?: never; + path: { + id: string; + /** + * api-version should be required in standalone clients + */ + 'api-version': string; + }; + query?: never; +}; + +export type FileResponseResponse = Blob | File; + +export type ComplexTypesData = { + body?: never; + path?: never; + query: { + /** + * Parameter containing object + */ + parameterObject: { + first?: { + second?: { + third?: string; + }; + }; + }; + /** + * Parameter containing reference + */ + parameterReference: ModelWithString; + }; +}; + +export type ComplexTypesResponse = Array; + +export type MultipartResponseResponse = { + file?: Blob | File; + metadata?: { + foo?: string; + bar?: string; + }; +}; + +export type MultipartRequestData = { + body?: { + content?: Blob | File; + data?: ModelWithString | null; + }; +}; + +export type ComplexParamsData = { + body?: { + readonly key: string | null; + name: string | null; + enabled?: boolean; + type: 'Monkey' | 'Horse' | 'Bird'; + listOfModels?: Array | null; + listOfStrings?: Array | null; + parameters: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; + readonly user?: { + readonly id?: number; + readonly name?: string | null; + }; + }; + path: { + id: number; + /** + * api-version should be required in standalone clients + */ + 'api-version': string; + }; + query?: never; +}; + +export type ComplexParamsResponse = ModelWithString; + +export type TestErrorCodeData = { + body?: never; + path?: never; + query: { + /** + * Status code to return + */ + status: number; + }; +}; + +export type NonAsciiæøåÆøÅöôêÊ字符串Data = { + body?: never; + path?: never; + query: { + /** + * Dummy input param + */ + nonAsciiParamæøåÆØÅöôêÊ: number; + }; +}; + +export type NonAsciiæøåÆøÅöôêÊ字符串Response = Array; + +export type PutWithFormUrlEncodedData = { + body: ArrayWithStrings; +}; \ No newline at end of file diff --git a/packages/openapi-ts/test/plugins.spec.ts b/packages/openapi-ts/test/plugins.spec.ts index 40e229c1b..590e42512 100644 --- a/packages/openapi-ts/test/plugins.spec.ts +++ b/packages/openapi-ts/test/plugins.spec.ts @@ -202,6 +202,13 @@ for (const version of versions) { }), description: 'generate services', }, + { + config: createConfig({ + output: '.', + plugins: ['fastify'], + }), + description: 'generate Fastify types with Fastify plugin', + }, ]; it.each(scenarios)('$description', async ({ config }) => { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f210c960d..9ba491f32 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -149,6 +149,25 @@ importers: specifier: 5.4.6 version: 5.4.6(@types/node@22.8.5)(less@4.2.0)(sass@1.77.6)(terser@5.31.6) + examples/openapi-ts-fastify: + dependencies: + '@hey-api/openapi-ts': + specifier: workspace:* + version: link:../../packages/openapi-ts + fastify: + specifier: 5.0.0 + version: 5.0.0 + fastify-openapi-glue: + specifier: 4.7.1 + version: 4.7.1 + devDependencies: + '@hey-api/client-fetch': + specifier: workspace:* + version: link:../../packages/client-fetch + vitest: + specifier: 2.1.5 + version: 2.1.5(@types/node@22.8.5)(jsdom@24.1.0)(less@4.2.0)(sass@1.77.6)(terser@5.31.6) + examples/openapi-ts-fetch: dependencies: '@hey-api/client-fetch': @@ -632,6 +651,9 @@ importers: express: specifier: 4.21.0 version: 4.21.0 + fastify: + specifier: 5.0.0 + version: 5.0.0 glob: specifier: 10.4.3 version: 10.4.3 @@ -2225,6 +2247,18 @@ packages: resolution: {integrity: sha512-BsWiH1yFGjXXS2yvrf5LyuoSIIbPrGUWob917o+BTKuZ7qJdxX8aJLRxs1fS9n6r7vESrq1OUqb68dANcFXuQQ==} engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} + '@fastify/ajv-compiler@4.0.1': + resolution: {integrity: sha512-DxrBdgsjNLP0YM6W5Hd6/Fmj43S8zMKiFJYgi+Ri3htTGAowPVG/tG1wpnWLMjufEnehRivUCKZ1pLDIoZdTuw==} + + '@fastify/error@4.0.0': + resolution: {integrity: sha512-OO/SA8As24JtT1usTUTKgGH7uLvhfwZPwlptRi2Dp5P4KKmJI3gvsZ8MIHnNwDs4sLf/aai5LzTyl66xr7qMxA==} + + '@fastify/fast-json-stringify-compiler@5.0.1': + resolution: {integrity: sha512-f2d3JExJgFE3UbdFcpPwqNUEoHWmt8pAKf8f+9YuLESdefA0WgqxeT6DrGL4Yrf/9ihXNSKOqpjEmurV405meA==} + + '@fastify/merge-json-schemas@0.1.1': + resolution: {integrity: sha512-fERDVz7topgNjtXsJTTW1JKLy0rhuLRcquYqNR9rF7OcVpCa2OVW49ZPDIhaRRCaUuvVxI+N416xUoF76HNSXA==} + '@floating-ui/core@1.6.2': resolution: {integrity: sha512-+2XpQV9LLZeanU4ZevzRnGFg2neDeKHgFLjP6YLW+tly0IvrhqT4u8enLGjLH3qeh85g19xY5rsAusfwTdn5lg==} @@ -3347,6 +3381,10 @@ packages: resolution: {integrity: sha512-jT54mc9+hPOwie9bji/g2krVuK1kkNh2PNFGwfgCg3Ofmt3hcyOBai1DKuot5uLTX4VCCbvfwiVR/hJniQl2SA==} engines: {node: ^18.19.1 || ^20.11.1 || >=22.0.0, npm: ^6.11.0 || ^7.5.6 || >=8.0.0, yarn: '>= 1.13.0'} + '@seriousme/openapi-schema-validator@2.2.5': + resolution: {integrity: sha512-WQJjr03X6PLw8TOC4vTHqPl9ihtpY17jaVBJ6Yt/lHrGabUYP+BTq4yM9AbfDLP5C7v6+sfF2OJsET/W7QvKQw==} + hasBin: true + '@shikijs/core@1.10.3': resolution: {integrity: sha512-D45PMaBaeDHxww+EkcDQtDAtzv00Gcsp72ukBtaLSmqRvh0WgGMq3Al0rl1QQBZfuneO75NXMIzEZGFitThWbg==} @@ -3842,30 +3880,59 @@ packages: '@vitest/expect@2.0.0': resolution: {integrity: sha512-5BSfZ0+dAVmC6uPF7s+TcKx0i7oyYHb1WQQL5gg6G2c+Qkaa5BNrdRM74sxDfUIZUgYCr6bfCqmJp+X5bfcNxQ==} + '@vitest/expect@2.1.5': + resolution: {integrity: sha512-nZSBTW1XIdpZvEJyoP/Sy8fUg0b8od7ZpGDkTUcfJ7wz/VoZAFzFfLyxVxGFhUjJzhYqSbIpfMtl/+k/dpWa3Q==} + + '@vitest/mocker@2.1.5': + resolution: {integrity: sha512-XYW6l3UuBmitWqSUXTNXcVBUCRytDogBsWuNXQijc00dtnU/9OqpXWp4OJroVrad/gLIomAq9aW8yWDBtMthhQ==} + peerDependencies: + msw: ^2.4.9 + vite: ^5.0.0 + peerDependenciesMeta: + msw: + optional: true + vite: + optional: true + + '@vitest/pretty-format@2.1.5': + resolution: {integrity: sha512-4ZOwtk2bqG5Y6xRGHcveZVr+6txkH7M2e+nPFd6guSoN638v/1XQ0K06eOpi0ptVU/2tW/pIU4IoPotY/GZ9fw==} + '@vitest/runner@1.6.0': resolution: {integrity: sha512-P4xgwPjwesuBiHisAVz/LSSZtDjOTPYZVmNAnpHHSR6ONrf8eCJOFRvUwdHn30F5M1fxhqtl7QZQUk2dprIXAg==} '@vitest/runner@2.0.0': resolution: {integrity: sha512-OovFmlkfRmdhevbWImBUtn9IEM+CKac8O+m9p6W9jTATGVBnDJQ6/jb1gpHyWxsu0ALi5f+TLi+Uyst7AAimMw==} + '@vitest/runner@2.1.5': + resolution: {integrity: sha512-pKHKy3uaUdh7X6p1pxOkgkVAFW7r2I818vHDthYLvUyjRfkKOU6P45PztOch4DZarWQne+VOaIMwA/erSSpB9g==} + '@vitest/snapshot@1.6.0': resolution: {integrity: sha512-+Hx43f8Chus+DCmygqqfetcAZrDJwvTj0ymqjQq4CvmpKFSTVteEOBzCusu1x2tt4OJcvBflyHUE0DZSLgEMtQ==} '@vitest/snapshot@2.0.0': resolution: {integrity: sha512-B520cSAQwtWgocPpARadnNLslHCxFs5tf7SG2TT96qz+SZgsXqcB1xI3w3/S9kUzdqykEKrMLvW+sIIpMcuUdw==} + '@vitest/snapshot@2.1.5': + resolution: {integrity: sha512-zmYw47mhfdfnYbuhkQvkkzYroXUumrwWDGlMjpdUr4jBd3HZiV2w7CQHj+z7AAS4VOtWxI4Zt4bWt4/sKcoIjg==} + '@vitest/spy@1.6.0': resolution: {integrity: sha512-leUTap6B/cqi/bQkXUu6bQV5TZPx7pmMBKBQiI0rJA8c3pB56ZsaTbREnF7CJfmvAS4V2cXIBAh/3rVwrrCYgw==} '@vitest/spy@2.0.0': resolution: {integrity: sha512-0g7ho4wBK09wq8iNZFtUcQZcUcbPmbLWFotL0GXel0fvk5yPi4nTEKpIvZ+wA5eRyqPUCIfIUl10AWzLr67cmA==} + '@vitest/spy@2.1.5': + resolution: {integrity: sha512-aWZF3P0r3w6DiYTVskOYuhBc7EMc3jvn1TkBg8ttylFFRqNN2XGD7V5a4aQdk6QiUzZQ4klNBSpCLJgWNdIiNw==} + '@vitest/utils@1.6.0': resolution: {integrity: sha512-21cPiuGMoMZwiOHa2i4LXkMkMkCGzA+MVFV70jRwHo95dL4x/ts5GZhML1QWuy7yfp3WzK3lRvZi3JnXTYqrBw==} '@vitest/utils@2.0.0': resolution: {integrity: sha512-t0jbx8VugWEP6A29NbyfQKVU68Vo6oUw0iX3a8BwO3nrZuivfHcFO4Y5UsqXlplX+83P9UaqEvC2YQhspC0JSA==} + '@vitest/utils@2.1.5': + resolution: {integrity: sha512-yfj6Yrp0Vesw2cwJbP+cl04OC+IHFsuQsrsJBL9pyGeQXE56v1UAOQco+SR55Vf1nQzfV0QJg1Qum7AaWUwwYg==} + '@volar/language-core@2.4.0-alpha.18': resolution: {integrity: sha512-JAYeJvYQQROmVRtSBIczaPjP3DX4QW1fOqW1Ebs0d3Y3EwSNRglz03dSv0Dm61dzd0Yx3WgTW3hndDnTQqgmyg==} @@ -4114,6 +4181,9 @@ packages: resolution: {integrity: sha512-6/mh1E2u2YgEsCHdY0Yx5oW+61gZU+1vXaoiHHrpKeuRNNgFvS+/jrwHiQhB5apAf5oB7UB7E19ol2R2LKH8hQ==} engines: {node: ^14.17.0 || ^16.13.0 || >=18.0.0} + abstract-logging@2.0.1: + resolution: {integrity: sha512-2BjRTZxTPvheOvGbBslFSYOUkr+SjPtOnrLP33f+VIWLzezQpZcqVg7ja3L4dBXmzzgwT+a029jRx5PCi3JuiA==} + accepts@1.3.8: resolution: {integrity: sha512-PYAthTa2m2VKxuvSD3DPC/Gy+U+sOA1LAuT8mkmRuvw+NACSaeXEQ+NHcVF7rONl6qcaxV3Uuemwawk+7+SJLw==} engines: {node: '>= 0.6'} @@ -4300,6 +4370,10 @@ packages: asynckit@0.4.0: resolution: {integrity: sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==} + atomic-sleep@1.0.0: + resolution: {integrity: sha512-kNOjDqAh7px0XWNI+4QbzoiR/nTkHAWNud2uvnJquD1/x5a7EQZMJT0AczqK0Qn67oY/TTQ1LbUKajZpp3I9tQ==} + engines: {node: '>=8.0.0'} + autoprefixer@10.4.19: resolution: {integrity: sha512-BaENR2+zBZ8xXhM4pUaKUxlVdxZ0EZhjvbopwnXmxRUfqDmwSpC2lAi/QXvx7NRdPCo1WKEcEF6mV64si1z4Ew==} engines: {node: ^10 || ^12 || >=14} @@ -4314,6 +4388,9 @@ packages: peerDependencies: postcss: ^8.1.0 + avvio@9.1.0: + resolution: {integrity: sha512-fYASnYi600CsH/j9EQov7lECAniYiBFiiAtBNuZYLA2leLe9qOvZzqYHFjtIj6gD2VMoMLP14834LFWvr4IfDw==} + axios@1.7.7: resolution: {integrity: sha512-S4kL7XrjgBmvdGut0sN3yJxqYzrDOnivkBiN0OFs6hLiUam3UPvswUo0kqGyhqUZGEOytHyumEdXsAkgCOUf3Q==} @@ -4510,6 +4587,10 @@ packages: resolution: {integrity: sha512-pT1ZgP8rPNqUgieVaEY+ryQr6Q4HXNg8Ei9UnLUrjN4IA7dvQC5JB+/kxVcPNDHyBcc/26CXPkbNzq3qwrOEKA==} engines: {node: '>=12'} + chai@5.1.2: + resolution: {integrity: sha512-aGtmf24DW6MLHHG5gCx4zaI3uBq3KRtxeVs0DjFH6Z0rDNbsvTxFASFvdj79pxjxZ8/5u3PIiN3IwEIQkiiuPw==} + engines: {node: '>=12'} + chalk@2.4.2: resolution: {integrity: sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==} engines: {node: '>=4'} @@ -4720,6 +4801,10 @@ packages: resolution: {integrity: sha512-yki5XnKuf750l50uGTllt6kKILY4nQ1eNIQatoXEByZ5dWgnKqbnqmTrBE5B4N7lrMJKQ2ytWMiTO2o0v6Ew/w==} engines: {node: '>= 0.6'} + cookie@1.0.1: + resolution: {integrity: sha512-Xd8lFX4LM9QEEwxQpF9J9NTUh8pmdJO0cyRJhFiDoLTk2eH8FXlRv2IFGYVadZpqI3j8fhNrSdKCeYPxiAhLXw==} + engines: {node: '>=18'} + copy-anything@2.0.6: resolution: {integrity: sha512-1j20GZTsvKNkc4BY3NpMOM8tt///wY3FpIzozTOFO2ffuZcV61nojHXVKIy3WM+7ADCy5FVhdZYHYDdgTU0yJw==} @@ -5107,6 +5192,9 @@ packages: es-module-lexer@1.5.3: resolution: {integrity: sha512-i1gCgmR9dCl6Vil6UKPI/trA69s08g/syhiDK9TG0Nf1RJjjFI+AzoWW7sPufzkgYAn861skuCwJa0pIIHYxvg==} + es-module-lexer@1.5.4: + resolution: {integrity: sha512-MVNK56NiMrOwitFB7cqDwq0CQutbw+0BvLshJSse0MUNU+y1FC3bUS/AQg7oUng+/wKrrki7JfmwtVHkVfPLlw==} + es6-promise@3.3.1: resolution: {integrity: sha512-SOp9Phqvqn7jtEUxPWdWfWoLmyt2VaJ6MpvP9Comy1MceMXqE6bxvaTu4iaxpYYPzhny28Lc+M87/c2cPK6lDg==} @@ -5328,6 +5416,10 @@ packages: resolution: {integrity: sha512-VyhnebXciFV2DESc+p6B+y0LjSm0krU4OgJN44qFAhBY0TJ+1V61tYD2+wHusZ6F9n5K+vl8k0sTy7PEfV4qpg==} engines: {node: '>=16.17'} + expect-type@1.1.0: + resolution: {integrity: sha512-bFi65yM+xZgk+u/KRIpekdSYkTB5W1pEf0Lt8Q8Msh7b+eQ7LXVtIB1Bkm4fvclDEL1b2CZkMhv2mOeF8tMdkA==} + engines: {node: '>=12.0.0'} + exponential-backoff@3.1.1: resolution: {integrity: sha512-dX7e/LHVJ6W3DE1MHWi9S1EYzDESENfLrYohG2G++ovZrYOkm4Knwa0mc1cn84xJOR4KEU0WSchhLbd0UklbHw==} @@ -5350,6 +5442,9 @@ packages: engines: {node: '>= 10.17.0'} hasBin: true + fast-decode-uri-component@1.0.1: + resolution: {integrity: sha512-WKgKWg5eUxvRZGwW8FvfbaH7AXSh2cL+3j5fMGzUMCxWBJ3dV3a7Wz8y2f/uQ0e3B6WmodD3oS54jTQ9HVTIIg==} + fast-deep-equal@3.1.3: resolution: {integrity: sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==} @@ -5366,12 +5461,36 @@ packages: fast-json-stable-stringify@2.1.0: resolution: {integrity: sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==} + fast-json-stringify@6.0.0: + resolution: {integrity: sha512-FGMKZwniMTgZh7zQp9b6XnBVxUmKVahQLQeRQHqwYmPDqDhcEKZ3BaQsxelFFI5PY7nN71OEeiL47/zUWcYe1A==} + fast-levenshtein@2.0.6: resolution: {integrity: sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw==} + fast-querystring@1.1.2: + resolution: {integrity: sha512-g6KuKWmFXc0fID8WWH0jit4g0AGBoJhCkJMb1RmbsSEUNvQ+ZC8D6CUZ+GtF8nMzSPXnhiePyyqqipzNNEnHjg==} + + fast-redact@3.5.0: + resolution: {integrity: sha512-dwsoQlS7h9hMeYUq1W++23NDcBLV4KqONnITDV9DjfS3q1SgDGVrBdvvTLUotWtPSD7asWDV9/CmsZPy8Hf70A==} + engines: {node: '>=6'} + + fast-uri@2.4.0: + resolution: {integrity: sha512-ypuAmmMKInk5q7XcepxlnUWDLWv4GFtaJqAzWKqn62IpQ3pejtr5dTVbt3vwqVaMKmkNR55sTT+CqUKIaT21BA==} + fast-uri@3.0.3: resolution: {integrity: sha512-aLrHthzCjH5He4Z2H9YZ+v6Ujb9ocRuW6ZzkJQOrTxleEijANq4v1TsaPaVG1PZcuurEzrLcWRyYBYXD5cEiaw==} + fastify-openapi-glue@4.7.1: + resolution: {integrity: sha512-vP9rVJYohzrnj60qD7feB6aaDdpE1BQgVOaVYuTHXT6ce7MHyf/oj9Wo0o6RhST7BtP7J3SET+7k+mh/ShECag==} + engines: {node: '>=14.0.0'} + hasBin: true + + fastify-plugin@4.5.1: + resolution: {integrity: sha512-stRHYGeuqpEZTL1Ef0Ovr2ltazUT9g844X5z/zEBFLG8RYlpDiOCIG+ATvYEp+/zmc7sN29mcIMp8gvYplYPIQ==} + + fastify@5.0.0: + resolution: {integrity: sha512-Qe4dU+zGOzg7vXjw4EvcuyIbNnMwTmcuOhlOrOJsgwzvjEZmsM/IeHulgJk+r46STjdJS/ZJbxO8N70ODXDMEQ==} + fastq@1.17.1: resolution: {integrity: sha512-sRVD3lWVIXWg6By68ZN7vho9a1pQcN/WBFaAAsDDFzlJjvoGx0P8z7V1t72grFJfJhu3YPZBuu25f7Kaw2jN1w==} @@ -5417,6 +5536,10 @@ packages: resolution: {integrity: sha512-9ZonPT4ZAK4a+1pUPVPZJapbi7O5qbbJPdYw/NOQWZZbVLdDTYM3A4R9z/DpAM08IDaFGsvPgiGZ82WEwUDWjg==} engines: {node: '>=14.16'} + find-my-way@9.1.0: + resolution: {integrity: sha512-Y5jIsuYR4BwWDYYQ2A/RWWE6gD8a0FMgtU+HOq1WKku+Cwdz8M1v8wcAmRXXM1/iqtoqg06v+LjAxMYbCjViMw==} + engines: {node: '>=14'} + find-up@4.1.0: resolution: {integrity: sha512-PpOwAdQ/YlXQ2vj8a3h8IipDuYRi3wceVQQGYWxNINccq40Anw7BlsEXCMbt1Zt+OLA6Fq9suIpIWD0OsnISlw==} engines: {node: '>=8'} @@ -5718,10 +5841,6 @@ packages: resolution: {integrity: sha512-7mz/721AbnJwIVbnaSv1Cz3Am0ZLT/UBwkC92VlxhXv/k/BBQfM2fXElQNC27BVGr0uwUpplYPQM9LnaBMR5NQ==} engines: {node: '>=8.0.0'} - https-proxy-agent@7.0.4: - resolution: {integrity: sha512-wlwpilI7YdjSkWaQ/7omYBMTliDcmCN8OLihO6I9B86g06lMyAoqgoDpV0XqoaPOKj+0DIdAvnsWfyAAhmimcg==} - engines: {node: '>= 14'} - https-proxy-agent@7.0.5: resolution: {integrity: sha512-1e4Wqeblerz+tMKPIq2EMGiiWW1dIjZOksyHWSUm1rmuvw/how9hBHZ38lAGj5ID4Ik6EdkOw7NmWPy6LAwalw==} engines: {node: '>= 14'} @@ -6069,6 +6188,9 @@ packages: resolution: {integrity: sha512-fi0NG4bPjCHunUJffmLd0gxssIgkNmArMvis4iNah6Owg1MCJjWhEcDLmsK6iGkJq3tHwbDkTlce70/tmXN4cQ==} engines: {node: ^14.17.0 || ^16.13.0 || >=18.0.0} + json-schema-ref-resolver@1.0.1: + resolution: {integrity: sha512-EJAj1pgHc1hxF6vo2Z3s69fMjO1INq6eGHXZ8Z6wCQeldCuwxGK9Sxf4/cScGn3FZubCVUehfWtcDM/PLteCQw==} + json-schema-traverse@0.4.1: resolution: {integrity: sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==} @@ -6177,6 +6299,9 @@ packages: webpack: optional: true + light-my-request@6.3.0: + resolution: {integrity: sha512-bWTAPJmeWQH5suJNYwG0f5cs0p6ho9e6f1Ppoxv5qMosY+s9Ir2+ZLvvHcgA7VTDop4zl/NCHhOVVqU+kd++Ow==} + lilconfig@2.1.0: resolution: {integrity: sha512-utWOt/GHzuUxnLKxB6dk81RoOeoNeHgbrXiuGk4yyF5qlRz+iIVWu56E2fqGHFrXz0QNUhLB/8nKqvRH66JKGQ==} engines: {node: '>=10'} @@ -6281,6 +6406,9 @@ packages: loupe@3.1.1: resolution: {integrity: sha512-edNu/8D5MKVfGVFRhFf8aAxiTM6Wumfz5XsaatSxlD3w4R1d/WEKUTydCdPGbl9K7QG/Ca3GnDV2sIKIpXRQcw==} + loupe@3.1.2: + resolution: {integrity: sha512-23I4pFZHmAemUnz8WZXbYRSKYj801VDaNv9ETuMh7IrMc7VuVVSo+Z9iLE3ni30+U48iDWfi30d3twAXBYmnCg==} + lru-cache@10.4.0: resolution: {integrity: sha512-bfJaPTuEiTYBu+ulDaeQ0F+uLmlfFkMgXj4cbwfuMSjgObGMzb55FMMbDvbRU0fAHZ4sLGkz2mKwcMg8Dvm8Ww==} engines: {node: '>=18'} @@ -6308,6 +6436,9 @@ packages: magic-string@0.30.11: resolution: {integrity: sha512-+Wri9p0QHMy+545hKww7YAu5NyzF8iomPL/RQazugQ9+Ez4Ic3mERMd8ZTX5rfK944j+560ZJi8iAwgak1Ac7A==} + magic-string@0.30.12: + resolution: {integrity: sha512-Ea8I3sQMVXr8JhN4z+H/d8zwo+tYDgHE9+5G4Wnrwhs0gaK9fXTKx0Tw5Xwsd/bCPTTZNRAdpyzvoeORe9LYpw==} + magicast@0.3.4: resolution: {integrity: sha512-TyDF/Pn36bBji9rWKHlZe+PZb6Mx5V8IHCSxk7X4aljM4e/vyDvZZYwHewdVaqiA0nb3ghfHU/6AUpDxWoER2Q==} @@ -6700,6 +6831,10 @@ packages: ohash@1.1.4: resolution: {integrity: sha512-FlDryZAahJmEF3VR3w1KogSEdWX3WhA5GPakFx4J81kEAiHyLMpdLLElS8n8dfNadMgAne/MywcvmogzscVt4g==} + on-exit-leak-free@2.1.2: + resolution: {integrity: sha512-0eJJY6hXLGf1udHwfNftBqH+g73EU4B504nZeKpz1sYRKafAghwxEJunB2O7rDZkL4PGfsMVnTXZ2EjibbqcsA==} + engines: {node: '>=14.0.0'} + on-finished@2.3.0: resolution: {integrity: sha512-ikqdkGAAyf/X/gPhXGvfgAytDZtDbr+bkNUJ0N9h5MI/dmdgCs3l6hoHrcUv41sRKew3jIwrp4qQDXiK99Utww==} engines: {node: '>= 0.8'} @@ -6949,6 +7084,16 @@ packages: typescript: optional: true + pino-abstract-transport@2.0.0: + resolution: {integrity: sha512-F63x5tizV6WCh4R6RHyi2Ml+M70DNRXt/+HANowMflpgGFMAym/VKm6G7ZOQRjqN7XbGxK1Lg9t6ZrtzOaivMw==} + + pino-std-serializers@7.0.0: + resolution: {integrity: sha512-e906FRY0+tV27iq4juKzSYPbUj2do2X2JX4EzSca1631EB2QJQUqGbDuERal7LCtOpxl6x3+nvo9NPZcmjkiFA==} + + pino@9.5.0: + resolution: {integrity: sha512-xSEmD4pLnV54t0NOUN16yCl7RIB1c5UUOse5HSyEXtBp+FgFQyPeDutc+Q2ZO7/22vImV7VfEjH/1zV2QuqvYw==} + hasBin: true + pirates@4.0.6: resolution: {integrity: sha512-saLsH7WeYYPiD25LDuLRRY/i+6HaPYr6G1OUlN39otzkSTxKnubR9RTxS3/Kk50s1g2JTgFwWQDQyplC5/SHZg==} engines: {node: '>= 6'} @@ -7141,6 +7286,9 @@ packages: process-nextick-args@2.0.1: resolution: {integrity: sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==} + process-warning@4.0.0: + resolution: {integrity: sha512-/MyYDxttz7DfGMMHiysAsFE4qF+pQYAA8ziO/3NcRVrQ5fSk+Mns4QZA/oRPFzvcqNoVJXQNWNAsdwBXLUkQKw==} + progress@2.0.3: resolution: {integrity: sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA==} engines: {node: '>=0.4.0'} @@ -7216,6 +7364,9 @@ packages: queue-tick@1.0.1: resolution: {integrity: sha512-kJt5qhMxoszgU/62PLP1CJytzd2NKetjSRnyuj31fDd3Rlcz3fzlFdFLD1SItunPwyqEOkca6GbV612BWfaBag==} + quick-format-unescaped@4.0.4: + resolution: {integrity: sha512-tYC1Q1hgyRuHgloV/YXs2w15unPVh8qfu/qCTfhTYamaw7fyhumKa2yGpdSo87vY32rIclj+4fWYQXUMs9EHvg==} + randombytes@2.1.0: resolution: {integrity: sha512-vYl3iOX+4CKUWuxGi9Ukhie6fsqXqS9FE2Zaic4tNFD2N2QQaXOMFbuKK4QmDHC0JO6B1Zp41J0LpT0oR68amQ==} @@ -7302,6 +7453,10 @@ packages: resolution: {integrity: sha512-yDMz9g+VaZkqBYS/ozoBJwaBhTbZo3UNYQHNRw1D3UFQB8oHB4uS/tAODO+ZLjGWmUbKnIlOWO+aaIiAxrUWHA==} engines: {node: '>= 14.16.0'} + real-require@0.2.0: + resolution: {integrity: sha512-57frrGM/OCTLqLOAh0mhVA9VBMHd+9U7Zb2THMGdBUoZVOtGbJzjxsYGDJ3A9AYYCP4hn6y1TVbaOfzWtm5GFg==} + engines: {node: '>= 12.13.0'} + reflect-metadata@0.2.2: resolution: {integrity: sha512-urBwgfrvVP/eAyXx4hluJivBKzuEbSQs9rKWCrCkbSxNv8mxPcUZKeuoF3Uy4mJl3Lwprp6yy5/39VWigZ4K6Q==} @@ -7381,6 +7536,10 @@ packages: resolution: {integrity: sha512-oMA2dcrw6u0YfxJQXm342bFKX/E4sG9rbTzO9ptUcR/e8A33cHuvStiYOwH7fszkZlZ1z/ta9AAoPk2F4qIOHA==} engines: {node: '>=18'} + ret@0.5.0: + resolution: {integrity: sha512-I1XxrZSQ+oErkRR4jYbAyEEu2I0avBvvMM5JN+6EBprOGRCs63ENqZ3vjavq8fBw2+62G5LF5XelKwuJpcvcxw==} + engines: {node: '>=10'} + retry@0.12.0: resolution: {integrity: sha512-9LkiTwjUh6rT555DtE9rTX+BKByPfrMzEAtnlEtdEwr3Nkffwiihqe2bWADg+OQRjt9gl6ICdmB/ZFDCGAtSow==} engines: {node: '>= 4'} @@ -7446,6 +7605,13 @@ packages: safe-buffer@5.2.1: resolution: {integrity: sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==} + safe-regex2@4.0.0: + resolution: {integrity: sha512-Hvjfv25jPDVr3U+4LDzBuZPPOymELG3PYcSk5hcevooo1yxxamQL/bHs/GrEPGmMoMEwRrHVGiCA1pXi97B8Ew==} + + safe-stable-stringify@2.5.0: + resolution: {integrity: sha512-b3rppTKm9T+PsVCBEOUR46GWI7fdOs00VKZ1+9c1EWDaDMvjQc6tUwuFyIprgGgTcWoVHSKrU8H31ZHA2e0RHA==} + engines: {node: '>=10'} + safer-buffer@2.1.2: resolution: {integrity: sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==} @@ -7499,6 +7665,9 @@ packages: search-insights@2.14.0: resolution: {integrity: sha512-OLN6MsPMCghDOqlCtsIsYgtsC0pnwVTyT9Mu6A3ewOj1DxvzZF6COrn2g86E/c05xbktB0XN04m/t1Z+n+fTGw==} + secure-json-parse@2.7.0: + resolution: {integrity: sha512-6aU+Rwsezw7VR8/nyvKTx8QpWH9FrcYiXXlqC4z5d5XQBDRqtbfsRjnwGyqbi3gddNtWHuEk9OANUotL26qKUw==} + select-hose@2.0.0: resolution: {integrity: sha512-mEugaLK+YfkijB4fx0e6kImuJdCIt2LxCRcbEYPqRGCs4F2ogyfZU5IAZRdjCP8JPq2AtdNoC/Dux63d9Kiryg==} @@ -7669,6 +7838,9 @@ packages: solid-js@1.8.20: resolution: {integrity: sha512-SsgaExCJ97mPm9WpAusjZ484Z8zTp8ggiueQOsrm81iAP7UaxaN+wiOgnPcJ9u6B2SQpoQ4FiDPAZBqVWi1V4g==} + sonic-boom@4.2.0: + resolution: {integrity: sha512-INb7TM37/mAcsGmc9hyyI6+QR3rR1zVRu36B0NeGXKnOOLiZOfER5SA+N7X7k3yUYRzLWafduTDvJAfDswwEww==} + sorcery@0.11.1: resolution: {integrity: sha512-o7npfeJE6wi6J9l0/5LKshFzZ2rMatRiCDwYeDQaOzqdzRJwALhX7mk/A/ecg6wjMu7wdZbmXfD2S/vpOg0bdQ==} hasBin: true @@ -7728,6 +7900,10 @@ packages: resolution: {integrity: sha512-1POYv7uv2gXoyGFpBCmpDVSNV74IfsWlDW216UPjbWufNf+bSU6GdbDsxdcxtfwb4xlI3yxzOTKClUosxARYrQ==} engines: {node: '>=0.10.0'} + split2@4.2.0: + resolution: {integrity: sha512-UcjcJOWknrNkF6PLX83qcHM6KHgVKNkV62Y8a5uYDVv9ydGQVwAHMKqHdJje1VTWpljG0WYpCDhrCdAOYH4TWg==} + engines: {node: '>= 10.x'} + sprintf-js@1.0.3: resolution: {integrity: sha512-D9cPgkvLlV3t3IzL0D0YLvGA9Ahk4PcvVwUbN0dSGr1aP0Nrt4AEnTUbuGvquEC0mA64Gqt1fzirlRs5ibXx8g==} @@ -7752,6 +7928,9 @@ packages: std-env@3.7.0: resolution: {integrity: sha512-JPbdCEQLj1w5GilpiHAx3qJvFndqybBysA3qUOnznweH4QbNYUsW/ea8QzSrnh0vNsezMMw5bcVool8lM0gwzg==} + std-env@3.8.0: + resolution: {integrity: sha512-Bc3YwwCB+OzldMxOXJIIvC6cPRWr/LxOp48CdQTOkPyk/t4JWWJbrilwBd7RJzKV8QW7tJkcgAmeuLLJugl5/w==} + streamroller@3.1.5: resolution: {integrity: sha512-KFxaM7XT+irxvdqSP1LGLgNWbYN7ay5owZ3r/8t77p+EtSUAfUgtl7be3xtqtOmGUl9K9YPO2ca8133RlTjvKw==} engines: {node: '>=8.0'} @@ -7992,6 +8171,9 @@ packages: peerDependencies: tslib: ^2 + thread-stream@3.1.0: + resolution: {integrity: sha512-OqyPZ9u96VohAyMfJykzmivOrY2wfMSf3C5TtFJVgN+Hm6aj+voFhlK+kZEIv2FBh1X6Xp3DlnCOfEQ3B2J86A==} + through@2.3.8: resolution: {integrity: sha512-w89qg7PI8wAdvX60bMDP+bFoD5Dvhm9oLheFp5O4a2QF0cSBGsBX4qZmadPMvVqlLJBBci+WqGGOAPvcDeNSVg==} @@ -8004,6 +8186,12 @@ packages: tinybench@2.8.0: resolution: {integrity: sha512-1/eK7zUnIklz4JUUlL+658n58XO2hHLQfSk1Zf2LKieUjxidN16eKFEoDEfjHc3ohofSSqK3X5yO6VGb6iW8Lw==} + tinybench@2.9.0: + resolution: {integrity: sha512-0+DUvqWMValLmha6lr4kD8iAMK1HzV0/aKnCtWb9v9641TnP/MFb7Pc2bxoxQjTXAErryXVgUOfv2YqNllqGeg==} + + tinyexec@0.3.1: + resolution: {integrity: sha512-WiCJLEECkO18gwqIp6+hJg0//p23HXp4S+gGtAKu3mI2F2/sXC4FvHvXvB0zJVVaTPhx1/tOwdbRsa1sOBIKqQ==} + tinyglobby@0.2.6: resolution: {integrity: sha512-NbBoFBpqfcgd1tCiO8Lkfdk+xrA7mlLR9zgvZcZWQQwU63XAfUePyd6wZBaU93Hqw347lHnwFzttAkemHzzz4g==} engines: {node: '>=12.0.0'} @@ -8016,6 +8204,14 @@ packages: resolution: {integrity: sha512-KIKExllK7jp3uvrNtvRBYBWBOAXSX8ZvoaD8T+7KB/QHIuoJW3Pmr60zucywjAlMb5TeXUkcs/MWeWLu0qvuAQ==} engines: {node: ^18.0.0 || >=20.0.0} + tinypool@1.0.1: + resolution: {integrity: sha512-URZYihUbRPcGv95En+sz6MfghfIc2OJ1sv/RmhWZLouPY0/8Vo80viwPvg3dlaS9fuq7fQMEfgRRK7BBZThBEA==} + engines: {node: ^18.0.0 || >=20.0.0} + + tinyrainbow@1.2.0: + resolution: {integrity: sha512-weEDEq7Z5eTHPDh4xjX789+fHfF+P8boiFB+0vbWzpbnbsEr/GRaohi/uMKxg8RZMXnl1ItAi/IUHWMsjDV7kQ==} + engines: {node: '>=14.0.0'} + tinyspy@2.2.1: resolution: {integrity: sha512-KYad6Vy5VDWV4GH3fjpseMQ/XU2BhIYP7Vzd0LG44qRWm/Yt2WCOTicFdvmgo6gWaqooMQCawTtILVQJupKu7A==} engines: {node: '>=14.0.0'} @@ -8024,6 +8220,10 @@ packages: resolution: {integrity: sha512-q5nmENpTHgiPVd1cJDDc9cVoYN5x4vCvwT3FMilvKPKneCBZAxn2YWQjDF0UMcE9k0Cay1gBiDfTMU0g+mPMQA==} engines: {node: '>=14.0.0'} + tinyspy@3.0.2: + resolution: {integrity: sha512-n1cw8k1k0x4pgA2+9XrOkFydTerNcJ1zWCO5Nn9scWHTD+5tp8dghT2x1uduQePZTZgd3Tupf+x9BxJjeJi77Q==} + engines: {node: '>=14.0.0'} + tmp@0.0.33: resolution: {integrity: sha512-jRCJlojKnZ3addtTOjdIqoRuPEKBvNXcGYqzO6zWZX8KfKEpnGY5jfggJQ3EjKuu8D4bJRr0y+cYJFmYbImXGw==} engines: {node: '>=0.6.0'} @@ -8040,6 +8240,10 @@ packages: resolution: {integrity: sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==} engines: {node: '>=8.0'} + toad-cache@3.7.0: + resolution: {integrity: sha512-/m8M+2BJUpoJdgAHoG+baCwBT+tf2VraSfkBgl0Y00qIWt41DJ8R5B8nsEw0I58YwF5IZH6z24/2TobDKnqSWw==} + engines: {node: '>=12'} + toidentifier@1.0.1: resolution: {integrity: sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==} engines: {node: '>=0.6'} @@ -8351,6 +8555,11 @@ packages: engines: {node: ^18.0.0 || >=20.0.0} hasBin: true + vite-node@2.1.5: + resolution: {integrity: sha512-rd0QIgx74q4S1Rd56XIiL2cYEdyWn13cunYBIuqh9mpmQr7gGS0IxXoP8R6OaZtNQQLyXSWbd4rXKYUbhFpK5w==} + engines: {node: ^18.0.0 || >=20.0.0} + hasBin: true + vite-plugin-inspect@0.8.5: resolution: {integrity: sha512-JvTUqsP1JNDw0lMZ5Z/r5cSj81VK2B7884LO1DC3GMBhdcjcsAnJjdWq7bzQL01Xbh+v60d3lju3g+z7eAtNew==} engines: {node: '>=14'} @@ -8473,6 +8682,31 @@ packages: jsdom: optional: true + vitest@2.1.5: + resolution: {integrity: sha512-P4ljsdpuzRTPI/kbND2sDZ4VmieerR2c9szEZpjc+98Z9ebvnXmM5+0tHEKqYZumXqlvnmfWsjeFOjXVriDG7A==} + engines: {node: ^18.0.0 || >=20.0.0} + hasBin: true + peerDependencies: + '@edge-runtime/vm': '*' + '@types/node': ^18.0.0 || >=20.0.0 + '@vitest/browser': 2.1.5 + '@vitest/ui': 2.1.5 + happy-dom: '*' + jsdom: '*' + peerDependenciesMeta: + '@edge-runtime/vm': + optional: true + '@types/node': + optional: true + '@vitest/browser': + optional: true + '@vitest/ui': + optional: true + happy-dom: + optional: true + jsdom: + optional: true + void-elements@2.0.1: resolution: {integrity: sha512-qZKX4RnBzH2ugr8Lxa7x+0V6XD9Sb/ouARtiasEQCHB1EVU4NXtmHsDDrx1dO4ne5fc3J6EW05BP1Dl0z0iung==} engines: {node: '>=0.10.0'} @@ -8956,7 +9190,7 @@ snapshots: typescript: 5.5.3 vite: 5.4.6(@types/node@22.8.5)(less@4.2.0)(sass@1.77.6)(terser@5.31.6) watchpack: 2.4.1 - webpack: 5.94.0(esbuild@0.23.1) + webpack: 5.94.0(esbuild@0.23.0) webpack-dev-middleware: 7.4.2(webpack@5.94.0(esbuild@0.23.0)) webpack-dev-server: 5.0.4(webpack@5.94.0(esbuild@0.23.0)) webpack-merge: 6.0.1 @@ -9044,7 +9278,7 @@ snapshots: typescript: 5.5.3 vite: 5.4.6(@types/node@22.8.5)(less@4.2.0)(sass@1.77.6)(terser@5.31.6) watchpack: 2.4.1 - webpack: 5.94.0(esbuild@0.23.1) + webpack: 5.94.0(esbuild@0.23.0) webpack-dev-middleware: 7.4.2(webpack@5.94.0(esbuild@0.23.0)) webpack-dev-server: 5.0.4(webpack@5.94.0(esbuild@0.23.0)) webpack-merge: 6.0.1 @@ -9075,7 +9309,7 @@ snapshots: dependencies: '@angular-devkit/architect': 0.1802.11(chokidar@3.6.0) rxjs: 7.8.1 - webpack: 5.94.0(esbuild@0.23.1) + webpack: 5.94.0(esbuild@0.23.0) webpack-dev-server: 5.0.4(webpack@5.94.0(esbuild@0.23.0)) transitivePeerDependencies: - chokidar @@ -10790,6 +11024,22 @@ snapshots: '@eslint/object-schema@2.1.4': {} + '@fastify/ajv-compiler@4.0.1': + dependencies: + ajv: 8.17.1 + ajv-formats: 3.0.1(ajv@8.17.1) + fast-uri: 3.0.3 + + '@fastify/error@4.0.0': {} + + '@fastify/fast-json-stringify-compiler@5.0.1': + dependencies: + fast-json-stringify: 6.0.0 + + '@fastify/merge-json-schemas@0.1.1': + dependencies: + fast-deep-equal: 3.1.3 + '@floating-ui/core@1.6.2': dependencies: '@floating-ui/utils': 0.2.2 @@ -11094,7 +11344,7 @@ snapshots: dependencies: '@angular/compiler-cli': 18.2.11(@angular/compiler@18.2.11(@angular/core@18.2.11(rxjs@7.8.1)(zone.js@0.15.0)))(typescript@5.5.3) typescript: 5.5.3 - webpack: 5.94.0(esbuild@0.23.1) + webpack: 5.94.0(esbuild@0.23.0) '@nodelib/fs.scandir@2.1.5': dependencies: @@ -12000,6 +12250,14 @@ snapshots: transitivePeerDependencies: - chokidar + '@seriousme/openapi-schema-validator@2.2.5': + dependencies: + ajv: 8.17.1 + ajv-draft-04: 1.0.0(ajv@8.17.1) + ajv-formats: 3.0.1(ajv@8.17.1) + js-yaml: 4.1.0 + minimist: 1.2.8 + '@shikijs/core@1.10.3': dependencies: '@types/hast': 3.0.4 @@ -12630,6 +12888,25 @@ snapshots: '@vitest/utils': 2.0.0 chai: 5.1.1 + '@vitest/expect@2.1.5': + dependencies: + '@vitest/spy': 2.1.5 + '@vitest/utils': 2.1.5 + chai: 5.1.2 + tinyrainbow: 1.2.0 + + '@vitest/mocker@2.1.5(vite@5.4.6(@types/node@22.8.5)(less@4.2.0)(sass@1.77.6)(terser@5.31.6))': + dependencies: + '@vitest/spy': 2.1.5 + estree-walker: 3.0.3 + magic-string: 0.30.12 + optionalDependencies: + vite: 5.4.6(@types/node@22.8.5)(less@4.2.0)(sass@1.77.6)(terser@5.31.6) + + '@vitest/pretty-format@2.1.5': + dependencies: + tinyrainbow: 1.2.0 + '@vitest/runner@1.6.0': dependencies: '@vitest/utils': 1.6.0 @@ -12641,6 +12918,11 @@ snapshots: '@vitest/utils': 2.0.0 pathe: 1.1.2 + '@vitest/runner@2.1.5': + dependencies: + '@vitest/utils': 2.1.5 + pathe: 1.1.2 + '@vitest/snapshot@1.6.0': dependencies: magic-string: 0.30.11 @@ -12653,6 +12935,12 @@ snapshots: pathe: 1.1.2 pretty-format: 29.7.0 + '@vitest/snapshot@2.1.5': + dependencies: + '@vitest/pretty-format': 2.1.5 + magic-string: 0.30.12 + pathe: 1.1.2 + '@vitest/spy@1.6.0': dependencies: tinyspy: 2.2.1 @@ -12661,6 +12949,10 @@ snapshots: dependencies: tinyspy: 3.0.0 + '@vitest/spy@2.1.5': + dependencies: + tinyspy: 3.0.2 + '@vitest/utils@1.6.0': dependencies: diff-sequences: 29.6.3 @@ -12675,6 +12967,12 @@ snapshots: loupe: 3.1.1 pretty-format: 29.7.0 + '@vitest/utils@2.1.5': + dependencies: + '@vitest/pretty-format': 2.1.5 + loupe: 3.1.2 + tinyrainbow: 1.2.0 + '@volar/language-core@2.4.0-alpha.18': dependencies: '@volar/source-map': 2.4.0-alpha.18 @@ -13056,6 +13354,8 @@ snapshots: abbrev@2.0.0: {} + abstract-logging@2.0.1: {} + accepts@1.3.8: dependencies: mime-types: 2.1.35 @@ -13104,6 +13404,10 @@ snapshots: ajv: 8.13.0 optional: true + ajv-draft-04@1.0.0(ajv@8.17.1): + optionalDependencies: + ajv: 8.17.1 + ajv-formats@2.1.1(ajv@8.17.1): optionalDependencies: ajv: 8.17.1 @@ -13243,6 +13547,8 @@ snapshots: asynckit@0.4.0: {} + atomic-sleep@1.0.0: {} + autoprefixer@10.4.19(postcss@8.4.39): dependencies: browserslist: 4.23.1 @@ -13263,6 +13569,11 @@ snapshots: postcss: 8.4.41 postcss-value-parser: 4.2.0 + avvio@9.1.0: + dependencies: + '@fastify/error': 4.0.0 + fastq: 1.17.1 + axios@1.7.7: dependencies: follow-redirects: 1.15.6(debug@4.3.7) @@ -13280,7 +13591,7 @@ snapshots: '@babel/core': 7.25.2 find-cache-dir: 4.0.0 schema-utils: 4.2.0 - webpack: 5.94.0(esbuild@0.23.1) + webpack: 5.94.0(esbuild@0.23.0) babel-plugin-polyfill-corejs2@0.4.11(@babel/core@7.25.2): dependencies: @@ -13507,6 +13818,14 @@ snapshots: loupe: 3.1.1 pathval: 2.0.0 + chai@5.1.2: + dependencies: + assertion-error: 2.0.1 + check-error: 2.1.1 + deep-eql: 5.0.2 + loupe: 3.1.1 + pathval: 2.0.0 + chalk@2.4.2: dependencies: ansi-styles: 3.2.1 @@ -13717,6 +14036,8 @@ snapshots: cookie@0.7.2: {} + cookie@1.0.1: {} + copy-anything@2.0.6: dependencies: is-what: 3.14.1 @@ -13733,7 +14054,7 @@ snapshots: normalize-path: 3.0.0 schema-utils: 4.2.0 serialize-javascript: 6.0.2 - webpack: 5.94.0(esbuild@0.23.1) + webpack: 5.94.0(esbuild@0.23.0) core-js-compat@3.39.0: dependencies: @@ -13790,7 +14111,7 @@ snapshots: postcss-value-parser: 4.2.0 semver: 7.6.3 optionalDependencies: - webpack: 5.94.0(esbuild@0.23.1) + webpack: 5.94.0(esbuild@0.23.0) css-select@5.1.0: dependencies: @@ -14062,6 +14383,8 @@ snapshots: es-module-lexer@1.5.3: {} + es-module-lexer@1.5.4: {} + es6-promise@3.3.1: {} esbuild-wasm@0.23.0: {} @@ -14436,6 +14759,8 @@ snapshots: signal-exit: 4.1.0 strip-final-newline: 3.0.0 + expect-type@1.1.0: {} + exponential-backoff@3.1.1: {} express@4.21.0: @@ -14494,6 +14819,8 @@ snapshots: transitivePeerDependencies: - supports-color + fast-decode-uri-component@1.0.1: {} + fast-deep-equal@3.1.3: {} fast-diff@1.3.0: {} @@ -14510,10 +14837,55 @@ snapshots: fast-json-stable-stringify@2.1.0: {} + fast-json-stringify@6.0.0: + dependencies: + '@fastify/merge-json-schemas': 0.1.1 + ajv: 8.17.1 + ajv-formats: 3.0.1(ajv@8.17.1) + fast-deep-equal: 3.1.3 + fast-uri: 2.4.0 + json-schema-ref-resolver: 1.0.1 + rfdc: 1.4.1 + fast-levenshtein@2.0.6: {} + fast-querystring@1.1.2: + dependencies: + fast-decode-uri-component: 1.0.1 + + fast-redact@3.5.0: {} + + fast-uri@2.4.0: {} + fast-uri@3.0.3: {} + fastify-openapi-glue@4.7.1: + dependencies: + '@seriousme/openapi-schema-validator': 2.2.5 + fastify-plugin: 4.5.1 + js-yaml: 4.1.0 + minimist: 1.2.8 + + fastify-plugin@4.5.1: {} + + fastify@5.0.0: + dependencies: + '@fastify/ajv-compiler': 4.0.1 + '@fastify/error': 4.0.0 + '@fastify/fast-json-stringify-compiler': 5.0.1 + abstract-logging: 2.0.1 + avvio: 9.1.0 + fast-json-stringify: 6.0.0 + find-my-way: 9.1.0 + light-my-request: 6.3.0 + pino: 9.5.0 + process-warning: 4.0.0 + proxy-addr: 2.0.7 + rfdc: 1.4.1 + secure-json-parse: 2.7.0 + semver: 7.6.3 + toad-cache: 3.7.0 + fastq@1.17.1: dependencies: reusify: 1.0.4 @@ -14574,6 +14946,12 @@ snapshots: common-path-prefix: 3.0.0 pkg-dir: 7.0.0 + find-my-way@9.1.0: + dependencies: + fast-deep-equal: 3.1.3 + fast-querystring: 1.1.2 + safe-regex2: 4.0.0 + find-up@4.1.0: dependencies: locate-path: 5.0.0 @@ -14866,7 +15244,7 @@ snapshots: http-proxy-agent@7.0.2: dependencies: agent-base: 7.1.1 - debug: 4.3.5 + debug: 4.3.7 transitivePeerDependencies: - supports-color @@ -14901,13 +15279,6 @@ snapshots: transitivePeerDependencies: - debug - https-proxy-agent@7.0.4: - dependencies: - agent-base: 7.1.1 - debug: 4.3.5 - transitivePeerDependencies: - - supports-color - https-proxy-agent@7.0.5: dependencies: agent-base: 7.1.1 @@ -15181,7 +15552,7 @@ snapshots: form-data: 4.0.0 html-encoding-sniffer: 4.0.0 http-proxy-agent: 7.0.2 - https-proxy-agent: 7.0.4 + https-proxy-agent: 7.0.5 is-potential-custom-element-name: 1.0.1 nwsapi: 2.2.12 parse5: 7.1.2 @@ -15211,6 +15582,10 @@ snapshots: json-parse-even-better-errors@3.0.2: {} + json-schema-ref-resolver@1.0.1: + dependencies: + fast-deep-equal: 3.1.3 + json-schema-traverse@0.4.1: {} json-schema-traverse@1.0.0: {} @@ -15318,7 +15693,7 @@ snapshots: dependencies: less: 4.2.0 optionalDependencies: - webpack: 5.94.0(esbuild@0.23.1) + webpack: 5.94.0(esbuild@0.23.0) less@4.2.0: dependencies: @@ -15343,7 +15718,13 @@ snapshots: dependencies: webpack-sources: 3.2.3 optionalDependencies: - webpack: 5.94.0(esbuild@0.23.1) + webpack: 5.94.0(esbuild@0.23.0) + + light-my-request@6.3.0: + dependencies: + cookie: 1.0.1 + process-warning: 4.0.0 + set-cookie-parser: 2.7.0 lilconfig@2.1.0: {} @@ -15483,6 +15864,8 @@ snapshots: dependencies: get-func-name: 2.0.2 + loupe@3.1.2: {} + lru-cache@10.4.0: {} lru-cache@10.4.3: {} @@ -15510,6 +15893,10 @@ snapshots: dependencies: '@jridgewell/sourcemap-codec': 1.5.0 + magic-string@0.30.12: + dependencies: + '@jridgewell/sourcemap-codec': 1.5.0 + magicast@0.3.4: dependencies: '@babel/parser': 7.25.3 @@ -15612,7 +15999,7 @@ snapshots: dependencies: schema-utils: 4.2.0 tapable: 2.2.1 - webpack: 5.94.0(esbuild@0.23.1) + webpack: 5.94.0(esbuild@0.23.0) minimalistic-assert@1.0.1: {} @@ -15908,6 +16295,8 @@ snapshots: ohash@1.1.4: {} + on-exit-leak-free@2.1.2: {} + on-finished@2.3.0: dependencies: ee-first: 1.1.1 @@ -16159,6 +16548,26 @@ snapshots: optionalDependencies: typescript: 5.5.3 + pino-abstract-transport@2.0.0: + dependencies: + split2: 4.2.0 + + pino-std-serializers@7.0.0: {} + + pino@9.5.0: + dependencies: + atomic-sleep: 1.0.0 + fast-redact: 3.5.0 + on-exit-leak-free: 2.1.2 + pino-abstract-transport: 2.0.0 + pino-std-serializers: 7.0.0 + process-warning: 4.0.0 + quick-format-unescaped: 4.0.4 + real-require: 0.2.0 + safe-stable-stringify: 2.5.0 + sonic-boom: 4.2.0 + thread-stream: 3.1.0 + pirates@4.0.6: {} piscina@4.6.1: @@ -16227,7 +16636,7 @@ snapshots: postcss: 8.4.41 semver: 7.6.3 optionalDependencies: - webpack: 5.94.0(esbuild@0.23.1) + webpack: 5.94.0(esbuild@0.23.0) transitivePeerDependencies: - typescript @@ -16323,6 +16732,8 @@ snapshots: process-nextick-args@2.0.1: {} + process-warning@4.0.0: {} + progress@2.0.3: {} promise-inflight@1.0.1: {} @@ -16406,6 +16817,8 @@ snapshots: queue-tick@1.0.1: {} + quick-format-unescaped@4.0.4: {} + randombytes@2.1.0: dependencies: safe-buffer: 5.2.1 @@ -16504,6 +16917,8 @@ snapshots: readdirp@4.0.2: {} + real-require@0.2.0: {} + reflect-metadata@0.2.2: {} regenerate-unicode-properties@10.2.0: @@ -16581,6 +16996,8 @@ snapshots: onetime: 7.0.0 signal-exit: 4.1.0 + ret@0.5.0: {} + retry@0.12.0: {} retry@0.13.1: {} @@ -16667,6 +17084,12 @@ snapshots: safe-buffer@5.2.1: {} + safe-regex2@4.0.0: + dependencies: + ret: 0.5.0 + + safe-stable-stringify@2.5.0: {} + safer-buffer@2.1.2: {} sander@0.5.1: @@ -16681,7 +17104,7 @@ snapshots: neo-async: 2.6.2 optionalDependencies: sass: 1.77.6 - webpack: 5.94.0(esbuild@0.23.1) + webpack: 5.94.0(esbuild@0.23.0) sass@1.77.6: dependencies: @@ -16715,6 +17138,8 @@ snapshots: search-insights@2.14.0: {} + secure-json-parse@2.7.0: {} + select-hose@2.0.0: {} selfsigned@2.4.1: @@ -16932,6 +17357,10 @@ snapshots: seroval: 1.1.1 seroval-plugins: 1.1.1(seroval@1.1.1) + sonic-boom@4.2.0: + dependencies: + atomic-sleep: 1.0.0 + sorcery@0.11.1: dependencies: '@jridgewell/sourcemap-codec': 1.5.0 @@ -16947,7 +17376,7 @@ snapshots: dependencies: iconv-lite: 0.6.3 source-map-js: 1.2.1 - webpack: 5.94.0(esbuild@0.23.1) + webpack: 5.94.0(esbuild@0.23.0) source-map-support@0.5.21: dependencies: @@ -17004,6 +17433,8 @@ snapshots: speakingurl@14.0.1: {} + split2@4.2.0: {} + sprintf-js@1.0.3: {} sprintf-js@1.1.3: {} @@ -17020,6 +17451,8 @@ snapshots: std-env@3.7.0: {} + std-env@3.8.0: {} + streamroller@3.1.5: dependencies: date-format: 4.0.14 @@ -17312,16 +17745,16 @@ snapshots: term-size@2.2.1: {} - terser-webpack-plugin@5.3.10(esbuild@0.23.1)(webpack@5.94.0(esbuild@0.23.0)): + terser-webpack-plugin@5.3.10(esbuild@0.23.0)(webpack@5.94.0(esbuild@0.23.0)): dependencies: '@jridgewell/trace-mapping': 0.3.25 jest-worker: 27.5.1 schema-utils: 3.3.0 serialize-javascript: 6.0.2 terser: 5.31.6 - webpack: 5.94.0(esbuild@0.23.1) + webpack: 5.94.0(esbuild@0.23.0) optionalDependencies: - esbuild: 0.23.1 + esbuild: 0.23.0 terser@5.31.6: dependencies: @@ -17354,6 +17787,10 @@ snapshots: dependencies: tslib: 2.8.1 + thread-stream@3.1.0: + dependencies: + real-require: 0.2.0 + through@2.3.8: {} thunky@1.1.0: {} @@ -17365,6 +17802,10 @@ snapshots: tinybench@2.8.0: {} + tinybench@2.9.0: {} + + tinyexec@0.3.1: {} + tinyglobby@0.2.6: dependencies: fdir: 6.3.0(picomatch@4.0.2) @@ -17374,10 +17815,16 @@ snapshots: tinypool@1.0.0: {} + tinypool@1.0.1: {} + + tinyrainbow@1.2.0: {} + tinyspy@2.2.1: {} tinyspy@3.0.0: {} + tinyspy@3.0.2: {} + tmp@0.0.33: dependencies: os-tmpdir: 1.0.2 @@ -17390,6 +17837,8 @@ snapshots: dependencies: is-number: 7.0.0 + toad-cache@3.7.0: {} + toidentifier@1.0.1: {} totalist@3.0.1: {} @@ -17727,6 +18176,24 @@ snapshots: - supports-color - terser + vite-node@2.1.5(@types/node@22.8.5)(less@4.2.0)(sass@1.77.6)(terser@5.31.6): + dependencies: + cac: 6.7.14 + debug: 4.3.7 + es-module-lexer: 1.5.4 + pathe: 1.1.2 + vite: 5.4.6(@types/node@22.8.5)(less@4.2.0)(sass@1.77.6)(terser@5.31.6) + transitivePeerDependencies: + - '@types/node' + - less + - lightningcss + - sass + - sass-embedded + - stylus + - sugarss + - supports-color + - terser + vite-plugin-inspect@0.8.5(rollup@4.22.4)(vite@5.4.6(@types/node@20.14.5)(less@4.2.0)(sass@1.77.6)(terser@5.31.6)): dependencies: '@antfu/utils': 0.7.10 @@ -17965,6 +18432,42 @@ snapshots: - supports-color - terser + vitest@2.1.5(@types/node@22.8.5)(jsdom@24.1.0)(less@4.2.0)(sass@1.77.6)(terser@5.31.6): + dependencies: + '@vitest/expect': 2.1.5 + '@vitest/mocker': 2.1.5(vite@5.4.6(@types/node@22.8.5)(less@4.2.0)(sass@1.77.6)(terser@5.31.6)) + '@vitest/pretty-format': 2.1.5 + '@vitest/runner': 2.1.5 + '@vitest/snapshot': 2.1.5 + '@vitest/spy': 2.1.5 + '@vitest/utils': 2.1.5 + chai: 5.1.2 + debug: 4.3.7 + expect-type: 1.1.0 + magic-string: 0.30.12 + pathe: 1.1.2 + std-env: 3.8.0 + tinybench: 2.9.0 + tinyexec: 0.3.1 + tinypool: 1.0.1 + tinyrainbow: 1.2.0 + vite: 5.4.6(@types/node@22.8.5)(less@4.2.0)(sass@1.77.6)(terser@5.31.6) + vite-node: 2.1.5(@types/node@22.8.5)(less@4.2.0)(sass@1.77.6)(terser@5.31.6) + why-is-node-running: 2.3.0 + optionalDependencies: + '@types/node': 22.8.5 + jsdom: 24.1.0 + transitivePeerDependencies: + - less + - lightningcss + - msw + - sass + - sass-embedded + - stylus + - sugarss + - supports-color + - terser + void-elements@2.0.1: {} vscode-uri@3.0.8: {} @@ -18060,7 +18563,7 @@ snapshots: range-parser: 1.2.1 schema-utils: 4.2.0 optionalDependencies: - webpack: 5.94.0(esbuild@0.23.1) + webpack: 5.94.0(esbuild@0.23.0) webpack-dev-server@5.0.4(webpack@5.94.0(esbuild@0.23.0)): dependencies: @@ -18095,7 +18598,7 @@ snapshots: webpack-dev-middleware: 7.4.2(webpack@5.94.0(esbuild@0.23.0)) ws: 8.17.1 optionalDependencies: - webpack: 5.94.0(esbuild@0.23.1) + webpack: 5.94.0(esbuild@0.23.0) transitivePeerDependencies: - bufferutil - debug @@ -18113,9 +18616,9 @@ snapshots: webpack-subresource-integrity@5.1.0(webpack@5.94.0(esbuild@0.23.0)): dependencies: typed-assert: 1.0.9 - webpack: 5.94.0(esbuild@0.23.1) + webpack: 5.94.0(esbuild@0.23.0) - webpack@5.94.0(esbuild@0.23.1): + webpack@5.94.0(esbuild@0.23.0): dependencies: '@types/estree': 1.0.5 '@webassemblyjs/ast': 1.12.1 @@ -18137,7 +18640,7 @@ snapshots: neo-async: 2.6.2 schema-utils: 3.3.0 tapable: 2.2.1 - terser-webpack-plugin: 5.3.10(esbuild@0.23.1)(webpack@5.94.0(esbuild@0.23.0)) + terser-webpack-plugin: 5.3.10(esbuild@0.23.0)(webpack@5.94.0(esbuild@0.23.0)) watchpack: 2.4.1 webpack-sources: 3.2.3 transitivePeerDependencies: -- 2.51.2 From 9a08d67b9a7aab799f1aecab5e97ebdaffc6d2f1 Mon Sep 17 00:00:00 2001 From: Lubos Date: Sat, 16 Nov 2024 07:10:55 +0800 Subject: [PATCH 03/13] chore: update fastify example to match other examples pattern --- .changeset/gorgeous-cups-search.md | 2 +- .../openapi-ts-axios/openapi-ts.config.ts | 2 - .../openapi-ts-fastify/openapi-ts.config.ts | 8 +- examples/openapi-ts-fastify/package.json | 11 +- .../src/{gen => client}/fastify.gen.ts | 0 .../src/{gen => client}/index.ts | 0 .../src/{gen => client}/services.gen.ts | 0 .../src/{gen => client}/types.gen.ts | 0 examples/openapi-ts-fastify/src/handlers.ts | 2 +- examples/openapi-ts-fastify/test/pets.test.ts | 2 +- .../openapi-ts-fetch/openapi-ts.config.ts | 2 - .../openapi-ts.config.ts | 2 - .../openapi-ts.config.ts | 2 - pnpm-lock.yaml | 194 ++++-------------- 14 files changed, 52 insertions(+), 175 deletions(-) rename examples/openapi-ts-fastify/src/{gen => client}/fastify.gen.ts (100%) rename examples/openapi-ts-fastify/src/{gen => client}/index.ts (100%) rename examples/openapi-ts-fastify/src/{gen => client}/services.gen.ts (100%) rename examples/openapi-ts-fastify/src/{gen => client}/types.gen.ts (100%) diff --git a/.changeset/gorgeous-cups-search.md b/.changeset/gorgeous-cups-search.md index 3a26359c3..61df419bc 100644 --- a/.changeset/gorgeous-cups-search.md +++ b/.changeset/gorgeous-cups-search.md @@ -2,4 +2,4 @@ '@hey-api/openapi-ts': minor --- -feat: add fastify-openapi-glue plugin +feat: add `fastify` plugin diff --git a/examples/openapi-ts-axios/openapi-ts.config.ts b/examples/openapi-ts-axios/openapi-ts.config.ts index e72999da9..ebc14a20f 100644 --- a/examples/openapi-ts-axios/openapi-ts.config.ts +++ b/examples/openapi-ts-axios/openapi-ts.config.ts @@ -4,8 +4,6 @@ export default defineConfig({ client: '@hey-api/client-axios', input: 'https://raw.githubusercontent.com/swagger-api/swagger-petstore/master/src/main/resources/openapi.yaml', - // 'https://raw.githubusercontent.com/Redocly/museum-openapi-example/main/openapi.yaml', - // '../../packages/openapi-ts/test/spec/v3.json', output: { format: 'prettier', lint: 'eslint', diff --git a/examples/openapi-ts-fastify/openapi-ts.config.ts b/examples/openapi-ts-fastify/openapi-ts.config.ts index 268779158..c9f038d3a 100644 --- a/examples/openapi-ts-fastify/openapi-ts.config.ts +++ b/examples/openapi-ts-fastify/openapi-ts.config.ts @@ -5,6 +5,10 @@ export default defineConfig({ experimentalParser: true, input: 'https://gist.githubusercontent.com/seriousme/55bd4c8ba2e598e416bb5543dcd362dc/raw/cf0b86ba37bb54bf1a6bf047c0ecf2a0ce4c62e0/petstore-v3.1.json', - output: './src/gen', - plugins: ['fastify'], + output: { + format: 'prettier', + lint: 'eslint', + path: './src/client', + }, + plugins: ['@hey-api/types', '@hey-api/services', 'fastify'], }); diff --git a/examples/openapi-ts-fastify/package.json b/examples/openapi-ts-fastify/package.json index 877466ea9..643a66179 100644 --- a/examples/openapi-ts-fastify/package.json +++ b/examples/openapi-ts-fastify/package.json @@ -5,16 +5,19 @@ "type": "module", "scripts": { "openapi-ts": "openapi-ts", - "typecheck": "tsc --noEmit", - "test": "vitest" + "test": "vitest", + "typecheck": "tsc --noEmit" }, "dependencies": { - "@hey-api/openapi-ts": "workspace:*", + "@hey-api/client-fetch": "workspace:*", "fastify": "5.0.0", "fastify-openapi-glue": "4.7.1" }, "devDependencies": { - "@hey-api/client-fetch": "workspace:*", + "@hey-api/openapi-ts": "workspace:*", + "eslint": "9.6.0", + "prettier": "3.3.2", + "typescript": "5.5.3", "vitest": "2.1.5" } } diff --git a/examples/openapi-ts-fastify/src/gen/fastify.gen.ts b/examples/openapi-ts-fastify/src/client/fastify.gen.ts similarity index 100% rename from examples/openapi-ts-fastify/src/gen/fastify.gen.ts rename to examples/openapi-ts-fastify/src/client/fastify.gen.ts diff --git a/examples/openapi-ts-fastify/src/gen/index.ts b/examples/openapi-ts-fastify/src/client/index.ts similarity index 100% rename from examples/openapi-ts-fastify/src/gen/index.ts rename to examples/openapi-ts-fastify/src/client/index.ts diff --git a/examples/openapi-ts-fastify/src/gen/services.gen.ts b/examples/openapi-ts-fastify/src/client/services.gen.ts similarity index 100% rename from examples/openapi-ts-fastify/src/gen/services.gen.ts rename to examples/openapi-ts-fastify/src/client/services.gen.ts diff --git a/examples/openapi-ts-fastify/src/gen/types.gen.ts b/examples/openapi-ts-fastify/src/client/types.gen.ts similarity index 100% rename from examples/openapi-ts-fastify/src/gen/types.gen.ts rename to examples/openapi-ts-fastify/src/client/types.gen.ts diff --git a/examples/openapi-ts-fastify/src/handlers.ts b/examples/openapi-ts-fastify/src/handlers.ts index fbb509ae7..1907905e1 100644 --- a/examples/openapi-ts-fastify/src/handlers.ts +++ b/examples/openapi-ts-fastify/src/handlers.ts @@ -1,4 +1,4 @@ -import type { Pet, RouteHandlers } from './gen/fastify.gen'; +import type { Pet, RouteHandlers } from './client/fastify.gen'; export const serviceHandlers: Pick = { showPetById(request, reply) { diff --git a/examples/openapi-ts-fastify/test/pets.test.ts b/examples/openapi-ts-fastify/test/pets.test.ts index 68a6c1b11..66104acee 100644 --- a/examples/openapi-ts-fastify/test/pets.test.ts +++ b/examples/openapi-ts-fastify/test/pets.test.ts @@ -1,5 +1,5 @@ import { type FastifyInstance } from 'fastify'; -import { client, showPetById } from 'src/gen'; +import { client, showPetById } from 'src/client'; import { buildServer } from 'src/server'; import { afterAll, beforeAll, describe, expect, test } from 'vitest'; diff --git a/examples/openapi-ts-fetch/openapi-ts.config.ts b/examples/openapi-ts-fetch/openapi-ts.config.ts index 463df2054..18b8ede57 100644 --- a/examples/openapi-ts-fetch/openapi-ts.config.ts +++ b/examples/openapi-ts-fetch/openapi-ts.config.ts @@ -4,8 +4,6 @@ export default defineConfig({ client: '@hey-api/client-fetch', input: 'https://raw.githubusercontent.com/swagger-api/swagger-petstore/master/src/main/resources/openapi.yaml', - // 'https://raw.githubusercontent.com/Redocly/museum-openapi-example/main/openapi.yaml', - // '../../packages/openapi-ts/test/spec/v3.json', output: { format: 'prettier', lint: 'eslint', diff --git a/examples/openapi-ts-tanstack-svelte-query/openapi-ts.config.ts b/examples/openapi-ts-tanstack-svelte-query/openapi-ts.config.ts index 2d68e785e..4eeb88d91 100644 --- a/examples/openapi-ts-tanstack-svelte-query/openapi-ts.config.ts +++ b/examples/openapi-ts-tanstack-svelte-query/openapi-ts.config.ts @@ -4,8 +4,6 @@ export default defineConfig({ client: '@hey-api/client-fetch', input: 'https://raw.githubusercontent.com/swagger-api/swagger-petstore/master/src/main/resources/openapi.yaml', - // 'https://raw.githubusercontent.com/Redocly/museum-openapi-example/main/openapi.yaml', - // '../../packages/openapi-ts/test/spec/v3.json', output: { format: 'prettier', lint: 'eslint', diff --git a/examples/openapi-ts-tanstack-vue-query/openapi-ts.config.ts b/examples/openapi-ts-tanstack-vue-query/openapi-ts.config.ts index 4bc702467..03f761656 100644 --- a/examples/openapi-ts-tanstack-vue-query/openapi-ts.config.ts +++ b/examples/openapi-ts-tanstack-vue-query/openapi-ts.config.ts @@ -4,8 +4,6 @@ export default defineConfig({ client: '@hey-api/client-fetch', input: 'https://raw.githubusercontent.com/swagger-api/swagger-petstore/master/src/main/resources/openapi.yaml', - // 'https://raw.githubusercontent.com/Redocly/museum-openapi-example/main/openapi.yaml', - // '../../packages/openapi-ts/test/spec/v3.json', output: { format: 'prettier', lint: 'eslint', diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9ba491f32..1a5311f18 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -151,9 +151,9 @@ importers: examples/openapi-ts-fastify: dependencies: - '@hey-api/openapi-ts': + '@hey-api/client-fetch': specifier: workspace:* - version: link:../../packages/openapi-ts + version: link:../../packages/client-fetch fastify: specifier: 5.0.0 version: 5.0.0 @@ -161,9 +161,18 @@ importers: specifier: 4.7.1 version: 4.7.1 devDependencies: - '@hey-api/client-fetch': + '@hey-api/openapi-ts': specifier: workspace:* - version: link:../../packages/client-fetch + version: link:../../packages/openapi-ts + eslint: + specifier: 9.6.0 + version: 9.6.0 + prettier: + specifier: 3.3.2 + version: 3.3.2 + typescript: + specifier: 5.5.3 + version: 5.5.3 vitest: specifier: 2.1.5 version: 2.1.5(@types/node@22.8.5)(jsdom@24.1.0)(less@4.2.0)(sass@1.77.6)(terser@5.31.6) @@ -285,7 +294,7 @@ importers: devDependencies: '@angular-devkit/build-angular': specifier: ^18.2.11 - version: 18.2.11(@angular/compiler-cli@18.2.11(@angular/compiler@18.2.11(@angular/core@18.2.11(rxjs@7.8.1)(zone.js@0.15.0)))(typescript@5.5.3))(@types/node@22.8.5)(chokidar@3.6.0)(karma@6.4.4)(tailwindcss@3.4.9)(typescript@5.5.3) + version: 18.2.11(@angular/compiler-cli@18.2.11(@angular/compiler@18.2.11(@angular/core@18.2.11(rxjs@7.8.1)(zone.js@0.15.0)))(typescript@5.5.3))(@types/node@22.8.5)(chokidar@3.6.0)(karma@6.4.4)(tailwindcss@3.4.9(ts-node@10.9.2(@types/node@22.8.5)(typescript@5.5.3)))(typescript@5.5.3) '@angular/cli': specifier: ^18.2.11 version: 18.2.11(chokidar@3.6.0) @@ -9190,7 +9199,7 @@ snapshots: typescript: 5.5.3 vite: 5.4.6(@types/node@22.8.5)(less@4.2.0)(sass@1.77.6)(terser@5.31.6) watchpack: 2.4.1 - webpack: 5.94.0(esbuild@0.23.0) + webpack: 5.94.0(esbuild@0.23.1) webpack-dev-middleware: 7.4.2(webpack@5.94.0(esbuild@0.23.0)) webpack-dev-server: 5.0.4(webpack@5.94.0(esbuild@0.23.0)) webpack-merge: 6.0.1 @@ -9217,99 +9226,11 @@ snapshots: - utf-8-validate - webpack-cli - '@angular-devkit/build-angular@18.2.11(@angular/compiler-cli@18.2.11(@angular/compiler@18.2.11(@angular/core@18.2.11(rxjs@7.8.1)(zone.js@0.15.0)))(typescript@5.5.3))(@types/node@22.8.5)(chokidar@3.6.0)(karma@6.4.4)(tailwindcss@3.4.9)(typescript@5.5.3)': - dependencies: - '@ampproject/remapping': 2.3.0 - '@angular-devkit/architect': 0.1802.11(chokidar@3.6.0) - '@angular-devkit/build-webpack': 0.1802.11(chokidar@3.6.0)(webpack-dev-server@5.0.4(webpack@5.94.0(esbuild@0.23.0)))(webpack@5.94.0(esbuild@0.23.0)) - '@angular-devkit/core': 18.2.11(chokidar@3.6.0) - '@angular/build': 18.2.11(@angular/compiler-cli@18.2.11(@angular/compiler@18.2.11(@angular/core@18.2.11(rxjs@7.8.1)(zone.js@0.15.0)))(typescript@5.5.3))(@types/node@22.8.5)(chokidar@3.6.0)(less@4.2.0)(postcss@8.4.41)(tailwindcss@3.4.9)(terser@5.31.6)(typescript@5.5.3) - '@angular/compiler-cli': 18.2.11(@angular/compiler@18.2.11(@angular/core@18.2.11(rxjs@7.8.1)(zone.js@0.15.0)))(typescript@5.5.3) - '@babel/core': 7.25.2 - '@babel/generator': 7.25.0 - '@babel/helper-annotate-as-pure': 7.24.7 - '@babel/helper-split-export-declaration': 7.24.7 - '@babel/plugin-transform-async-generator-functions': 7.25.0(@babel/core@7.25.2) - '@babel/plugin-transform-async-to-generator': 7.24.7(@babel/core@7.25.2) - '@babel/plugin-transform-runtime': 7.24.7(@babel/core@7.25.2) - '@babel/preset-env': 7.25.3(@babel/core@7.25.2) - '@babel/runtime': 7.25.0 - '@discoveryjs/json-ext': 0.6.1 - '@ngtools/webpack': 18.2.11(@angular/compiler-cli@18.2.11(@angular/compiler@18.2.11(@angular/core@18.2.11(rxjs@7.8.1)(zone.js@0.15.0)))(typescript@5.5.3))(typescript@5.5.3)(webpack@5.94.0(esbuild@0.23.0)) - '@vitejs/plugin-basic-ssl': 1.1.0(vite@5.4.6(@types/node@22.8.5)(less@4.2.0)(sass@1.77.6)(terser@5.31.6)) - ansi-colors: 4.1.3 - autoprefixer: 10.4.20(postcss@8.4.41) - babel-loader: 9.1.3(@babel/core@7.25.2)(webpack@5.94.0(esbuild@0.23.0)) - browserslist: 4.24.2 - copy-webpack-plugin: 12.0.2(webpack@5.94.0(esbuild@0.23.0)) - critters: 0.0.24 - css-loader: 7.1.2(webpack@5.94.0(esbuild@0.23.0)) - esbuild-wasm: 0.23.0 - fast-glob: 3.3.2 - http-proxy-middleware: 3.0.3 - https-proxy-agent: 7.0.5 - istanbul-lib-instrument: 6.0.3 - jsonc-parser: 3.3.1 - karma-source-map-support: 1.4.0 - less: 4.2.0 - less-loader: 12.2.0(less@4.2.0)(webpack@5.94.0(esbuild@0.23.0)) - license-webpack-plugin: 4.0.2(webpack@5.94.0(esbuild@0.23.0)) - loader-utils: 3.3.1 - magic-string: 0.30.11 - mini-css-extract-plugin: 2.9.0(webpack@5.94.0(esbuild@0.23.0)) - mrmime: 2.0.0 - open: 10.1.0 - ora: 5.4.1 - parse5-html-rewriting-stream: 7.0.0 - picomatch: 4.0.2 - piscina: 4.6.1 - postcss: 8.4.41 - postcss-loader: 8.1.1(postcss@8.4.41)(typescript@5.5.3)(webpack@5.94.0(esbuild@0.23.0)) - resolve-url-loader: 5.0.0 - rxjs: 7.8.1 - sass: 1.77.6 - sass-loader: 16.0.0(sass@1.77.6)(webpack@5.94.0(esbuild@0.23.0)) - semver: 7.6.3 - source-map-loader: 5.0.0(webpack@5.94.0(esbuild@0.23.0)) - source-map-support: 0.5.21 - terser: 5.31.6 - tree-kill: 1.2.2 - tslib: 2.6.3 - typescript: 5.5.3 - vite: 5.4.6(@types/node@22.8.5)(less@4.2.0)(sass@1.77.6)(terser@5.31.6) - watchpack: 2.4.1 - webpack: 5.94.0(esbuild@0.23.0) - webpack-dev-middleware: 7.4.2(webpack@5.94.0(esbuild@0.23.0)) - webpack-dev-server: 5.0.4(webpack@5.94.0(esbuild@0.23.0)) - webpack-merge: 6.0.1 - webpack-subresource-integrity: 5.1.0(webpack@5.94.0(esbuild@0.23.0)) - optionalDependencies: - esbuild: 0.23.0 - karma: 6.4.4 - tailwindcss: 3.4.9(ts-node@10.9.2(@types/node@20.14.5)(typescript@5.5.3)) - transitivePeerDependencies: - - '@rspack/core' - - '@swc/core' - - '@types/node' - - bufferutil - - chokidar - - debug - - html-webpack-plugin - - lightningcss - - node-sass - - sass-embedded - - stylus - - sugarss - - supports-color - - uglify-js - - utf-8-validate - - webpack-cli - '@angular-devkit/build-webpack@0.1802.11(chokidar@3.6.0)(webpack-dev-server@5.0.4(webpack@5.94.0(esbuild@0.23.0)))(webpack@5.94.0(esbuild@0.23.0))': dependencies: '@angular-devkit/architect': 0.1802.11(chokidar@3.6.0) rxjs: 7.8.1 - webpack: 5.94.0(esbuild@0.23.0) + webpack: 5.94.0(esbuild@0.23.1) webpack-dev-server: 5.0.4(webpack@5.94.0(esbuild@0.23.0)) transitivePeerDependencies: - chokidar @@ -9383,49 +9304,6 @@ snapshots: - supports-color - terser - '@angular/build@18.2.11(@angular/compiler-cli@18.2.11(@angular/compiler@18.2.11(@angular/core@18.2.11(rxjs@7.8.1)(zone.js@0.15.0)))(typescript@5.5.3))(@types/node@22.8.5)(chokidar@3.6.0)(less@4.2.0)(postcss@8.4.41)(tailwindcss@3.4.9)(terser@5.31.6)(typescript@5.5.3)': - dependencies: - '@ampproject/remapping': 2.3.0 - '@angular-devkit/architect': 0.1802.11(chokidar@3.6.0) - '@angular/compiler-cli': 18.2.11(@angular/compiler@18.2.11(@angular/core@18.2.11(rxjs@7.8.1)(zone.js@0.15.0)))(typescript@5.5.3) - '@babel/core': 7.25.2 - '@babel/helper-annotate-as-pure': 7.24.7 - '@babel/helper-split-export-declaration': 7.24.7 - '@babel/plugin-syntax-import-attributes': 7.24.7(@babel/core@7.25.2) - '@inquirer/confirm': 3.1.22 - '@vitejs/plugin-basic-ssl': 1.1.0(vite@5.4.6(@types/node@22.8.5)(less@4.2.0)(sass@1.77.6)(terser@5.31.6)) - browserslist: 4.24.2 - critters: 0.0.24 - esbuild: 0.23.0 - fast-glob: 3.3.2 - https-proxy-agent: 7.0.5 - listr2: 8.2.4 - lmdb: 3.0.13 - magic-string: 0.30.11 - mrmime: 2.0.0 - parse5-html-rewriting-stream: 7.0.0 - picomatch: 4.0.2 - piscina: 4.6.1 - rollup: 4.22.4 - sass: 1.77.6 - semver: 7.6.3 - typescript: 5.5.3 - vite: 5.4.6(@types/node@22.8.5)(less@4.2.0)(sass@1.77.6)(terser@5.31.6) - watchpack: 2.4.1 - optionalDependencies: - less: 4.2.0 - postcss: 8.4.41 - tailwindcss: 3.4.9(ts-node@10.9.2(@types/node@20.14.5)(typescript@5.5.3)) - transitivePeerDependencies: - - '@types/node' - - chokidar - - lightningcss - - sass-embedded - - stylus - - sugarss - - supports-color - - terser - '@angular/cdk@18.2.12(@angular/common@18.2.11(@angular/core@18.2.11(rxjs@7.8.1)(zone.js@0.15.0))(rxjs@7.8.1))(@angular/core@18.2.11(rxjs@7.8.1)(zone.js@0.15.0))(rxjs@7.8.1)': dependencies: '@angular/common': 18.2.11(@angular/core@18.2.11(rxjs@7.8.1)(zone.js@0.15.0))(rxjs@7.8.1) @@ -10999,7 +10877,7 @@ snapshots: '@eslint/config-array@0.17.0': dependencies: '@eslint/object-schema': 2.1.4 - debug: 4.3.5 + debug: 4.3.7 minimatch: 3.1.2 transitivePeerDependencies: - supports-color @@ -11344,7 +11222,7 @@ snapshots: dependencies: '@angular/compiler-cli': 18.2.11(@angular/compiler@18.2.11(@angular/core@18.2.11(rxjs@7.8.1)(zone.js@0.15.0)))(typescript@5.5.3) typescript: 5.5.3 - webpack: 5.94.0(esbuild@0.23.0) + webpack: 5.94.0(esbuild@0.23.1) '@nodelib/fs.scandir@2.1.5': dependencies: @@ -13591,7 +13469,7 @@ snapshots: '@babel/core': 7.25.2 find-cache-dir: 4.0.0 schema-utils: 4.2.0 - webpack: 5.94.0(esbuild@0.23.0) + webpack: 5.94.0(esbuild@0.23.1) babel-plugin-polyfill-corejs2@0.4.11(@babel/core@7.25.2): dependencies: @@ -14054,7 +13932,7 @@ snapshots: normalize-path: 3.0.0 schema-utils: 4.2.0 serialize-javascript: 6.0.2 - webpack: 5.94.0(esbuild@0.23.0) + webpack: 5.94.0(esbuild@0.23.1) core-js-compat@3.39.0: dependencies: @@ -14111,7 +13989,7 @@ snapshots: postcss-value-parser: 4.2.0 semver: 7.6.3 optionalDependencies: - webpack: 5.94.0(esbuild@0.23.0) + webpack: 5.94.0(esbuild@0.23.1) css-select@5.1.0: dependencies: @@ -14659,7 +14537,7 @@ snapshots: ajv: 6.12.6 chalk: 4.1.2 cross-spawn: 7.0.3 - debug: 4.3.5 + debug: 4.3.7 escape-string-regexp: 4.0.0 eslint-scope: 8.0.1 eslint-visitor-keys: 4.0.0 @@ -15693,7 +15571,7 @@ snapshots: dependencies: less: 4.2.0 optionalDependencies: - webpack: 5.94.0(esbuild@0.23.0) + webpack: 5.94.0(esbuild@0.23.1) less@4.2.0: dependencies: @@ -15718,7 +15596,7 @@ snapshots: dependencies: webpack-sources: 3.2.3 optionalDependencies: - webpack: 5.94.0(esbuild@0.23.0) + webpack: 5.94.0(esbuild@0.23.1) light-my-request@6.3.0: dependencies: @@ -15999,7 +15877,7 @@ snapshots: dependencies: schema-utils: 4.2.0 tapable: 2.2.1 - webpack: 5.94.0(esbuild@0.23.0) + webpack: 5.94.0(esbuild@0.23.1) minimalistic-assert@1.0.1: {} @@ -16636,7 +16514,7 @@ snapshots: postcss: 8.4.41 semver: 7.6.3 optionalDependencies: - webpack: 5.94.0(esbuild@0.23.0) + webpack: 5.94.0(esbuild@0.23.1) transitivePeerDependencies: - typescript @@ -17104,7 +16982,7 @@ snapshots: neo-async: 2.6.2 optionalDependencies: sass: 1.77.6 - webpack: 5.94.0(esbuild@0.23.0) + webpack: 5.94.0(esbuild@0.23.1) sass@1.77.6: dependencies: @@ -17376,7 +17254,7 @@ snapshots: dependencies: iconv-lite: 0.6.3 source-map-js: 1.2.1 - webpack: 5.94.0(esbuild@0.23.0) + webpack: 5.94.0(esbuild@0.23.1) source-map-support@0.5.21: dependencies: @@ -17745,16 +17623,16 @@ snapshots: term-size@2.2.1: {} - terser-webpack-plugin@5.3.10(esbuild@0.23.0)(webpack@5.94.0(esbuild@0.23.0)): + terser-webpack-plugin@5.3.10(esbuild@0.23.1)(webpack@5.94.0(esbuild@0.23.0)): dependencies: '@jridgewell/trace-mapping': 0.3.25 jest-worker: 27.5.1 schema-utils: 3.3.0 serialize-javascript: 6.0.2 terser: 5.31.6 - webpack: 5.94.0(esbuild@0.23.0) + webpack: 5.94.0(esbuild@0.23.1) optionalDependencies: - esbuild: 0.23.0 + esbuild: 0.23.1 terser@5.31.6: dependencies: @@ -18563,7 +18441,7 @@ snapshots: range-parser: 1.2.1 schema-utils: 4.2.0 optionalDependencies: - webpack: 5.94.0(esbuild@0.23.0) + webpack: 5.94.0(esbuild@0.23.1) webpack-dev-server@5.0.4(webpack@5.94.0(esbuild@0.23.0)): dependencies: @@ -18598,7 +18476,7 @@ snapshots: webpack-dev-middleware: 7.4.2(webpack@5.94.0(esbuild@0.23.0)) ws: 8.17.1 optionalDependencies: - webpack: 5.94.0(esbuild@0.23.0) + webpack: 5.94.0(esbuild@0.23.1) transitivePeerDependencies: - bufferutil - debug @@ -18616,9 +18494,9 @@ snapshots: webpack-subresource-integrity@5.1.0(webpack@5.94.0(esbuild@0.23.0)): dependencies: typed-assert: 1.0.9 - webpack: 5.94.0(esbuild@0.23.0) + webpack: 5.94.0(esbuild@0.23.1) - webpack@5.94.0(esbuild@0.23.0): + webpack@5.94.0(esbuild@0.23.1): dependencies: '@types/estree': 1.0.5 '@webassemblyjs/ast': 1.12.1 @@ -18640,7 +18518,7 @@ snapshots: neo-async: 2.6.2 schema-utils: 3.3.0 tapable: 2.2.1 - terser-webpack-plugin: 5.3.10(esbuild@0.23.0)(webpack@5.94.0(esbuild@0.23.0)) + terser-webpack-plugin: 5.3.10(esbuild@0.23.1)(webpack@5.94.0(esbuild@0.23.0)) watchpack: 2.4.1 webpack-sources: 3.2.3 transitivePeerDependencies: -- 2.51.2 From cefd05fe9a9da1930aa9a5a9026cdb9e2b7ae5d4 Mon Sep 17 00:00:00 2001 From: Lubos Date: Sat, 16 Nov 2024 07:16:13 +0800 Subject: [PATCH 04/13] test: update snapshots --- .../3.0.x/plugins/fastify/{ => default}/fastify.gen.ts | 0 .../__snapshots__/3.0.x/plugins/fastify/{ => default}/index.ts | 0 .../3.0.x/plugins/fastify/{ => default}/services.gen.ts | 0 .../3.0.x/plugins/fastify/{ => default}/types.gen.ts | 0 .../3.1.x/plugins/fastify/{ => default}/fastify.gen.ts | 0 .../__snapshots__/3.1.x/plugins/fastify/{ => default}/index.ts | 0 .../3.1.x/plugins/fastify/{ => default}/services.gen.ts | 0 .../3.1.x/plugins/fastify/{ => default}/types.gen.ts | 0 packages/openapi-ts/test/plugins.spec.ts | 2 +- 9 files changed, 1 insertion(+), 1 deletion(-) rename packages/openapi-ts/test/__snapshots__/3.0.x/plugins/fastify/{ => default}/fastify.gen.ts (100%) rename packages/openapi-ts/test/__snapshots__/3.0.x/plugins/fastify/{ => default}/index.ts (100%) rename packages/openapi-ts/test/__snapshots__/3.0.x/plugins/fastify/{ => default}/services.gen.ts (100%) rename packages/openapi-ts/test/__snapshots__/3.0.x/plugins/fastify/{ => default}/types.gen.ts (100%) rename packages/openapi-ts/test/__snapshots__/3.1.x/plugins/fastify/{ => default}/fastify.gen.ts (100%) rename packages/openapi-ts/test/__snapshots__/3.1.x/plugins/fastify/{ => default}/index.ts (100%) rename packages/openapi-ts/test/__snapshots__/3.1.x/plugins/fastify/{ => default}/services.gen.ts (100%) rename packages/openapi-ts/test/__snapshots__/3.1.x/plugins/fastify/{ => default}/types.gen.ts (100%) diff --git a/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/fastify/fastify.gen.ts b/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/fastify/default/fastify.gen.ts similarity index 100% rename from packages/openapi-ts/test/__snapshots__/3.0.x/plugins/fastify/fastify.gen.ts rename to packages/openapi-ts/test/__snapshots__/3.0.x/plugins/fastify/default/fastify.gen.ts diff --git a/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/fastify/index.ts b/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/fastify/default/index.ts similarity index 100% rename from packages/openapi-ts/test/__snapshots__/3.0.x/plugins/fastify/index.ts rename to packages/openapi-ts/test/__snapshots__/3.0.x/plugins/fastify/default/index.ts diff --git a/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/fastify/services.gen.ts b/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/fastify/default/services.gen.ts similarity index 100% rename from packages/openapi-ts/test/__snapshots__/3.0.x/plugins/fastify/services.gen.ts rename to packages/openapi-ts/test/__snapshots__/3.0.x/plugins/fastify/default/services.gen.ts diff --git a/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/fastify/types.gen.ts b/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/fastify/default/types.gen.ts similarity index 100% rename from packages/openapi-ts/test/__snapshots__/3.0.x/plugins/fastify/types.gen.ts rename to packages/openapi-ts/test/__snapshots__/3.0.x/plugins/fastify/default/types.gen.ts diff --git a/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/fastify/fastify.gen.ts b/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/fastify/default/fastify.gen.ts similarity index 100% rename from packages/openapi-ts/test/__snapshots__/3.1.x/plugins/fastify/fastify.gen.ts rename to packages/openapi-ts/test/__snapshots__/3.1.x/plugins/fastify/default/fastify.gen.ts diff --git a/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/fastify/index.ts b/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/fastify/default/index.ts similarity index 100% rename from packages/openapi-ts/test/__snapshots__/3.1.x/plugins/fastify/index.ts rename to packages/openapi-ts/test/__snapshots__/3.1.x/plugins/fastify/default/index.ts diff --git a/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/fastify/services.gen.ts b/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/fastify/default/services.gen.ts similarity index 100% rename from packages/openapi-ts/test/__snapshots__/3.1.x/plugins/fastify/services.gen.ts rename to packages/openapi-ts/test/__snapshots__/3.1.x/plugins/fastify/default/services.gen.ts diff --git a/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/fastify/types.gen.ts b/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/fastify/default/types.gen.ts similarity index 100% rename from packages/openapi-ts/test/__snapshots__/3.1.x/plugins/fastify/types.gen.ts rename to packages/openapi-ts/test/__snapshots__/3.1.x/plugins/fastify/default/types.gen.ts diff --git a/packages/openapi-ts/test/plugins.spec.ts b/packages/openapi-ts/test/plugins.spec.ts index 590e42512..b3a1a2838 100644 --- a/packages/openapi-ts/test/plugins.spec.ts +++ b/packages/openapi-ts/test/plugins.spec.ts @@ -204,7 +204,7 @@ for (const version of versions) { }, { config: createConfig({ - output: '.', + output: 'default', plugins: ['fastify'], }), description: 'generate Fastify types with Fastify plugin', -- 2.51.2 From 22b113dbef7c1361456d1780e15131dbb274760f Mon Sep 17 00:00:00 2001 From: Lubos Date: Sat, 16 Nov 2024 07:40:57 +0800 Subject: [PATCH 05/13] chore: pass plugin.output to path in context.createFile() --- .../openapi-ts/src/plugins/@hey-api/schemas/config.ts | 2 +- .../openapi-ts/src/plugins/@hey-api/schemas/plugin.ts | 4 ++-- .../openapi-ts/src/plugins/@hey-api/services/config.ts | 2 +- .../openapi-ts/src/plugins/@hey-api/services/plugin.ts | 4 ++-- .../src/plugins/@hey-api/transformers/config.ts | 2 +- .../src/plugins/@hey-api/transformers/plugin.ts | 4 ++-- .../openapi-ts/src/plugins/@hey-api/types/config.ts | 2 +- .../openapi-ts/src/plugins/@hey-api/types/plugin.ts | 4 ++-- .../@tanstack/angular-query-experimental/config.ts | 2 +- .../src/plugins/@tanstack/react-query/config.ts | 2 +- .../src/plugins/@tanstack/solid-query/config.ts | 2 +- .../src/plugins/@tanstack/svelte-query/config.ts | 2 +- .../src/plugins/@tanstack/vue-query/config.ts | 2 +- packages/openapi-ts/src/plugins/fastify/config.ts | 2 +- packages/openapi-ts/src/plugins/fastify/plugin.ts | 10 +++++++--- packages/openapi-ts/src/plugins/fastify/types.d.ts | 2 -- 16 files changed, 25 insertions(+), 23 deletions(-) diff --git a/packages/openapi-ts/src/plugins/@hey-api/schemas/config.ts b/packages/openapi-ts/src/plugins/@hey-api/schemas/config.ts index 4dda71041..39704b712 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/schemas/config.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/schemas/config.ts @@ -13,7 +13,7 @@ export const defaultConfig: PluginConfig = { }; /** - * Type helper for Hey API schemas plugin, returns {@link PluginConfig} object + * Type helper for `@hey-api/schemas` plugin, returns {@link PluginConfig} object */ export const defineConfig: DefineConfig = (config) => ({ ...defaultConfig, diff --git a/packages/openapi-ts/src/plugins/@hey-api/schemas/plugin.ts b/packages/openapi-ts/src/plugins/@hey-api/schemas/plugin.ts index 5ae2c8c8a..f4ed62001 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/schemas/plugin.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/schemas/plugin.ts @@ -291,10 +291,10 @@ const schemasV3_1_X = (context: IRContext) => { } }; -export const handler: PluginHandler = ({ context }) => { +export const handler: PluginHandler = ({ context, plugin }) => { context.createFile({ id: schemasId, - path: 'schemas', + path: plugin.output, }); if (context.spec.openapi) { diff --git a/packages/openapi-ts/src/plugins/@hey-api/services/config.ts b/packages/openapi-ts/src/plugins/@hey-api/services/config.ts index 9ba498f03..1069f7348 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/services/config.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/services/config.ts @@ -17,7 +17,7 @@ export const defaultConfig: PluginConfig = { }; /** - * Type helper for Hey API services plugin, returns {@link PluginConfig} object + * Type helper for `@hey-api/services` plugin, returns {@link PluginConfig} object */ export const defineConfig: DefineConfig = (config) => ({ ...defaultConfig, diff --git a/packages/openapi-ts/src/plugins/@hey-api/services/plugin.ts b/packages/openapi-ts/src/plugins/@hey-api/services/plugin.ts index 823564511..0cdcb1c3f 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/services/plugin.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/services/plugin.ts @@ -421,7 +421,7 @@ const generateFlatServices = ({ context }: { context: IRContext }) => { } }; -export const handler: PluginHandler = ({ context }) => { +export const handler: PluginHandler = ({ context, plugin }) => { if (!context.config.client.name) { throw new Error( '🚫 client needs to be set to generate services - which HTTP client do you want to use?', @@ -430,7 +430,7 @@ export const handler: PluginHandler = ({ context }) => { const file = context.createFile({ id: servicesId, - path: 'services', + path: plugin.output, }); const servicesOutput = file.nameWithoutExtension(); diff --git a/packages/openapi-ts/src/plugins/@hey-api/transformers/config.ts b/packages/openapi-ts/src/plugins/@hey-api/transformers/config.ts index 442b4654a..acc9f5343 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/transformers/config.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/transformers/config.ts @@ -13,7 +13,7 @@ export const defaultConfig: PluginConfig = { }; /** - * Type helper for Hey API transformers plugin, returns {@link PluginConfig} object + * Type helper for `@hey-api/transformers`, returns {@link PluginConfig} object */ export const defineConfig: DefineConfig = (config) => ({ ...defaultConfig, diff --git a/packages/openapi-ts/src/plugins/@hey-api/transformers/plugin.ts b/packages/openapi-ts/src/plugins/@hey-api/transformers/plugin.ts index a76e6bbde..d70cf558e 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/transformers/plugin.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/transformers/plugin.ts @@ -356,10 +356,10 @@ const processSchemaType = ({ }; // handles only response transformers for now -export const handler: PluginHandler = ({ context }) => { +export const handler: PluginHandler = ({ context, plugin }) => { const file = context.createFile({ id: transformersId, - path: 'transformers', + path: plugin.output, }); for (const path in context.ir.paths) { diff --git a/packages/openapi-ts/src/plugins/@hey-api/types/config.ts b/packages/openapi-ts/src/plugins/@hey-api/types/config.ts index 4843a8eec..0b1764828 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/types/config.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/types/config.ts @@ -14,7 +14,7 @@ export const defaultConfig: PluginConfig = { }; /** - * Type helper for Hey API types plugin, returns {@link PluginConfig} object + * Type helper for `@hey-api/types` plugin, returns {@link PluginConfig} object */ export const defineConfig: DefineConfig = (config) => ({ ...defaultConfig, diff --git a/packages/openapi-ts/src/plugins/@hey-api/types/plugin.ts b/packages/openapi-ts/src/plugins/@hey-api/types/plugin.ts index 39135b1b6..4f00b524f 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/types/plugin.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/types/plugin.ts @@ -173,10 +173,10 @@ const operationToType = ({ } }; -export const handler: PluginHandler = ({ context }) => { +export const handler: PluginHandler = ({ context, plugin }) => { const file = context.createFile({ id: typesId, - path: 'types', + path: plugin.output, }); const options: SchemaToTypeOptions = { enums: context.config.plugins['@hey-api/types']?.enums, diff --git a/packages/openapi-ts/src/plugins/@tanstack/angular-query-experimental/config.ts b/packages/openapi-ts/src/plugins/@tanstack/angular-query-experimental/config.ts index eb59d68cb..106e71744 100644 --- a/packages/openapi-ts/src/plugins/@tanstack/angular-query-experimental/config.ts +++ b/packages/openapi-ts/src/plugins/@tanstack/angular-query-experimental/config.ts @@ -15,7 +15,7 @@ export const defaultConfig: PluginConfig = { }; /** - * Type helper for TanStack Angular Query Experimental plugin, returns {@link PluginConfig} object + * Type helper for `@tanstack/angular-query-experimental` plugin, returns {@link PluginConfig} object */ export const defineConfig: DefineConfig = (config) => ({ ...defaultConfig, diff --git a/packages/openapi-ts/src/plugins/@tanstack/react-query/config.ts b/packages/openapi-ts/src/plugins/@tanstack/react-query/config.ts index 3374a10c2..296da5ba4 100644 --- a/packages/openapi-ts/src/plugins/@tanstack/react-query/config.ts +++ b/packages/openapi-ts/src/plugins/@tanstack/react-query/config.ts @@ -15,7 +15,7 @@ export const defaultConfig: PluginConfig = { }; /** - * Type helper for TanStack React Query plugin, returns {@link PluginConfig} object + * Type helper for `@tanstack/react-query` plugin, returns {@link PluginConfig} object */ export const defineConfig: DefineConfig = (config) => ({ ...defaultConfig, diff --git a/packages/openapi-ts/src/plugins/@tanstack/solid-query/config.ts b/packages/openapi-ts/src/plugins/@tanstack/solid-query/config.ts index 709651315..087fdcbc0 100644 --- a/packages/openapi-ts/src/plugins/@tanstack/solid-query/config.ts +++ b/packages/openapi-ts/src/plugins/@tanstack/solid-query/config.ts @@ -15,7 +15,7 @@ export const defaultConfig: PluginConfig = { }; /** - * Type helper for TanStack Solid Query plugin, returns {@link PluginConfig} object + * Type helper for `@tanstack/solid-query` plugin, returns {@link PluginConfig} object */ export const defineConfig: DefineConfig = (config) => ({ ...defaultConfig, diff --git a/packages/openapi-ts/src/plugins/@tanstack/svelte-query/config.ts b/packages/openapi-ts/src/plugins/@tanstack/svelte-query/config.ts index 45497987a..fc07b29bb 100644 --- a/packages/openapi-ts/src/plugins/@tanstack/svelte-query/config.ts +++ b/packages/openapi-ts/src/plugins/@tanstack/svelte-query/config.ts @@ -15,7 +15,7 @@ export const defaultConfig: PluginConfig = { }; /** - * Type helper for TanStack Svelte Query plugin, returns {@link PluginConfig} object + * Type helper for `@tanstack/svelte-query` plugin, returns {@link PluginConfig} object */ export const defineConfig: DefineConfig = (config) => ({ ...defaultConfig, diff --git a/packages/openapi-ts/src/plugins/@tanstack/vue-query/config.ts b/packages/openapi-ts/src/plugins/@tanstack/vue-query/config.ts index 482d7c69a..067227ad7 100644 --- a/packages/openapi-ts/src/plugins/@tanstack/vue-query/config.ts +++ b/packages/openapi-ts/src/plugins/@tanstack/vue-query/config.ts @@ -15,7 +15,7 @@ export const defaultConfig: PluginConfig = { }; /** - * Type helper for TanStack Vue Query plugin, returns {@link PluginConfig} object + * Type helper for `@tanstack/vue-query` plugin, returns {@link PluginConfig} object */ export const defineConfig: DefineConfig = (config) => ({ ...defaultConfig, diff --git a/packages/openapi-ts/src/plugins/fastify/config.ts b/packages/openapi-ts/src/plugins/fastify/config.ts index 57d73d84c..f3c198c69 100644 --- a/packages/openapi-ts/src/plugins/fastify/config.ts +++ b/packages/openapi-ts/src/plugins/fastify/config.ts @@ -12,7 +12,7 @@ export const defaultConfig: PluginConfig = { }; /** - * Type helper for the Fastify plugin, returns {@link PluginConfig} object + * Type helper for `fastify` plugin, returns {@link PluginConfig} object */ export const defineConfig: DefineConfig = (config) => ({ ...defaultConfig, diff --git a/packages/openapi-ts/src/plugins/fastify/plugin.ts b/packages/openapi-ts/src/plugins/fastify/plugin.ts index fd1fb1946..82a2646ad 100644 --- a/packages/openapi-ts/src/plugins/fastify/plugin.ts +++ b/packages/openapi-ts/src/plugins/fastify/plugin.ts @@ -17,7 +17,7 @@ import { } from '../utils/types'; import type { Config } from './types'; -const FILE_ID = 'fastify'; +const fastifyId = 'fastify'; const ROUTE_HANDLER_NAME = 'RouteHandler'; const OPERATIONS_IDENTIFIER = 'RouteHandlers'; const ROUTE_PROPERTY_NAME = { @@ -154,7 +154,7 @@ const pathsToType = ({ } } - const identifier = context.file({ id: FILE_ID })!.identifier({ + const identifier = context.file({ id: fastifyId })!.identifier({ $ref: OPERATIONS_IDENTIFIER, create: true, namespace: 'type', @@ -171,7 +171,11 @@ const pathsToType = ({ }; export const handler: PluginHandler = ({ context, plugin }) => { - const file = context.createFile({ id: FILE_ID, path: plugin.output }); + const file = context.createFile({ + id: fastifyId, + path: plugin.output, + }); + const options: SchemaToTypeOptions = { file }; file.import({ asType: true, module: 'fastify', name: ROUTE_HANDLER_NAME }); componentsToType({ diff --git a/packages/openapi-ts/src/plugins/fastify/types.d.ts b/packages/openapi-ts/src/plugins/fastify/types.d.ts index 0af8eb49b..777dc9a76 100644 --- a/packages/openapi-ts/src/plugins/fastify/types.d.ts +++ b/packages/openapi-ts/src/plugins/fastify/types.d.ts @@ -13,5 +13,3 @@ export interface Config extends PluginName<'fastify'> { */ output?: string; } - -export interface UserConfig extends Omit {} -- 2.51.2 From 255c4280737965d8ab401ee0bcfcda4e8948eb4a Mon Sep 17 00:00:00 2001 From: Lubos Date: Sat, 16 Nov 2024 21:42:29 +0800 Subject: [PATCH 06/13] chore: remove unused config option --- packages/openapi-ts/src/ir/schema.ts | 28 ++- .../openapi-ts/src/plugins/fastify/config.ts | 1 - .../openapi-ts/src/plugins/fastify/plugin.ts | 207 ++++++++---------- .../openapi-ts/src/plugins/fastify/types.d.ts | 6 - packages/openapi-ts/test/sample.cjs | 5 +- 5 files changed, 113 insertions(+), 134 deletions(-) diff --git a/packages/openapi-ts/src/ir/schema.ts b/packages/openapi-ts/src/ir/schema.ts index d4e79610f..acafffab5 100644 --- a/packages/openapi-ts/src/ir/schema.ts +++ b/packages/openapi-ts/src/ir/schema.ts @@ -80,27 +80,25 @@ export const irParametersToIrSchema = ({ type: 'object', }; - if (parameters) { - const properties: Record = {}; - const required: Array = []; + const properties: Record = {}; + const required: Array = []; - for (const name in parameters) { - const parameter = parameters[name]; + for (const name in parameters) { + const parameter = parameters[name]; - properties[name] = deduplicateSchema({ - schema: parameter.schema, - }); + properties[name] = deduplicateSchema({ + schema: parameter.schema, + }); - if (parameter.required) { - required.push(name); - } + if (parameter.required) { + required.push(name); } + } - irSchema.properties = properties; + irSchema.properties = properties; - if (required.length) { - irSchema.required = required; - } + if (required.length) { + irSchema.required = required; } return irSchema; diff --git a/packages/openapi-ts/src/plugins/fastify/config.ts b/packages/openapi-ts/src/plugins/fastify/config.ts index f3c198c69..375679c92 100644 --- a/packages/openapi-ts/src/plugins/fastify/config.ts +++ b/packages/openapi-ts/src/plugins/fastify/config.ts @@ -7,7 +7,6 @@ export const defaultConfig: PluginConfig = { _handler: handler, _handlerLegacy: () => {}, name: 'fastify', - operationId: true, output: 'fastify', }; diff --git a/packages/openapi-ts/src/plugins/fastify/plugin.ts b/packages/openapi-ts/src/plugins/fastify/plugin.ts index 82a2646ad..36903f3f3 100644 --- a/packages/openapi-ts/src/plugins/fastify/plugin.ts +++ b/packages/openapi-ts/src/plugins/fastify/plugin.ts @@ -1,68 +1,34 @@ -import ts from 'typescript'; - import { compiler, type Property } from '../../compiler'; import type { IRContext } from '../../ir/context'; import type { IROperationObject, - IRParameterObject, IRPathItemObject, IRPathsObject, } from '../../ir/ir'; import { irParametersToIrSchema } from '../../ir/schema'; import type { PluginHandler } from '../types'; -import { - componentsToType, - schemaToType, - type SchemaToTypeOptions, -} from '../utils/types'; +import { componentsToType, schemaToType } from '../utils/types'; import type { Config } from './types'; const fastifyId = 'fastify'; -const ROUTE_HANDLER_NAME = 'RouteHandler'; -const OPERATIONS_IDENTIFIER = 'RouteHandlers'; -const ROUTE_PROPERTY_NAME = { - BODY: 'Body', - HEADER: 'Headers', - PATH: 'Params', - QUERY: 'Querystring', - RESPONSE: 'Reply', -}; -const NUMERIC_CODE_REGEX = /\b[0-9]{3}\b/; - -const parameterToProperty = ({ - options, - parameter, - name, -}: { - name: string; - options: SchemaToTypeOptions; - parameter: Record; -}): Property => { - const schema = irParametersToIrSchema({ - parameters: parameter, - }); - return { - isRequired: !!schema.required, - name, - type: schemaToType({ options, schema }), - }; -}; -const operationToProperty = ({ +const operationToRouteHandler = ({ + context, operation, - options, }: { + context: IRContext; operation: IROperationObject; - options: SchemaToTypeOptions; }): Property => { - const operationProperties: Array = []; + const file = context.file({ id: fastifyId })!; + + const properties: Array = []; if (operation.body) { - operationProperties.push({ + properties.push({ isRequired: operation.body.required, - name: ROUTE_PROPERTY_NAME.BODY, + name: 'Body', type: schemaToType({ - options, + options: { file }, schema: operation.body.schema, }), }); @@ -70,53 +36,68 @@ const operationToProperty = ({ if (operation.parameters) { if (operation.parameters.header) { - operationProperties.push( - parameterToProperty({ - name: ROUTE_PROPERTY_NAME.HEADER, - options, - parameter: operation.parameters.header, + const schema = irParametersToIrSchema({ + parameters: operation.parameters.header, + }); + properties.push({ + isRequired: Boolean(schema.required), + name: 'Headers', + type: schemaToType({ + options: { file }, + schema, }), - ); + }); } - if (operation.parameters.query) { - operationProperties.push( - parameterToProperty({ - name: ROUTE_PROPERTY_NAME.QUERY, - options, - parameter: operation.parameters.query, + if (operation.parameters.path) { + const schema = irParametersToIrSchema({ + parameters: operation.parameters.path, + }); + properties.push({ + isRequired: Boolean(schema.required), + name: 'Params', + type: schemaToType({ + options: { file }, + schema, }), - ); + }); } - if (operation.parameters.path) { - operationProperties.push( - parameterToProperty({ - name: ROUTE_PROPERTY_NAME.PATH, - options, - parameter: operation.parameters.path, + if (operation.parameters.query) { + const schema = irParametersToIrSchema({ + parameters: operation.parameters.query, + }); + properties.push({ + isRequired: Boolean(schema.required), + name: 'Querystring', + type: schemaToType({ + options: { file }, + schema, }), - ); + }); } } if (operation.responses) { const responseProperties: Array = []; + for (const code in operation.responses) { - if (code === 'default') continue; - const response = operation.responses[code]; + if (code === 'default') { + continue; + } + + const response = operation.responses[code]!; responseProperties.push({ - name: NUMERIC_CODE_REGEX.test(code) - ? ts.factory.createNumericLiteral(code) - : code, + name: code, type: schemaToType({ - options, - schema: response?.schema ?? {}, + options: { file }, + schema: response.schema, }), }); } - operationProperties.push({ - name: ROUTE_PROPERTY_NAME.RESPONSE, + + properties.push({ + name: 'Reply', type: compiler.typeInterfaceNode({ properties: responseProperties, useLegacyResolution: false, @@ -124,50 +105,52 @@ const operationToProperty = ({ }); } - const operationType = compiler.typeInterfaceNode({ - properties: operationProperties, - useLegacyResolution: false, - }); - const property: Property = { + const routeHandler: Property = { name: operation.id, - type: compiler.typeNode(ROUTE_HANDLER_NAME, [operationType]), + type: compiler.typeNode('RouteHandler', [ + compiler.typeInterfaceNode({ + properties, + useLegacyResolution: false, + }), + ]), }; - return property; + return routeHandler; }; -const pathsToType = ({ - context, - options, -}: { - context: IRContext; - options: SchemaToTypeOptions; -}): ts.Node => { - const operationsProperties = []; +const processRouteHandlers = ({ context }: { context: IRContext }) => { + const file = context.file({ id: fastifyId })!; + + const routeHandlers: Array = []; + for (const path in context.ir.paths) { const pathItem = context.ir.paths[path as keyof IRPathsObject]; - for (const method in pathItem) { - const operation = pathItem[method as keyof IRPathItemObject]; - if (operation) { - const operationProperty = operationToProperty({ operation, options }); - operationsProperties.push(operationProperty); - } + + for (const _method in pathItem) { + const method = _method as keyof IRPathItemObject; + const operation = pathItem[method]!; + + const routeHandler = operationToRouteHandler({ context, operation }); + routeHandlers.push(routeHandler); } } - const identifier = context.file({ id: fastifyId })!.identifier({ - $ref: OPERATIONS_IDENTIFIER, + const identifier = file.identifier({ + $ref: 'RouteHandlers', create: true, namespace: 'type', }); - const paths = compiler.typeAliasDeclaration({ - exportType: true, - name: identifier.name || '', - type: compiler.typeInterfaceNode({ - properties: operationsProperties, - useLegacyResolution: false, - }), - }); - return paths; + if (identifier.name) { + file.add( + compiler.typeAliasDeclaration({ + exportType: true, + name: identifier.name, + type: compiler.typeInterfaceNode({ + properties: routeHandlers, + useLegacyResolution: false, + }), + }), + ); + } }; export const handler: PluginHandler = ({ context, plugin }) => { @@ -175,12 +158,16 @@ export const handler: PluginHandler = ({ context, plugin }) => { id: fastifyId, path: plugin.output, }); - - const options: SchemaToTypeOptions = { file }; - file.import({ asType: true, module: 'fastify', name: ROUTE_HANDLER_NAME }); + file.import({ + asType: true, + module: 'fastify', + name: 'RouteHandler', + }); componentsToType({ context, - options, + options: { + file, + }, }); - file.add(pathsToType({ context, options })); + processRouteHandlers({ context }); }; diff --git a/packages/openapi-ts/src/plugins/fastify/types.d.ts b/packages/openapi-ts/src/plugins/fastify/types.d.ts index 777dc9a76..378aa47c6 100644 --- a/packages/openapi-ts/src/plugins/fastify/types.d.ts +++ b/packages/openapi-ts/src/plugins/fastify/types.d.ts @@ -1,12 +1,6 @@ import type { PluginName } from '../types'; export interface Config extends PluginName<'fastify'> { - // TODO: parser - rename operationId option to something like inferId?: boolean - /** - * Use operation ID to generate operation names? - * @default true - */ - operationId?: boolean; /** * Name of the generated file. * @default 'fastify' diff --git a/packages/openapi-ts/test/sample.cjs b/packages/openapi-ts/test/sample.cjs index 4b0f5d5e0..241cbbed4 100644 --- a/packages/openapi-ts/test/sample.cjs +++ b/packages/openapi-ts/test/sample.cjs @@ -13,8 +13,8 @@ const main = async () => { input: { // include: // '^(#/components/schemas/import|#/paths/api/v{api-version}/simple/options)$', - path: './test/spec/3.1.x/discriminator-one-of.yaml', - // path: './test/spec/3.0.x/full.json', + // path: './test/spec/3.1.x/discriminator-one-of.yaml', + path: './test/spec/3.0.x/full.json', // path: 'https://mongodb-mms-prod-build-server.s3.amazonaws.com/openapi/2caffd88277a4e27c95dcefc7e3b6a63a3b03297-v2-2023-11-15.json', }, // name: 'foo', @@ -51,6 +51,7 @@ const main = async () => { }, { // name: 'zod', + name: 'fastify', }, ], // useOptions: false, -- 2.51.2 From 715d5a81cf76dc37ff8419af8899f4043fd38893 Mon Sep 17 00:00:00 2001 From: Lubos Date: Sun, 17 Nov 2024 12:29:54 +0800 Subject: [PATCH 07/13] chore: use exported data types --- packages/openapi-ts/src/ir/parameter.ts | 38 +- packages/openapi-ts/src/ir/schema.ts | 35 +- .../src/plugins/@hey-api/types/plugin.ts | 38 +- .../openapi-ts/src/plugins/fastify/config.ts | 2 +- .../openapi-ts/src/plugins/fastify/plugin.ts | 106 ++-- .../plugins/fastify/default/fastify.gen.ts | 475 +++--------------- .../plugins/fastify/default/fastify.gen.ts | 475 +++--------------- 7 files changed, 282 insertions(+), 887 deletions(-) diff --git a/packages/openapi-ts/src/ir/parameter.ts b/packages/openapi-ts/src/ir/parameter.ts index 3975e6884..6eadad1fc 100644 --- a/packages/openapi-ts/src/ir/parameter.ts +++ b/packages/openapi-ts/src/ir/parameter.ts @@ -1,6 +1,18 @@ -import type { IRParametersObject } from './ir'; +import type { IRParameterObject, IRParametersObject } from './ir'; import type { Pagination } from './pagination'; +export const hasParameterGroupObjectRequired = ( + parameterGroup?: Record, +): boolean => { + for (const name in parameterGroup) { + if (parameterGroup[name].required) { + return true; + } + } + + return false; +}; + export const hasParametersObjectRequired = ( parameters: IRParametersObject | undefined, ): boolean => { @@ -8,28 +20,20 @@ export const hasParametersObjectRequired = ( return false; } - for (const name in parameters.cookie) { - if (parameters.cookie[name].required) { - return true; - } + if (hasParameterGroupObjectRequired(parameters.cookie)) { + return true; } - for (const name in parameters.header) { - if (parameters.header[name].required) { - return true; - } + if (hasParameterGroupObjectRequired(parameters.header)) { + return true; } - for (const name in parameters.path) { - if (parameters.path[name].required) { - return true; - } + if (hasParameterGroupObjectRequired(parameters.path)) { + return true; } - for (const name in parameters.query) { - if (parameters.query[name].required) { - return true; - } + if (hasParameterGroupObjectRequired(parameters.query)) { + return true; } return false; diff --git a/packages/openapi-ts/src/ir/schema.ts b/packages/openapi-ts/src/ir/schema.ts index acafffab5..045c00d21 100644 --- a/packages/openapi-ts/src/ir/schema.ts +++ b/packages/openapi-ts/src/ir/schema.ts @@ -1,4 +1,4 @@ -import type { IRParameterObject, IRSchemaObject } from './ir'; +import type { IRSchemaObject } from './ir'; /** * Ensure we don't produce redundant types, e.g. string | string. @@ -70,36 +70,3 @@ export const deduplicateSchema = ({ return schema; }; - -export const irParametersToIrSchema = ({ - parameters, -}: { - parameters: Record; -}): IRSchemaObject => { - const irSchema: IRSchemaObject = { - type: 'object', - }; - - const properties: Record = {}; - const required: Array = []; - - for (const name in parameters) { - const parameter = parameters[name]; - - properties[name] = deduplicateSchema({ - schema: parameter.schema, - }); - - if (parameter.required) { - required.push(name); - } - } - - irSchema.properties = properties; - - if (required.length) { - irSchema.required = required; - } - - return irSchema; -}; diff --git a/packages/openapi-ts/src/plugins/@hey-api/types/plugin.ts b/packages/openapi-ts/src/plugins/@hey-api/types/plugin.ts index 4f00b524f..7e88a15d0 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/types/plugin.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/types/plugin.ts @@ -2,12 +2,13 @@ import { compiler } from '../../../compiler'; import type { IRContext } from '../../../ir/context'; import type { IROperationObject, + IRParameterObject, IRPathItemObject, IRPathsObject, IRSchemaObject, } from '../../../ir/ir'; import { operationResponsesMap } from '../../../ir/operation'; -import { irParametersToIrSchema } from '../../../ir/schema'; +import { deduplicateSchema } from '../../../ir/schema'; import type { PluginHandler } from '../../types'; import { componentsToType, @@ -23,6 +24,41 @@ import type { Config } from './types'; export const typesId = 'types'; +const irParametersToIrSchema = ({ + parameters, +}: { + parameters: Record; +}): IRSchemaObject => { + const irSchema: IRSchemaObject = { + type: 'object', + }; + + if (parameters) { + const properties: Record = {}; + const required: Array = []; + + for (const name in parameters) { + const parameter = parameters[name]; + + properties[name] = deduplicateSchema({ + schema: parameter.schema, + }); + + if (parameter.required) { + required.push(name); + } + } + + irSchema.properties = properties; + + if (required.length) { + irSchema.required = required; + } + } + + return irSchema; +}; + const operationToDataType = ({ context, operation, diff --git a/packages/openapi-ts/src/plugins/fastify/config.ts b/packages/openapi-ts/src/plugins/fastify/config.ts index 375679c92..d123a8f83 100644 --- a/packages/openapi-ts/src/plugins/fastify/config.ts +++ b/packages/openapi-ts/src/plugins/fastify/config.ts @@ -3,7 +3,7 @@ import { handler } from './plugin'; import type { Config } from './types'; export const defaultConfig: PluginConfig = { - _dependencies: ['@hey-api/services'], + _dependencies: ['@hey-api/types', '@hey-api/services'], _handler: handler, _handlerLegacy: () => {}, name: 'fastify', diff --git a/packages/openapi-ts/src/plugins/fastify/plugin.ts b/packages/openapi-ts/src/plugins/fastify/plugin.ts index 36903f3f3..341016036 100644 --- a/packages/openapi-ts/src/plugins/fastify/plugin.ts +++ b/packages/openapi-ts/src/plugins/fastify/plugin.ts @@ -5,7 +5,8 @@ import type { IRPathItemObject, IRPathsObject, } from '../../ir/ir'; -import { irParametersToIrSchema } from '../../ir/schema'; +import { hasParameterGroupObjectRequired } from '../../ir/parameter'; +import { operationDataRef } from '../@hey-api/services/plugin'; import type { PluginHandler } from '../types'; import { componentsToType, schemaToType } from '../utils/types'; import type { Config } from './types'; @@ -23,58 +24,70 @@ const operationToRouteHandler = ({ const properties: Array = []; - if (operation.body) { - properties.push({ - isRequired: operation.body.required, - name: 'Body', - type: schemaToType({ - options: { file }, - schema: operation.body.schema, - }), - }); - } + const identifierData = context.file({ id: 'types' })!.identifier({ + $ref: operationDataRef({ id: operation.id }), + namespace: 'type', + }); - if (operation.parameters) { - if (operation.parameters.header) { - const schema = irParametersToIrSchema({ - parameters: operation.parameters.header, + if (identifierData.name) { + if (operation.body) { + file.import({ + asType: true, + module: file.relativePathToFile({ context, id: 'types' }), + name: identifierData.name, }); properties.push({ - isRequired: Boolean(schema.required), - name: 'Headers', - type: schemaToType({ - options: { file }, - schema, - }), + isRequired: operation.body.required, + name: 'Body', + type: `${identifierData.name}['body']`, }); } - if (operation.parameters.path) { - const schema = irParametersToIrSchema({ - parameters: operation.parameters.path, - }); - properties.push({ - isRequired: Boolean(schema.required), - name: 'Params', - type: schemaToType({ - options: { file }, - schema, - }), - }); - } + if (operation.parameters) { + if (operation.parameters.header) { + file.import({ + asType: true, + module: file.relativePathToFile({ context, id: 'types' }), + name: identifierData.name, + }); + properties.push({ + isRequired: hasParameterGroupObjectRequired( + operation.parameters.header, + ), + name: 'Headers', + type: `${identifierData.name}['headers']`, + }); + } - if (operation.parameters.query) { - const schema = irParametersToIrSchema({ - parameters: operation.parameters.query, - }); - properties.push({ - isRequired: Boolean(schema.required), - name: 'Querystring', - type: schemaToType({ - options: { file }, - schema, - }), - }); + if (operation.parameters.path) { + file.import({ + asType: true, + module: file.relativePathToFile({ context, id: 'types' }), + name: identifierData.name, + }); + properties.push({ + isRequired: hasParameterGroupObjectRequired( + operation.parameters.path, + ), + name: 'Params', + type: `${identifierData.name}['path']`, + }); + } + + if (operation.parameters.query) { + file.import({ + asType: true, + module: file.relativePathToFile({ context, id: 'types' }), + name: identifierData.name, + }); + properties.push({ + isRequired: hasParameterGroupObjectRequired( + operation.parameters.query, + ), + name: 'Querystring', + type: `${identifierData.name}['query']`, + }); + } } } @@ -87,6 +100,7 @@ const operationToRouteHandler = ({ } const response = operation.responses[code]!; + // TODO: numeric literal for numbers responseProperties.push({ name: code, type: schemaToType({ diff --git a/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/fastify/default/fastify.gen.ts b/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/fastify/default/fastify.gen.ts index ab34859ed..586d7eb87 100644 --- a/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/fastify/default/fastify.gen.ts +++ b/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/fastify/default/fastify.gen.ts @@ -1,6 +1,7 @@ // This file is auto-generated by @hey-api/openapi-ts import type { RouteHandler } from 'fastify'; +import type { ImportData, GetApiVbyApiVersionSimpleOperationData, DeleteFooData3, CallWithDescriptionsData, DeprecatedCallData, CallWithParametersData, CallWithWeirdParameterNamesData, GetCallWithOptionalParamData, PostCallWithOptionalParamData, PostApiVbyApiVersionRequestBodyData, PostApiVbyApiVersionFormDataData, CallWithDefaultParametersData, CallWithDefaultOptionalParametersData, CallToTestOrderOfParamsData, CollectionFormatData, TypesData, UploadFileData, FileResponseData, ComplexTypesData, MultipartRequestData, ComplexParamsData, TestErrorCodeData, NonAsciiæøåÆøÅöôêÊ字符串Data, PutWithFormUrlEncodedData } from './types.gen'; /** * Model with number-only name @@ -948,25 +949,20 @@ export type x_Foo_Bar = ModelWithString; export type RouteHandlers = { export: RouteHandler<{}>; import: RouteHandler<{ - Body: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; + Body: ImportData['body']; Reply: { - 200: Model_From_Zendesk; + '200': Model_From_Zendesk; }; }>; apiVVersionOdataControllerCount: RouteHandler<{ Reply: { - 200: Model_From_Zendesk; + '200': Model_From_Zendesk; }; }>; getApiVbyApiVersionSimpleOperation: RouteHandler<{ - Params: { - /** - * foo in method - */ - foo_param: string; - }; + Params: GetApiVbyApiVersionSimpleOperationData['path']; Reply: { - 200: number; + '200': number; }; }>; deleteCallWithoutParametersAndResponse: RouteHandler<{}>; @@ -977,252 +973,55 @@ export type RouteHandlers = { postCallWithoutParametersAndResponse: RouteHandler<{}>; putCallWithoutParametersAndResponse: RouteHandler<{}>; deleteFoo: RouteHandler<{ - Headers: { - /** - * Parameter with illegal characters - */ - 'x-Foo-Bar': ModelWithString; - }; - Params: { - /** - * foo in method - */ - foo_param: string; - /** - * bar in method - */ - BarParam: string; - }; + Headers: DeleteFooData3['headers']; + Params: DeleteFooData3['path']; }>; callWithDescriptions: RouteHandler<{ - Querystring?: { - /** - * Testing multiline comments in string: First line - * Second line - * - * Fourth line - */ - parameterWithBreaks?: string; - /** - * Testing backticks in string: `backticks` and ```multiple backticks``` should work - */ - parameterWithBackticks?: string; - /** - * Testing slashes in string: \backwards\\\ and /forwards/// should work - */ - parameterWithSlashes?: string; - /** - * Testing expression placeholders in string: ${expression} should work - */ - parameterWithExpressionPlaceholders?: string; - /** - * Testing quotes in string: 'single quote''' and "double quotes""" should work - */ - parameterWithQuotes?: string; - /** - * Testing reserved characters in string: * inline * and ** inline ** should work - */ - parameterWithReservedCharacters?: string; - }; + Querystring?: CallWithDescriptionsData['query']; }>; deprecatedCall: RouteHandler<{ - Headers: { - /** - * This parameter is deprecated - * @deprecated - */ - parameter: DeprecatedModel | null; - }; + Headers: DeprecatedCallData['headers']; }>; callWithParameters: RouteHandler<{ - Body: {} | null; - Headers: { - /** - * This is the parameter that goes into the header - */ - parameterHeader: string | null; - }; - Querystring: { - foo_ref_enum?: ModelWithNestedArrayEnumsDataFoo; - foo_all_of_enum: ModelWithNestedArrayEnumsDataFoo; - /** - * This is the parameter that goes into the query params - */ - cursor: string | null; - }; - Params: { - /** - * This is the parameter that goes into the path - */ - parameterPath: string | null; - /** - * api-version should be required in standalone clients - */ - 'api-version': string | null; - }; + Body: CallWithParametersData['body']; + Headers: CallWithParametersData['headers']; + Params: CallWithParametersData['path']; + Querystring: CallWithParametersData['query']; }>; callWithWeirdParameterNames: RouteHandler<{ - Body: ModelWithString | null; - Headers: { - /** - * This is the parameter that goes into the request header - */ - 'parameter.header': string | null; - }; - Querystring: { - /** - * This is the parameter with a reserved keyword - */ - default?: string; - /** - * This is the parameter that goes into the request query params - */ - 'parameter-query': string | null; - }; - Params: { - /** - * This is the parameter that goes into the path - */ - 'parameter.path.1'?: string; - /** - * This is the parameter that goes into the path - */ - 'parameter-path-2'?: string; - /** - * This is the parameter that goes into the path - */ - 'PARAMETER-PATH-3'?: string; - /** - * api-version should be required in standalone clients - */ - 'api-version': string | null; - }; + Body: CallWithWeirdParameterNamesData['body']; + Headers: CallWithWeirdParameterNamesData['headers']; + Params: CallWithWeirdParameterNamesData['path']; + Querystring: CallWithWeirdParameterNamesData['query']; }>; getCallWithOptionalParam: RouteHandler<{ - Body: ModelWithOneOfEnum; - Querystring?: { - /** - * This is an optional parameter - */ - page?: number; - }; + Body: GetCallWithOptionalParamData['body']; + Querystring?: GetCallWithOptionalParamData['query']; }>; postCallWithOptionalParam: RouteHandler<{ - Body: { - offset?: number | null; - }; - Querystring: { - /** - * This is a required parameter - */ - parameter: Pageable; - }; + Body: PostCallWithOptionalParamData['body']; + Querystring: PostCallWithOptionalParamData['query']; Reply: { - 200: number; - 204: void; + '200': number; + '204': void; }; }>; postApiVbyApiVersionRequestBody: RouteHandler<{ - Body: ModelWithString; - Querystring?: { - /** - * This is a reusable parameter - */ - parameter?: string; - }; + Body: PostApiVbyApiVersionRequestBodyData['body']; + Querystring?: PostApiVbyApiVersionRequestBodyData['query']; }>; postApiVbyApiVersionFormData: RouteHandler<{ - Body: ModelWithString; - Querystring?: { - /** - * This is a reusable parameter - */ - parameter?: string; - }; + Body: PostApiVbyApiVersionFormDataData['body']; + Querystring?: PostApiVbyApiVersionFormDataData['query']; }>; callWithDefaultParameters: RouteHandler<{ - Querystring?: { - /** - * This is a simple string with default value - */ - parameterString?: string | null; - /** - * This is a simple number with default value - */ - parameterNumber?: number | null; - /** - * This is a simple boolean with default value - */ - parameterBoolean?: boolean | null; - /** - * This is a simple enum with default value - */ - parameterEnum?: 'Success' | 'Warning' | 'Error'; - /** - * This is a simple model with default value - */ - parameterModel?: ModelWithString | null; - }; + Querystring?: CallWithDefaultParametersData['query']; }>; callWithDefaultOptionalParameters: RouteHandler<{ - Querystring?: { - /** - * This is a simple string that is optional with default value - */ - parameterString?: string; - /** - * This is a simple number that is optional with default value - */ - parameterNumber?: number; - /** - * This is a simple boolean that is optional with default value - */ - parameterBoolean?: boolean; - /** - * This is a simple enum that is optional with default value - */ - parameterEnum?: 'Success' | 'Warning' | 'Error'; - /** - * This is a simple model that is optional with default value - */ - parameterModel?: ModelWithString; - }; + Querystring?: CallWithDefaultOptionalParametersData['query']; }>; callToTestOrderOfParams: RouteHandler<{ - Querystring: { - /** - * This is a optional string with default - */ - parameterOptionalStringWithDefault?: string; - /** - * This is a optional string with empty default - */ - parameterOptionalStringWithEmptyDefault?: string; - /** - * This is a optional string with no default - */ - parameterOptionalStringWithNoDefault?: string; - /** - * This is a string with default - */ - parameterStringWithDefault: string; - /** - * This is a string with empty default - */ - parameterStringWithEmptyDefault: string; - /** - * This is a string with no default - */ - parameterStringWithNoDefault: string; - /** - * This is a string that can be null with no default - */ - parameterStringNullableWithNoDefault?: string | null; - /** - * This is a string that can be null with default - */ - parameterStringNullableWithDefault?: string | null; - }; + Querystring: CallToTestOrderOfParamsData['query']; }>; duplicateName: RouteHandler<{}>; duplicateName2: RouteHandler<{}>; @@ -1230,23 +1029,23 @@ export type RouteHandlers = { duplicateName4: RouteHandler<{}>; callWithNoContentResponse: RouteHandler<{ Reply: { - 204: void; + '204': void; }; }>; callWithResponseAndNoContentResponse: RouteHandler<{ Reply: { - 200: number; - 204: void; + '200': number; + '204': void; }; }>; dummyA: RouteHandler<{ Reply: { - 200: _400; + '200': _400; }; }>; dummyB: RouteHandler<{ Reply: { - 204: void; + '204': void; }; }>; callWithResponse: RouteHandler<{ @@ -1254,147 +1053,66 @@ export type RouteHandlers = { }>; callWithDuplicateResponses: RouteHandler<{ Reply: { - 200: ModelWithBoolean & ModelWithInteger; - 201: ModelWithString; - 202: ModelWithString; - 500: ModelWithStringError; - 501: ModelWithStringError; - 502: ModelWithStringError; + '200': ModelWithBoolean & ModelWithInteger; + '201': ModelWithString; + '202': ModelWithString; + '500': ModelWithStringError; + '501': ModelWithStringError; + '502': ModelWithStringError; '4XX': DictionaryWithArray; }; }>; callWithResponses: RouteHandler<{ Reply: { - 200: { + '200': { readonly '@namespace.string'?: string; readonly '@namespace.integer'?: number; readonly value?: Array; }; - 201: ModelThatExtends; - 202: ModelThatExtendsExtends; - 500: ModelWithStringError; - 501: ModelWithStringError; - 502: ModelWithStringError; + '201': ModelThatExtends; + '202': ModelThatExtendsExtends; + '500': ModelWithStringError; + '501': ModelWithStringError; + '502': ModelWithStringError; }; }>; collectionFormat: RouteHandler<{ - Querystring: { - /** - * This is an array parameter that is sent as csv format (comma-separated values) - */ - parameterArrayCSV: Array | null; - /** - * This is an array parameter that is sent as ssv format (space-separated values) - */ - parameterArraySSV: Array | null; - /** - * This is an array parameter that is sent as tsv format (tab-separated values) - */ - parameterArrayTSV: Array | null; - /** - * This is an array parameter that is sent as pipes format (pipe-separated values) - */ - parameterArrayPipes: Array | null; - /** - * This is an array parameter that is sent as multi format (multiple parameter instances) - */ - parameterArrayMulti: Array | null; - }; + Querystring: CollectionFormatData['query']; }>; types: RouteHandler<{ - Querystring: { - /** - * This is a number parameter - */ - parameterNumber: number; - /** - * This is a string parameter - */ - parameterString: string | null; - /** - * This is a boolean parameter - */ - parameterBoolean: boolean | null; - /** - * This is an object parameter - */ - parameterObject: {} | null; - /** - * This is an array parameter - */ - parameterArray: Array | null; - /** - * This is a dictionary parameter - */ - parameterDictionary: {} | null; - /** - * This is an enum parameter - */ - parameterEnum: 'Success' | 'Warning' | 'Error'; - }; - Params?: { - /** - * This is a number parameter - */ - id?: number; - }; + Params?: TypesData['path']; + Querystring: TypesData['query']; Reply: { - 200: number; - 201: string; - 202: boolean; - 203: {}; + '200': number; + '201': string; + '202': boolean; + '203': {}; }; }>; uploadFile: RouteHandler<{ - Body: Blob | File; - Params: { - /** - * api-version should be required in standalone clients - */ - 'api-version': string | null; - }; + Body: UploadFileData['body']; + Params: UploadFileData['path']; Reply: { - 200: boolean; + '200': boolean; }; }>; fileResponse: RouteHandler<{ - Params: { - id: string; - /** - * api-version should be required in standalone clients - */ - 'api-version': string; - }; + Params: FileResponseData['path']; Reply: { - 200: Blob | File; + '200': Blob | File; }; }>; complexTypes: RouteHandler<{ - Querystring: { - /** - * Parameter containing object - */ - parameterObject: { - first?: { - second?: { - third?: string; - }; - }; - }; - /** - * Parameter containing reference - */ - parameterReference: ModelWithString; - }; + Querystring: ComplexTypesData['query']; Reply: { - 200: Array; - 400: unknown; - 500: unknown; + '200': Array; + '400': unknown; + '500': unknown; }; }>; multipartResponse: RouteHandler<{ Reply: { - 200: { + '200': { file?: Blob | File; metadata?: { foo?: string; @@ -1404,70 +1122,39 @@ export type RouteHandlers = { }; }>; multipartRequest: RouteHandler<{ - Body: { - content?: Blob | File; - data?: ModelWithString | null; - }; + Body: MultipartRequestData['body']; }>; complexParams: RouteHandler<{ - Body: { - readonly key: string | null; - name: string | null; - enabled?: boolean; - type: 'Monkey' | 'Horse' | 'Bird'; - listOfModels?: Array | null; - listOfStrings?: Array | null; - parameters: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; - readonly user?: { - readonly id?: number; - readonly name?: string | null; - }; - }; - Params: { - id: number; - /** - * api-version should be required in standalone clients - */ - 'api-version': string; - }; + Body: ComplexParamsData['body']; + Params: ComplexParamsData['path']; Reply: { - 200: ModelWithString; + '200': ModelWithString; }; }>; callWithResultFromHeader: RouteHandler<{ Reply: { - 200: unknown; - 400: unknown; - 500: unknown; + '200': unknown; + '400': unknown; + '500': unknown; }; }>; testErrorCode: RouteHandler<{ - Querystring: { - /** - * Status code to return - */ - status: number; - }; + Querystring: TestErrorCodeData['query']; Reply: { - 200: unknown; - 500: unknown; - 501: unknown; - 502: unknown; - 503: unknown; + '200': unknown; + '500': unknown; + '501': unknown; + '502': unknown; + '503': unknown; }; }>; nonAsciiæøåÆøÅöôêÊ字符串: RouteHandler<{ - Querystring: { - /** - * Dummy input param - */ - nonAsciiParamæøåÆØÅöôêÊ: number; - }; + Querystring: NonAsciiæøåÆøÅöôêÊ字符串Data['query']; Reply: { - 200: Array; + '200': Array; }; }>; putWithFormUrlEncoded: RouteHandler<{ - Body: ArrayWithStrings; + Body: PutWithFormUrlEncodedData['body']; }>; }; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/fastify/default/fastify.gen.ts b/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/fastify/default/fastify.gen.ts index b44c6b530..1729a59ed 100644 --- a/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/fastify/default/fastify.gen.ts +++ b/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/fastify/default/fastify.gen.ts @@ -1,6 +1,7 @@ // This file is auto-generated by @hey-api/openapi-ts import type { RouteHandler } from 'fastify'; +import type { ImportData, GetApiVbyApiVersionSimpleOperationData, DeleteFooData3, CallWithDescriptionsData, DeprecatedCallData, CallWithParametersData, CallWithWeirdParameterNamesData, GetCallWithOptionalParamData, PostCallWithOptionalParamData, PostApiVbyApiVersionRequestBodyData, PostApiVbyApiVersionFormDataData, CallWithDefaultParametersData, CallWithDefaultOptionalParametersData, CallToTestOrderOfParamsData, CollectionFormatData, TypesData, UploadFileData, FileResponseData, ComplexTypesData, MultipartRequestData, ComplexParamsData, TestErrorCodeData, NonAsciiæøåÆøÅöôêÊ字符串Data, PutWithFormUrlEncodedData } from './types.gen'; /** * Model with number-only name @@ -952,25 +953,20 @@ export type x_Foo_Bar = ModelWithString; export type RouteHandlers = { export: RouteHandler<{}>; import: RouteHandler<{ - Body: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; + Body: ImportData['body']; Reply: { - 200: Model_From_Zendesk; + '200': Model_From_Zendesk; }; }>; apiVVersionOdataControllerCount: RouteHandler<{ Reply: { - 200: Model_From_Zendesk; + '200': Model_From_Zendesk; }; }>; getApiVbyApiVersionSimpleOperation: RouteHandler<{ - Params: { - /** - * foo in method - */ - foo_param: unknown; - }; + Params: GetApiVbyApiVersionSimpleOperationData['path']; Reply: { - 200: number; + '200': number; }; }>; deleteCallWithoutParametersAndResponse: RouteHandler<{}>; @@ -981,252 +977,55 @@ export type RouteHandlers = { postCallWithoutParametersAndResponse: RouteHandler<{}>; putCallWithoutParametersAndResponse: RouteHandler<{}>; deleteFoo: RouteHandler<{ - Headers: { - /** - * Parameter with illegal characters - */ - 'x-Foo-Bar': ModelWithString; - }; - Params: { - /** - * foo in method - */ - foo_param: string; - /** - * bar in method - */ - BarParam: string; - }; + Headers: DeleteFooData3['headers']; + Params: DeleteFooData3['path']; }>; callWithDescriptions: RouteHandler<{ - Querystring?: { - /** - * Testing multiline comments in string: First line - * Second line - * - * Fourth line - */ - parameterWithBreaks?: string; - /** - * Testing backticks in string: `backticks` and ```multiple backticks``` should work - */ - parameterWithBackticks?: string; - /** - * Testing slashes in string: \backwards\\\ and /forwards/// should work - */ - parameterWithSlashes?: string; - /** - * Testing expression placeholders in string: ${expression} should work - */ - parameterWithExpressionPlaceholders?: string; - /** - * Testing quotes in string: 'single quote''' and "double quotes""" should work - */ - parameterWithQuotes?: string; - /** - * Testing reserved characters in string: * inline * and ** inline ** should work - */ - parameterWithReservedCharacters?: string; - }; + Querystring?: CallWithDescriptionsData['query']; }>; deprecatedCall: RouteHandler<{ - Headers: { - /** - * This parameter is deprecated - * @deprecated - */ - parameter: DeprecatedModel | null; - }; + Headers: DeprecatedCallData['headers']; }>; callWithParameters: RouteHandler<{ - Body: {} | null; - Headers: { - /** - * This is the parameter that goes into the header - */ - parameterHeader: string | null; - }; - Querystring: { - foo_ref_enum?: ModelWithNestedArrayEnumsDataFoo; - foo_all_of_enum: ModelWithNestedArrayEnumsDataFoo; - /** - * This is the parameter that goes into the query params - */ - cursor: string | null; - }; - Params: { - /** - * This is the parameter that goes into the path - */ - parameterPath: string | null; - /** - * api-version should be required in standalone clients - */ - 'api-version': string | null; - }; + Body: CallWithParametersData['body']; + Headers: CallWithParametersData['headers']; + Params: CallWithParametersData['path']; + Querystring: CallWithParametersData['query']; }>; callWithWeirdParameterNames: RouteHandler<{ - Body: ModelWithString | null; - Headers: { - /** - * This is the parameter that goes into the request header - */ - 'parameter.header': string | null; - }; - Querystring: { - /** - * This is the parameter with a reserved keyword - */ - default?: string; - /** - * This is the parameter that goes into the request query params - */ - 'parameter-query': string | null; - }; - Params: { - /** - * This is the parameter that goes into the path - */ - 'parameter.path.1'?: string; - /** - * This is the parameter that goes into the path - */ - 'parameter-path-2'?: string; - /** - * This is the parameter that goes into the path - */ - 'PARAMETER-PATH-3'?: string; - /** - * api-version should be required in standalone clients - */ - 'api-version': string | null; - }; + Body: CallWithWeirdParameterNamesData['body']; + Headers: CallWithWeirdParameterNamesData['headers']; + Params: CallWithWeirdParameterNamesData['path']; + Querystring: CallWithWeirdParameterNamesData['query']; }>; getCallWithOptionalParam: RouteHandler<{ - Body: ModelWithOneOfEnum; - Querystring?: { - /** - * This is an optional parameter - */ - page?: number; - }; + Body: GetCallWithOptionalParamData['body']; + Querystring?: GetCallWithOptionalParamData['query']; }>; postCallWithOptionalParam: RouteHandler<{ - Body: { - offset?: number | null; - }; - Querystring: { - /** - * This is a required parameter - */ - parameter: Pageable; - }; + Body: PostCallWithOptionalParamData['body']; + Querystring: PostCallWithOptionalParamData['query']; Reply: { - 200: number; - 204: void; + '200': number; + '204': void; }; }>; postApiVbyApiVersionRequestBody: RouteHandler<{ - Body: ModelWithString; - Querystring?: { - /** - * This is a reusable parameter - */ - parameter?: string; - }; + Body: PostApiVbyApiVersionRequestBodyData['body']; + Querystring?: PostApiVbyApiVersionRequestBodyData['query']; }>; postApiVbyApiVersionFormData: RouteHandler<{ - Body: ModelWithString; - Querystring?: { - /** - * This is a reusable parameter - */ - parameter?: string; - }; + Body: PostApiVbyApiVersionFormDataData['body']; + Querystring?: PostApiVbyApiVersionFormDataData['query']; }>; callWithDefaultParameters: RouteHandler<{ - Querystring?: { - /** - * This is a simple string with default value - */ - parameterString?: string | null; - /** - * This is a simple number with default value - */ - parameterNumber?: number | null; - /** - * This is a simple boolean with default value - */ - parameterBoolean?: boolean | null; - /** - * This is a simple enum with default value - */ - parameterEnum?: 'Success' | 'Warning' | 'Error'; - /** - * This is a simple model with default value - */ - parameterModel?: ModelWithString | null; - }; + Querystring?: CallWithDefaultParametersData['query']; }>; callWithDefaultOptionalParameters: RouteHandler<{ - Querystring?: { - /** - * This is a simple string that is optional with default value - */ - parameterString?: string; - /** - * This is a simple number that is optional with default value - */ - parameterNumber?: number; - /** - * This is a simple boolean that is optional with default value - */ - parameterBoolean?: boolean; - /** - * This is a simple enum that is optional with default value - */ - parameterEnum?: 'Success' | 'Warning' | 'Error'; - /** - * This is a simple model that is optional with default value - */ - parameterModel?: ModelWithString; - }; + Querystring?: CallWithDefaultOptionalParametersData['query']; }>; callToTestOrderOfParams: RouteHandler<{ - Querystring: { - /** - * This is a optional string with default - */ - parameterOptionalStringWithDefault?: string; - /** - * This is a optional string with empty default - */ - parameterOptionalStringWithEmptyDefault?: string; - /** - * This is a optional string with no default - */ - parameterOptionalStringWithNoDefault?: string; - /** - * This is a string with default - */ - parameterStringWithDefault: string; - /** - * This is a string with empty default - */ - parameterStringWithEmptyDefault: string; - /** - * This is a string with no default - */ - parameterStringWithNoDefault: string; - /** - * This is a string that can be null with no default - */ - parameterStringNullableWithNoDefault?: string | null; - /** - * This is a string that can be null with default - */ - parameterStringNullableWithDefault?: string | null; - }; + Querystring: CallToTestOrderOfParamsData['query']; }>; duplicateName: RouteHandler<{}>; duplicateName2: RouteHandler<{}>; @@ -1234,23 +1033,23 @@ export type RouteHandlers = { duplicateName4: RouteHandler<{}>; callWithNoContentResponse: RouteHandler<{ Reply: { - 204: void; + '204': void; }; }>; callWithResponseAndNoContentResponse: RouteHandler<{ Reply: { - 200: number; - 204: void; + '200': number; + '204': void; }; }>; dummyA: RouteHandler<{ Reply: { - 200: _400; + '200': _400; }; }>; dummyB: RouteHandler<{ Reply: { - 204: void; + '204': void; }; }>; callWithResponse: RouteHandler<{ @@ -1258,147 +1057,66 @@ export type RouteHandlers = { }>; callWithDuplicateResponses: RouteHandler<{ Reply: { - 200: ModelWithBoolean & ModelWithInteger; - 201: ModelWithString; - 202: ModelWithString; - 500: ModelWithStringError; - 501: ModelWithStringError; - 502: ModelWithStringError; + '200': ModelWithBoolean & ModelWithInteger; + '201': ModelWithString; + '202': ModelWithString; + '500': ModelWithStringError; + '501': ModelWithStringError; + '502': ModelWithStringError; '4XX': DictionaryWithArray; }; }>; callWithResponses: RouteHandler<{ Reply: { - 200: { + '200': { readonly '@namespace.string'?: string; readonly '@namespace.integer'?: number; readonly value?: Array; }; - 201: ModelThatExtends; - 202: ModelThatExtendsExtends; - 500: ModelWithStringError; - 501: ModelWithStringError; - 502: ModelWithStringError; + '201': ModelThatExtends; + '202': ModelThatExtendsExtends; + '500': ModelWithStringError; + '501': ModelWithStringError; + '502': ModelWithStringError; }; }>; collectionFormat: RouteHandler<{ - Querystring: { - /** - * This is an array parameter that is sent as csv format (comma-separated values) - */ - parameterArrayCSV: Array | null; - /** - * This is an array parameter that is sent as ssv format (space-separated values) - */ - parameterArraySSV: Array | null; - /** - * This is an array parameter that is sent as tsv format (tab-separated values) - */ - parameterArrayTSV: Array | null; - /** - * This is an array parameter that is sent as pipes format (pipe-separated values) - */ - parameterArrayPipes: Array | null; - /** - * This is an array parameter that is sent as multi format (multiple parameter instances) - */ - parameterArrayMulti: Array | null; - }; + Querystring: CollectionFormatData['query']; }>; types: RouteHandler<{ - Querystring: { - /** - * This is a number parameter - */ - parameterNumber: number; - /** - * This is a string parameter - */ - parameterString: string | null; - /** - * This is a boolean parameter - */ - parameterBoolean: boolean | null; - /** - * This is an object parameter - */ - parameterObject: {} | null; - /** - * This is an array parameter - */ - parameterArray: Array | null; - /** - * This is a dictionary parameter - */ - parameterDictionary: {} | null; - /** - * This is an enum parameter - */ - parameterEnum: 'Success' | 'Warning' | 'Error' | null; - }; - Params?: { - /** - * This is a number parameter - */ - id?: number; - }; + Params?: TypesData['path']; + Querystring: TypesData['query']; Reply: { - 200: number; - 201: string; - 202: boolean; - 203: {}; + '200': number; + '201': string; + '202': boolean; + '203': {}; }; }>; uploadFile: RouteHandler<{ - Body: Blob | File; - Params: { - /** - * api-version should be required in standalone clients - */ - 'api-version': string | null; - }; + Body: UploadFileData['body']; + Params: UploadFileData['path']; Reply: { - 200: boolean; + '200': boolean; }; }>; fileResponse: RouteHandler<{ - Params: { - id: string; - /** - * api-version should be required in standalone clients - */ - 'api-version': string; - }; + Params: FileResponseData['path']; Reply: { - 200: Blob | File; + '200': Blob | File; }; }>; complexTypes: RouteHandler<{ - Querystring: { - /** - * Parameter containing object - */ - parameterObject: { - first?: { - second?: { - third?: string; - }; - }; - }; - /** - * Parameter containing reference - */ - parameterReference: ModelWithString; - }; + Querystring: ComplexTypesData['query']; Reply: { - 200: Array; - 400: unknown; - 500: unknown; + '200': Array; + '400': unknown; + '500': unknown; }; }>; multipartResponse: RouteHandler<{ Reply: { - 200: { + '200': { file?: Blob | File; metadata?: { foo?: string; @@ -1408,70 +1126,39 @@ export type RouteHandlers = { }; }>; multipartRequest: RouteHandler<{ - Body: { - content?: Blob | File; - data?: ModelWithString | null; - }; + Body: MultipartRequestData['body']; }>; complexParams: RouteHandler<{ - Body: { - readonly key: string | null; - name: string | null; - enabled?: boolean; - type: 'Monkey' | 'Horse' | 'Bird'; - listOfModels?: Array | null; - listOfStrings?: Array | null; - parameters: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; - readonly user?: { - readonly id?: number; - readonly name?: string | null; - }; - }; - Params: { - id: number; - /** - * api-version should be required in standalone clients - */ - 'api-version': string; - }; + Body: ComplexParamsData['body']; + Params: ComplexParamsData['path']; Reply: { - 200: ModelWithString; + '200': ModelWithString; }; }>; callWithResultFromHeader: RouteHandler<{ Reply: { - 200: unknown; - 400: unknown; - 500: unknown; + '200': unknown; + '400': unknown; + '500': unknown; }; }>; testErrorCode: RouteHandler<{ - Querystring: { - /** - * Status code to return - */ - status: number; - }; + Querystring: TestErrorCodeData['query']; Reply: { - 200: unknown; - 500: unknown; - 501: unknown; - 502: unknown; - 503: unknown; + '200': unknown; + '500': unknown; + '501': unknown; + '502': unknown; + '503': unknown; }; }>; nonAsciiæøåÆøÅöôêÊ字符串: RouteHandler<{ - Querystring: { - /** - * Dummy input param - */ - nonAsciiParamæøåÆØÅöôêÊ: number; - }; + Querystring: NonAsciiæøåÆøÅöôêÊ字符串Data['query']; Reply: { - 200: Array; + '200': Array; }; }>; putWithFormUrlEncoded: RouteHandler<{ - Body: ArrayWithStrings; + Body: PutWithFormUrlEncodedData['body']; }>; }; \ No newline at end of file -- 2.51.2 From c2ee902bfefc1bda4fa7307a061ba9512b7c61f6 Mon Sep 17 00:00:00 2001 From: Lubos Date: Sun, 17 Nov 2024 17:02:37 +0800 Subject: [PATCH 08/13] chore: simplify fastify output --- packages/openapi-ts/src/ir/operation.ts | 77 +- .../src/plugins/@hey-api/services/plugin.ts | 35 +- .../plugins/@hey-api/transformers/plugin.ts | 13 +- .../src/plugins/@hey-api/types/plugin.ts | 149 ++- .../plugins/@tanstack/query-core/plugin.ts | 27 +- .../openapi-ts/src/plugins/fastify/plugin.ts | 110 +- .../openapi-ts/src/plugins/utils/types.ts | 42 +- .../3.0.x/operation-204/types.gen.ts | 13 +- .../parameter-explode-false/types.gen.ts | 7 + .../@hey-api/services/default/types.gen.ts | 319 ++++- .../asClass/types.gen.ts | 319 ++++- .../axios/types.gen.ts | 319 ++++- .../fetch/types.gen.ts | 319 ++++- .../react-query/asClass/types.gen.ts | 319 ++++- .../@tanstack/react-query/axios/types.gen.ts | 319 ++++- .../@tanstack/react-query/fetch/types.gen.ts | 319 ++++- .../solid-query/asClass/types.gen.ts | 319 ++++- .../@tanstack/solid-query/axios/types.gen.ts | 319 ++++- .../@tanstack/solid-query/fetch/types.gen.ts | 319 ++++- .../svelte-query/asClass/types.gen.ts | 319 ++++- .../@tanstack/svelte-query/axios/types.gen.ts | 319 ++++- .../@tanstack/svelte-query/fetch/types.gen.ts | 319 ++++- .../@tanstack/vue-query/asClass/types.gen.ts | 319 ++++- .../@tanstack/vue-query/axios/types.gen.ts | 319 ++++- .../@tanstack/vue-query/fetch/types.gen.ts | 319 ++++- .../plugins/fastify/default/fastify.gen.ts | 1069 +--------------- .../plugins/fastify/default/types.gen.ts | 319 ++++- .../3.1.x/operation-204/types.gen.ts | 13 +- .../parameter-explode-false/types.gen.ts | 7 + .../@hey-api/services/default/types.gen.ts | 319 ++++- .../asClass/types.gen.ts | 319 ++++- .../axios/types.gen.ts | 319 ++++- .../fetch/types.gen.ts | 319 ++++- .../react-query/asClass/types.gen.ts | 319 ++++- .../@tanstack/react-query/axios/types.gen.ts | 319 ++++- .../@tanstack/react-query/fetch/types.gen.ts | 319 ++++- .../solid-query/asClass/types.gen.ts | 319 ++++- .../@tanstack/solid-query/axios/types.gen.ts | 319 ++++- .../@tanstack/solid-query/fetch/types.gen.ts | 319 ++++- .../svelte-query/asClass/types.gen.ts | 319 ++++- .../@tanstack/svelte-query/axios/types.gen.ts | 319 ++++- .../@tanstack/svelte-query/fetch/types.gen.ts | 319 ++++- .../@tanstack/vue-query/asClass/types.gen.ts | 319 ++++- .../@tanstack/vue-query/axios/types.gen.ts | 319 ++++- .../@tanstack/vue-query/fetch/types.gen.ts | 319 ++++- .../plugins/fastify/default/fastify.gen.ts | 1073 +---------------- .../plugins/fastify/default/types.gen.ts | 319 ++++- 47 files changed, 10203 insertions(+), 3278 deletions(-) diff --git a/packages/openapi-ts/src/ir/operation.ts b/packages/openapi-ts/src/ir/operation.ts index 05443cc02..849dc51fe 100644 --- a/packages/openapi-ts/src/ir/operation.ts +++ b/packages/openapi-ts/src/ir/operation.ts @@ -77,28 +77,34 @@ const statusCodeToGroup = ({ }; interface OperationResponsesMap { - error: IRSchemaObject | undefined; - response: IRSchemaObject | undefined; + error?: IRSchemaObject; + errors?: IRSchemaObject; + response?: IRSchemaObject; + responses?: IRSchemaObject; } export const operationResponsesMap = ( operation: IROperationObject, ): OperationResponsesMap => { - const result: OperationResponsesMap = { - error: undefined, - response: undefined, - }; + const result: OperationResponsesMap = {}; if (!operation.responses) { return result; } - let errors: IRSchemaObject = {}; - const errorsItems: Array = []; + const errors: Omit & + Pick, 'properties'> = { + properties: {}, + type: 'object', + }; - let responses: IRSchemaObject = {}; - const responsesItems: Array = []; + const responses: Omit & + Pick, 'properties'> = { + properties: {}, + type: 'object', + }; + // store default response to be evaluated last let defaultResponse: IRResponseObject | undefined; for (const name in operation.responses) { @@ -110,14 +116,13 @@ export const operationResponsesMap = ( // TODO: parser - handle informational and redirection status codes break; case '2XX': - responsesItems.push(response.schema); + responses.properties[name] = response.schema; break; case '4XX': case '5XX': - errorsItems.push(response.schema); + errors.properties[name] = response.schema; break; case 'default': - // store default response to be evaluated last defaultResponse = response; break; } @@ -128,8 +133,8 @@ export const operationResponsesMap = ( let inferred = false; // assume default is intended for success if none exists yet - if (!responsesItems.length) { - responsesItems.push(defaultResponse.schema); + if (!Object.keys(responses.properties).length) { + responses.properties.default = defaultResponse.schema; inferred = true; } @@ -145,7 +150,7 @@ export const operationResponsesMap = ( (keyword) => description.includes(keyword) || $ref.includes(keyword), ) ) { - responsesItems.push(defaultResponse.schema); + responses.properties.default = defaultResponse.schema; inferred = true; } @@ -156,37 +161,45 @@ export const operationResponsesMap = ( (keyword) => description.includes(keyword) || $ref.includes(keyword), ) ) { - errorsItems.push(defaultResponse.schema); + errors.properties.default = defaultResponse.schema; inferred = true; } // if no keyword match, assume default schema is intended for error if (!inferred) { - errorsItems.push(defaultResponse.schema); + errors.properties.default = defaultResponse.schema; } } - if (errorsItems.length) { - errors = addItemsToSchema({ - items: errorsItems, + const errorKeys = Object.keys(errors.properties); + if (errorKeys.length) { + errors.required = errorKeys; + result.errors = errors; + + let errorUnion = addItemsToSchema({ + items: Object.values(errors.properties), mutateSchemaOneItem: true, - schema: errors, + schema: {}, }); - errors = deduplicateSchema({ schema: errors }); - if (Object.keys(errors).length && errors.type !== 'unknown') { - result.error = errors; + errorUnion = deduplicateSchema({ schema: errorUnion }); + if (Object.keys(errorUnion).length && errorUnion.type !== 'unknown') { + result.error = errorUnion; } } - if (responsesItems.length) { - responses = addItemsToSchema({ - items: responsesItems, + const responseKeys = Object.keys(responses.properties); + if (responseKeys.length) { + responses.required = responseKeys; + result.responses = responses; + + let responseUnion = addItemsToSchema({ + items: Object.values(responses.properties), mutateSchemaOneItem: true, - schema: responses, + schema: {}, }); - responses = deduplicateSchema({ schema: responses }); - if (Object.keys(responses).length && responses.type !== 'unknown') { - result.response = responses; + responseUnion = deduplicateSchema({ schema: responseUnion }); + if (Object.keys(responseUnion).length && responseUnion.type !== 'unknown') { + result.response = responseUnion; } } diff --git a/packages/openapi-ts/src/plugins/@hey-api/services/plugin.ts b/packages/openapi-ts/src/plugins/@hey-api/services/plugin.ts index 0cdcb1c3f..3bb234391 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/services/plugin.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/services/plugin.ts @@ -33,11 +33,11 @@ interface OperationIRRef { id: string; } -const operationIrRef = ({ +export const operationIrRef = ({ id, type, }: OperationIRRef & { - type: 'data' | 'error' | 'response'; + type: 'data' | 'error' | 'errors' | 'response' | 'responses'; }): string => { let affix = ''; switch (type) { @@ -45,11 +45,21 @@ const operationIrRef = ({ affix = 'Data'; break; case 'error': + // error union affix = 'Error'; break; + case 'errors': + // errors map + affix = 'Errors'; + break; case 'response': + // response union affix = 'Response'; break; + case 'responses': + // responses map + affix = 'Responses'; + break; } return `${irRef}${camelCase({ input: id, @@ -57,15 +67,6 @@ const operationIrRef = ({ })}${affix}`; }; -export const operationDataRef = ({ id }: OperationIRRef): string => - operationIrRef({ id, type: 'data' }); - -export const operationErrorRef = ({ id }: OperationIRRef): string => - operationIrRef({ id, type: 'error' }); - -export const operationResponseRef = ({ id }: OperationIRRef): string => - operationIrRef({ id, type: 'response' }); - const servicesId = 'services'; const requestOptions = ({ @@ -205,7 +206,7 @@ const generateClassServices = ({ context }: { context: IRContext }) => { const operation = pathItem[method]!; const identifierData = context.file({ id: 'types' })!.identifier({ - $ref: operationDataRef({ id: operation.id }), + $ref: operationIrRef({ id: operation.id, type: 'data' }), namespace: 'type', }); if (identifierData.name) { @@ -217,7 +218,7 @@ const generateClassServices = ({ context }: { context: IRContext }) => { } const identifierError = context.file({ id: 'types' })!.identifier({ - $ref: operationErrorRef({ id: operation.id }), + $ref: operationIrRef({ id: operation.id, type: 'error' }), namespace: 'type', }); if (identifierError.name) { @@ -229,7 +230,7 @@ const generateClassServices = ({ context }: { context: IRContext }) => { } const identifierResponse = context.file({ id: 'types' })!.identifier({ - $ref: operationResponseRef({ id: operation.id }), + $ref: operationIrRef({ id: operation.id, type: 'response' }), namespace: 'type', }); if (identifierResponse.name) { @@ -330,7 +331,7 @@ const generateFlatServices = ({ context }: { context: IRContext }) => { const operation = pathItem[method]!; const identifierData = context.file({ id: 'types' })!.identifier({ - $ref: operationDataRef({ id: operation.id }), + $ref: operationIrRef({ id: operation.id, type: 'data' }), namespace: 'type', }); if (identifierData.name) { @@ -342,7 +343,7 @@ const generateFlatServices = ({ context }: { context: IRContext }) => { } const identifierError = context.file({ id: 'types' })!.identifier({ - $ref: operationErrorRef({ id: operation.id }), + $ref: operationIrRef({ id: operation.id, type: 'error' }), namespace: 'type', }); if (identifierError.name) { @@ -354,7 +355,7 @@ const generateFlatServices = ({ context }: { context: IRContext }) => { } const identifierResponse = context.file({ id: 'types' })!.identifier({ - $ref: operationResponseRef({ id: operation.id }), + $ref: operationIrRef({ id: operation.id, type: 'response' }), namespace: 'type', }); if (identifierResponse.name) { diff --git a/packages/openapi-ts/src/plugins/@hey-api/transformers/plugin.ts b/packages/openapi-ts/src/plugins/@hey-api/transformers/plugin.ts index d70cf558e..b57793e82 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/transformers/plugin.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/transformers/plugin.ts @@ -11,7 +11,7 @@ import { operationResponsesMap } from '../../../ir/operation'; import { camelCase } from '../../../utils/camelCase'; import { irRef } from '../../../utils/ref'; import type { PluginHandler } from '../../types'; -import { operationResponseRef } from '../services/plugin'; +import { operationIrRef } from '../services/plugin'; import type { Config } from './types'; interface OperationIRRef { @@ -21,7 +21,7 @@ interface OperationIRRef { id: string; } -const operationIrRef = ({ +const operationTransformerIrRef = ({ id, type, }: OperationIRRef & { @@ -48,15 +48,16 @@ const operationIrRef = ({ // TODO: parser - currently unused export const operationDataTransformerRef = ({ id }: OperationIRRef): string => - operationIrRef({ id, type: 'data' }); + operationTransformerIrRef({ id, type: 'data' }); // TODO: parser - currently unused export const operationErrorTransformerRef = ({ id }: OperationIRRef): string => - operationIrRef({ id, type: 'error' }); + operationTransformerIrRef({ id, type: 'error' }); export const operationResponseTransformerRef = ({ id, -}: OperationIRRef): string => operationIrRef({ id, type: 'response' }); +}: OperationIRRef): string => + operationTransformerIrRef({ id, type: 'response' }); const schemaIrRef = ({ $ref, @@ -385,7 +386,7 @@ export const handler: PluginHandler = ({ context, plugin }) => { } const identifierResponse = context.file({ id: 'types' })!.identifier({ - $ref: operationResponseRef({ id: operation.id }), + $ref: operationIrRef({ id: operation.id, type: 'response' }), namespace: 'type', }); if (!identifierResponse.name) { diff --git a/packages/openapi-ts/src/plugins/@hey-api/types/plugin.ts b/packages/openapi-ts/src/plugins/@hey-api/types/plugin.ts index 7e88a15d0..e15bf1c0e 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/types/plugin.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/types/plugin.ts @@ -1,3 +1,5 @@ +import ts from 'typescript'; + import { compiler } from '../../../compiler'; import type { IRContext } from '../../../ir/context'; import type { @@ -10,16 +12,8 @@ import type { import { operationResponsesMap } from '../../../ir/operation'; import { deduplicateSchema } from '../../../ir/schema'; import type { PluginHandler } from '../../types'; -import { - componentsToType, - schemaToType, - type SchemaToTypeOptions, -} from '../../utils/types'; -import { - operationDataRef, - operationErrorRef, - operationResponseRef, -} from '../services/plugin'; +import { schemaToType, type SchemaToTypeOptions } from '../../utils/types'; +import { operationIrRef } from '../services/plugin'; import type { Config } from './types'; export const typesId = 'types'; @@ -141,7 +135,7 @@ const operationToDataType = ({ if (hasAnyProperties) { const identifier = context.file({ id: typesId })!.identifier({ - $ref: operationDataRef({ id: operation.id }), + $ref: operationIrRef({ id: operation.id, type: 'data' }), create: true, namespace: 'type', }); @@ -172,40 +166,99 @@ const operationToType = ({ options, }); - const { error, response } = operationResponsesMap(operation); + const file = context.file({ id: typesId })!; - if (error) { - const identifier = context.file({ id: typesId })!.identifier({ - $ref: operationErrorRef({ id: operation.id }), + const { error, errors, response, responses } = + operationResponsesMap(operation); + + if (errors) { + const identifierErrors = file.identifier({ + $ref: operationIrRef({ id: operation.id, type: 'errors' }), create: true, namespace: 'type', }); - const node = compiler.typeAliasDeclaration({ - exportType: true, - name: identifier.name || '', - type: schemaToType({ - options, - schema: error, - }), - }); - context.file({ id: typesId })!.add(node); + if (identifierErrors.name) { + const node = compiler.typeAliasDeclaration({ + exportType: true, + name: identifierErrors.name, + type: schemaToType({ + options, + schema: errors, + }), + }); + file.add(node); + + if (error) { + const identifierError = file.identifier({ + $ref: operationIrRef({ id: operation.id, type: 'error' }), + create: true, + namespace: 'type', + }); + if (identifierError.name) { + const errorsType = compiler.typeReferenceNode({ + typeName: identifierErrors.name, + }); + const keyofType = ts.factory.createTypeOperatorNode( + ts.SyntaxKind.KeyOfKeyword, + errorsType, + ); + const node = compiler.typeAliasDeclaration({ + exportType: true, + name: identifierError.name, + type: compiler.indexedAccessTypeNode({ + indexType: keyofType, + objectType: errorsType, + }), + }); + file.add(node); + } + } + } } - if (response) { - const identifier = context.file({ id: typesId })!.identifier({ - $ref: operationResponseRef({ id: operation.id }), + if (responses) { + const identifierResponses = file.identifier({ + $ref: operationIrRef({ id: operation.id, type: 'responses' }), create: true, namespace: 'type', }); - const node = compiler.typeAliasDeclaration({ - exportType: true, - name: identifier.name || '', - type: schemaToType({ - options, - schema: response, - }), - }); - context.file({ id: typesId })!.add(node); + if (identifierResponses.name) { + const node = compiler.typeAliasDeclaration({ + exportType: true, + name: identifierResponses.name, + type: schemaToType({ + options, + schema: responses, + }), + }); + file.add(node); + + if (response) { + const identifierResponse = file.identifier({ + $ref: operationIrRef({ id: operation.id, type: 'response' }), + create: true, + namespace: 'type', + }); + if (identifierResponse.name) { + const responsesType = compiler.typeReferenceNode({ + typeName: identifierResponses.name, + }); + const keyofType = ts.factory.createTypeOperatorNode( + ts.SyntaxKind.KeyOfKeyword, + responsesType, + ); + const node = compiler.typeAliasDeclaration({ + exportType: true, + name: identifierResponse.name, + type: compiler.indexedAccessTypeNode({ + indexType: keyofType, + objectType: responsesType, + }), + }); + file.add(node); + } + } + } } }; @@ -220,7 +273,29 @@ export const handler: PluginHandler = ({ context, plugin }) => { useTransformersDate: context.config.plugins['@hey-api/transformers']?.dates, }; - componentsToType({ context, options }); + if (context.ir.components) { + for (const name in context.ir.components.schemas) { + const schema = context.ir.components.schemas[name]; + const $ref = `#/components/schemas/${name}`; + + schemaToType({ + $ref, + options, + schema, + }); + } + + for (const name in context.ir.components.parameters) { + const parameter = context.ir.components.parameters[name]; + const $ref = `#/components/parameters/${name}`; + + schemaToType({ + $ref, + options, + schema: parameter.schema, + }); + } + } // TODO: parser - once types are a plugin, this logic can be simplified // provide config option on types to generate path types and services diff --git a/packages/openapi-ts/src/plugins/@tanstack/query-core/plugin.ts b/packages/openapi-ts/src/plugins/@tanstack/query-core/plugin.ts index 7e6dbfd02..de8fcab55 100644 --- a/packages/openapi-ts/src/plugins/@tanstack/query-core/plugin.ts +++ b/packages/openapi-ts/src/plugins/@tanstack/query-core/plugin.ts @@ -24,18 +24,14 @@ import type { Files } from '../../../types/utils'; import { getConfig } from '../../../utils/config'; import { getServiceName } from '../../../utils/postprocess'; import { transformServiceName } from '../../../utils/transform'; -import { - operationDataRef, - operationErrorRef, - operationResponseRef, -} from '../../@hey-api/services/plugin'; +import { operationIrRef } from '../../@hey-api/services/plugin'; import { operationOptionsType, serviceFunctionIdentifier, } from '../../@hey-api/services/plugin-legacy'; import { typesId } from '../../@hey-api/types/plugin'; import type { PluginHandler } from '../../types'; -import { schemaToType, type SchemaToTypeOptions } from '../../utils/types'; +import { schemaToType } from '../../utils/types'; import type { Config as AngularQueryConfig } from '../angular-query-experimental'; import type { Config as ReactQueryConfig } from '../react-query'; import type { Config as SolidQueryConfig } from '../solid-query'; @@ -556,7 +552,7 @@ const useTypeData = ({ plugin: Plugin; }) => { const identifierData = context.file({ id: 'types' })!.identifier({ - $ref: operationDataRef({ id: operation.id }), + $ref: operationIrRef({ id: operation.id, type: 'data' }), namespace: 'type', }); if (identifierData.name) { @@ -585,7 +581,7 @@ const useTypeError = ({ }) => { const file = context.file({ id: plugin.name })!; const identifierError = context.file({ id: 'types' })!.identifier({ - $ref: operationErrorRef({ id: operation.id }), + $ref: operationIrRef({ id: operation.id, type: 'error' }), namespace: 'type', }); if (identifierError.name) { @@ -632,7 +628,7 @@ const useTypeResponse = ({ plugin: Plugin; }) => { const identifierResponse = context.file({ id: 'types' })!.identifier({ - $ref: operationResponseRef({ id: operation.id }), + $ref: operationIrRef({ id: operation.id, type: 'response' }), namespace: 'type', }); if (identifierResponse.name) { @@ -891,17 +887,16 @@ export const handler: PluginHandler< const typeQueryKey = `${queryKeyName}<${typeData}>`; const typePageObjectParam = `Pick<${typeQueryKey}[0], 'body' | 'headers' | 'path' | 'query'>`; - const options: SchemaToTypeOptions = { - enums: context.config.plugins['@hey-api/types']?.enums, - file: context.file({ id: typesId })!, - useTransformersDate: - context.config.plugins['@hey-api/transformers']?.dates, - }; // TODO: parser - this is a bit clunky, need to compile type to string because // `compiler.returnFunctionCall()` accepts only strings, should be cleaned up const typePageParam = `${tsNodeToString({ node: schemaToType({ - options, + options: { + enums: context.config.plugins['@hey-api/types']?.enums, + file: context.file({ id: typesId })!, + useTransformersDate: + context.config.plugins['@hey-api/transformers']?.dates, + }, schema: pagination.schema, }), unescape: true, diff --git a/packages/openapi-ts/src/plugins/fastify/plugin.ts b/packages/openapi-ts/src/plugins/fastify/plugin.ts index 341016036..0a3014eda 100644 --- a/packages/openapi-ts/src/plugins/fastify/plugin.ts +++ b/packages/openapi-ts/src/plugins/fastify/plugin.ts @@ -1,3 +1,5 @@ +import type ts from 'typescript'; + import { compiler, type Property } from '../../compiler'; import type { IRContext } from '../../ir/context'; import type { @@ -6,9 +8,8 @@ import type { IRPathsObject, } from '../../ir/ir'; import { hasParameterGroupObjectRequired } from '../../ir/parameter'; -import { operationDataRef } from '../@hey-api/services/plugin'; +import { operationIrRef } from '../@hey-api/services/plugin'; import type { PluginHandler } from '../types'; -import { componentsToType, schemaToType } from '../utils/types'; import type { Config } from './types'; const fastifyId = 'fastify'; @@ -19,13 +20,14 @@ const operationToRouteHandler = ({ }: { context: IRContext; operation: IROperationObject; -}): Property => { +}): Property | undefined => { const file = context.file({ id: fastifyId })!; + const fileTypes = context.file({ id: 'types' })!; const properties: Array = []; - const identifierData = context.file({ id: 'types' })!.identifier({ - $ref: operationDataRef({ id: operation.id }), + const identifierData = fileTypes.identifier({ + $ref: operationIrRef({ id: operation.id, type: 'data' }), namespace: 'type', }); @@ -91,34 +93,54 @@ const operationToRouteHandler = ({ } } - if (operation.responses) { - const responseProperties: Array = []; - - for (const code in operation.responses) { - if (code === 'default') { - continue; - } + let errorsTypeReference: ts.TypeReferenceNode | undefined = undefined; + const identifierErrors = fileTypes.identifier({ + $ref: operationIrRef({ id: operation.id, type: 'errors' }), + namespace: 'type', + }); + if (identifierErrors.name) { + file.import({ + asType: true, + module: file.relativePathToFile({ context, id: 'types' }), + name: identifierErrors.name, + }); + errorsTypeReference = compiler.typeReferenceNode({ + typeName: identifierErrors.name, + }); + } - const response = operation.responses[code]!; - // TODO: numeric literal for numbers - responseProperties.push({ - name: code, - type: schemaToType({ - options: { file }, - schema: response.schema, - }), - }); - } + let responsesTypeReference: ts.TypeReferenceNode | undefined = undefined; + const identifierResponses = fileTypes.identifier({ + $ref: operationIrRef({ id: operation.id, type: 'responses' }), + namespace: 'type', + }); + if (identifierResponses.name) { + file.import({ + asType: true, + module: file.relativePathToFile({ context, id: 'types' }), + name: identifierResponses.name, + }); + responsesTypeReference = compiler.typeReferenceNode({ + typeName: identifierResponses.name, + }); + } + const replyTypes = [errorsTypeReference, responsesTypeReference].filter( + Boolean, + ); + if (replyTypes.length) { properties.push({ name: 'Reply', - type: compiler.typeInterfaceNode({ - properties: responseProperties, - useLegacyResolution: false, + type: compiler.typeIntersectionNode({ + types: replyTypes, }), }); } + if (!properties.length) { + return; + } + const routeHandler: Property = { name: operation.id, type: compiler.typeNode('RouteHandler', [ @@ -131,8 +153,11 @@ const operationToRouteHandler = ({ return routeHandler; }; -const processRouteHandlers = ({ context }: { context: IRContext }) => { - const file = context.file({ id: fastifyId })!; +export const handler: PluginHandler = ({ context, plugin }) => { + const file = context.createFile({ + id: fastifyId, + path: plugin.output, + }); const routeHandlers: Array = []; @@ -144,7 +169,9 @@ const processRouteHandlers = ({ context }: { context: IRContext }) => { const operation = pathItem[method]!; const routeHandler = operationToRouteHandler({ context, operation }); - routeHandlers.push(routeHandler); + if (routeHandler) { + routeHandlers.push(routeHandler); + } } } @@ -154,6 +181,14 @@ const processRouteHandlers = ({ context }: { context: IRContext }) => { namespace: 'type', }); if (identifier.name) { + if (routeHandlers.length) { + file.import({ + asType: true, + module: 'fastify', + name: 'RouteHandler', + }); + } + file.add( compiler.typeAliasDeclaration({ exportType: true, @@ -166,22 +201,3 @@ const processRouteHandlers = ({ context }: { context: IRContext }) => { ); } }; - -export const handler: PluginHandler = ({ context, plugin }) => { - const file = context.createFile({ - id: fastifyId, - path: plugin.output, - }); - file.import({ - asType: true, - module: 'fastify', - name: 'RouteHandler', - }); - componentsToType({ - context, - options: { - file, - }, - }); - processRouteHandlers({ context }); -}; diff --git a/packages/openapi-ts/src/plugins/utils/types.ts b/packages/openapi-ts/src/plugins/utils/types.ts index b703d41cd..b4067fb18 100644 --- a/packages/openapi-ts/src/plugins/utils/types.ts +++ b/packages/openapi-ts/src/plugins/utils/types.ts @@ -1,9 +1,8 @@ -import type ts from 'typescript'; +import ts from 'typescript'; import type { Property } from '../../compiler'; import { compiler } from '../../compiler'; import type { TypeScriptFile } from '../../generate/files'; -import type { IRContext } from '../../ir/context'; import type { IRSchemaObject } from '../../ir/ir'; import { deduplicateSchema } from '../../ir/schema'; import { ensureValidTypeScriptJavaScriptIdentifier } from '../../openApi'; @@ -369,6 +368,8 @@ const numberTypeToIdentifier = ({ }); }; +const digitsRegExp = /^\d+$/; + const objectTypeToIdentifier = ({ namespace, schema, @@ -387,11 +388,14 @@ const objectTypeToIdentifier = ({ for (const name in schema.properties) { const property = schema.properties[name]; const isRequired = required.includes(name); + digitsRegExp.lastIndex = 0; schemaProperties.push({ comment: parseSchemaJsDoc({ schema: property }), isReadOnly: property.accessScope === 'read', isRequired, - name, + name: digitsRegExp.test(name) + ? ts.factory.createNumericLiteral(name) + : name, type: schemaToType({ $ref: `${irRef}${name}`, namespace, @@ -677,35 +681,3 @@ export const schemaToType = ({ return type; }; - -export const componentsToType = ({ - context, - options, -}: { - context: IRContext; - options: SchemaToTypeOptions; -}) => { - if (context.ir.components) { - for (const name in context.ir.components.schemas) { - const schema = context.ir.components.schemas[name]; - const $ref = `#/components/schemas/${name}`; - - schemaToType({ - $ref, - options, - schema, - }); - } - - for (const name in context.ir.components.parameters) { - const parameter = context.ir.components.parameters[name]; - const $ref = `#/components/parameters/${name}`; - - schemaToType({ - $ref, - options, - schema: parameter.schema, - }); - } - } -}; diff --git a/packages/openapi-ts/test/__snapshots__/3.0.x/operation-204/types.gen.ts b/packages/openapi-ts/test/__snapshots__/3.0.x/operation-204/types.gen.ts index 82480d759..c3706fce7 100644 --- a/packages/openapi-ts/test/__snapshots__/3.0.x/operation-204/types.gen.ts +++ b/packages/openapi-ts/test/__snapshots__/3.0.x/operation-204/types.gen.ts @@ -1,3 +1,14 @@ // This file is auto-generated by @hey-api/openapi-ts -export type PostFooResponse = string | void; \ No newline at end of file +export type PostFooResponses = { + /** + * OK + */ + 200: string; + /** + * Created + */ + 204: void; +}; + +export type PostFooResponse = PostFooResponses[keyof PostFooResponses]; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/3.0.x/parameter-explode-false/types.gen.ts b/packages/openapi-ts/test/__snapshots__/3.0.x/parameter-explode-false/types.gen.ts index 2003ec4a4..6cd720ee8 100644 --- a/packages/openapi-ts/test/__snapshots__/3.0.x/parameter-explode-false/types.gen.ts +++ b/packages/openapi-ts/test/__snapshots__/3.0.x/parameter-explode-false/types.gen.ts @@ -6,4 +6,11 @@ export type PostFooData = { query?: { foo?: Array; }; +}; + +export type PostFooResponses = { + /** + * OK + */ + default: unknown; }; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/@hey-api/services/default/types.gen.ts b/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/@hey-api/services/default/types.gen.ts index b914fd963..37046a7eb 100644 --- a/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/@hey-api/services/default/types.gen.ts +++ b/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/@hey-api/services/default/types.gen.ts @@ -947,9 +947,27 @@ export type ImportData = { body: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; }; -export type ImportResponse = Model_From_Zendesk | ModelWithReadOnlyAndWriteOnly; +export type ImportResponses = { + /** + * Success + */ + 200: Model_From_Zendesk; + /** + * Default success response + */ + default: ModelWithReadOnlyAndWriteOnly; +}; + +export type ImportResponse = ImportResponses[keyof ImportResponses]; + +export type ApiVversionOdataControllerCountResponses = { + /** + * Success + */ + 200: Model_From_Zendesk; +}; -export type ApiVversionOdataControllerCountResponse = Model_From_Zendesk; +export type ApiVversionOdataControllerCountResponse = ApiVversionOdataControllerCountResponses[keyof ApiVversionOdataControllerCountResponses]; export type GetApiVbyApiVersionSimpleOperationData = { body?: never; @@ -962,9 +980,23 @@ export type GetApiVbyApiVersionSimpleOperationData = { query?: never; }; -export type GetApiVbyApiVersionSimpleOperationError = ModelWithBoolean; +export type GetApiVbyApiVersionSimpleOperationErrors = { + /** + * Default error response + */ + default: ModelWithBoolean; +}; -export type GetApiVbyApiVersionSimpleOperationResponse = number; +export type GetApiVbyApiVersionSimpleOperationError = GetApiVbyApiVersionSimpleOperationErrors[keyof GetApiVbyApiVersionSimpleOperationErrors]; + +export type GetApiVbyApiVersionSimpleOperationResponses = { + /** + * Response is a simple number + */ + 200: number; +}; + +export type GetApiVbyApiVersionSimpleOperationResponse = GetApiVbyApiVersionSimpleOperationResponses[keyof GetApiVbyApiVersionSimpleOperationResponses]; export type DeleteFooData3 = { body?: never; @@ -1136,7 +1168,18 @@ export type PostCallWithOptionalParamData = { }; }; -export type PostCallWithOptionalParamResponse = number | void; +export type PostCallWithOptionalParamResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; + +export type PostCallWithOptionalParamResponse = PostCallWithOptionalParamResponses[keyof PostCallWithOptionalParamResponses]; export type PostApiVbyApiVersionRequestBodyData = { /** @@ -1259,27 +1302,132 @@ export type CallToTestOrderOfParamsData = { }; }; -export type CallWithNoContentResponseResponse = void; +export type CallWithNoContentResponseResponses = { + /** + * Success + */ + 204: void; +}; -export type CallWithResponseAndNoContentResponseResponse = number | void; +export type CallWithNoContentResponseResponse = CallWithNoContentResponseResponses[keyof CallWithNoContentResponseResponses]; -export type DummyAResponse = _400; +export type CallWithResponseAndNoContentResponseResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; -export type DummyBResponse = void; +export type CallWithResponseAndNoContentResponseResponse = CallWithResponseAndNoContentResponseResponses[keyof CallWithResponseAndNoContentResponseResponses]; -export type CallWithResponseResponse = _import; +export type DummyAResponses = { + 200: _400; +}; -export type CallWithDuplicateResponsesError = ModelWithStringError | DictionaryWithArray | ModelWithBoolean; +export type DummyAResponse = DummyAResponses[keyof DummyAResponses]; -export type CallWithDuplicateResponsesResponse = (ModelWithBoolean & ModelWithInteger) | ModelWithString; +export type DummyBResponses = { + /** + * Success + */ + 204: void; +}; -export type CallWithResponsesError = ModelWithStringError; +export type DummyBResponse = DummyBResponses[keyof DummyBResponses]; -export type CallWithResponsesResponse = { - readonly '@namespace.string'?: string; - readonly '@namespace.integer'?: number; - readonly value?: Array; -} | ModelThatExtends | ModelThatExtendsExtends; +export type CallWithResponseResponses = { + default: _import; +}; + +export type CallWithResponseResponse = CallWithResponseResponses[keyof CallWithResponseResponses]; + +export type CallWithDuplicateResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for 4XX errors + */ + '4XX': DictionaryWithArray; + /** + * Default error response + */ + default: ModelWithBoolean; +}; + +export type CallWithDuplicateResponsesError = CallWithDuplicateResponsesErrors[keyof CallWithDuplicateResponsesErrors]; + +export type CallWithDuplicateResponsesResponses = { + /** + * Message for 200 response + */ + 200: ModelWithBoolean & ModelWithInteger; + /** + * Message for 201 response + */ + 201: ModelWithString; + /** + * Message for 202 response + */ + 202: ModelWithString; +}; + +export type CallWithDuplicateResponsesResponse = CallWithDuplicateResponsesResponses[keyof CallWithDuplicateResponsesResponses]; + +export type CallWithResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for default response + */ + default: ModelWithStringError; +}; + +export type CallWithResponsesError = CallWithResponsesErrors[keyof CallWithResponsesErrors]; + +export type CallWithResponsesResponses = { + /** + * Message for 200 response + */ + 200: { + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; + readonly value?: Array; + }; + /** + * Message for 201 response + */ + 201: ModelThatExtends; + /** + * Message for 202 response + */ + 202: ModelThatExtendsExtends; +}; + +export type CallWithResponsesResponse = CallWithResponsesResponses[keyof CallWithResponsesResponses]; export type CollectionFormatData = { body?: never; @@ -1348,7 +1496,26 @@ export type TypesData = { }; }; -export type TypesResponse = number | string | boolean | {}; +export type TypesResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Response is a simple string + */ + 201: string; + /** + * Response is a simple boolean + */ + 202: boolean; + /** + * Response is a simple object + */ + 203: {}; +}; + +export type TypesResponse = TypesResponses[keyof TypesResponses]; export type UploadFileData = { body: Blob | File; @@ -1361,7 +1528,11 @@ export type UploadFileData = { query?: never; }; -export type UploadFileResponse = boolean; +export type UploadFileResponses = { + 200: boolean; +}; + +export type UploadFileResponse = UploadFileResponses[keyof UploadFileResponses]; export type FileResponseData = { body?: never; @@ -1375,7 +1546,14 @@ export type FileResponseData = { query?: never; }; -export type FileResponseResponse = Blob | File; +export type FileResponseResponses = { + /** + * Success + */ + 200: Blob | File; +}; + +export type FileResponseResponse = FileResponseResponses[keyof FileResponseResponses]; export type ComplexTypesData = { body?: never; @@ -1398,16 +1576,41 @@ export type ComplexTypesData = { }; }; -export type ComplexTypesResponse = Array; +export type ComplexTypesErrors = { + /** + * 400 `server` error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type ComplexTypesResponses = { + /** + * Successful response + */ + 200: Array; +}; -export type MultipartResponseResponse = { - file?: Blob | File; - metadata?: { - foo?: string; - bar?: string; +export type ComplexTypesResponse = ComplexTypesResponses[keyof ComplexTypesResponses]; + +export type MultipartResponseResponses = { + /** + * OK + */ + 200: { + file?: Blob | File; + metadata?: { + foo?: string; + bar?: string; + }; }; }; +export type MultipartResponseResponse = MultipartResponseResponses[keyof MultipartResponseResponses]; + export type MultipartRequestData = { body?: { content?: Blob | File; @@ -1439,7 +1642,32 @@ export type ComplexParamsData = { query?: never; }; -export type ComplexParamsResponse = ModelWithString; +export type ComplexParamsResponses = { + /** + * Success + */ + 200: ModelWithString; +}; + +export type ComplexParamsResponse = ComplexParamsResponses[keyof ComplexParamsResponses]; + +export type CallWithResultFromHeaderErrors = { + /** + * 400 server error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type CallWithResultFromHeaderResponses = { + /** + * Successful response + */ + 200: unknown; +}; export type TestErrorCodeData = { body?: never; @@ -1452,6 +1680,32 @@ export type TestErrorCodeData = { }; }; +export type TestErrorCodeErrors = { + /** + * Custom message: Internal Server Error + */ + 500: unknown; + /** + * Custom message: Not Implemented + */ + 501: unknown; + /** + * Custom message: Bad Gateway + */ + 502: unknown; + /** + * Custom message: Service Unavailable + */ + 503: unknown; +}; + +export type TestErrorCodeResponses = { + /** + * Custom message: Successful response + */ + 200: unknown; +}; + export type NonAsciiæøåÆøÅöôêÊ字符串Data = { body?: never; path?: never; @@ -1463,7 +1717,14 @@ export type NonAsciiæøåÆøÅöôêÊ字符串Data = { }; }; -export type NonAsciiæøåÆøÅöôêÊ字符串Response = Array; +export type NonAsciiæøåÆøÅöôêÊ字符串Responses = { + /** + * Successful response + */ + 200: Array; +}; + +export type NonAsciiæøåÆøÅöôêÊ字符串Response = NonAsciiæøåÆøÅöôêÊ字符串Responses[keyof NonAsciiæøåÆøÅöôêÊ字符串Responses]; export type PutWithFormUrlEncodedData = { body: ArrayWithStrings; 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 b914fd963..37046a7eb 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 @@ -947,9 +947,27 @@ export type ImportData = { body: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; }; -export type ImportResponse = Model_From_Zendesk | ModelWithReadOnlyAndWriteOnly; +export type ImportResponses = { + /** + * Success + */ + 200: Model_From_Zendesk; + /** + * Default success response + */ + default: ModelWithReadOnlyAndWriteOnly; +}; + +export type ImportResponse = ImportResponses[keyof ImportResponses]; + +export type ApiVversionOdataControllerCountResponses = { + /** + * Success + */ + 200: Model_From_Zendesk; +}; -export type ApiVversionOdataControllerCountResponse = Model_From_Zendesk; +export type ApiVversionOdataControllerCountResponse = ApiVversionOdataControllerCountResponses[keyof ApiVversionOdataControllerCountResponses]; export type GetApiVbyApiVersionSimpleOperationData = { body?: never; @@ -962,9 +980,23 @@ export type GetApiVbyApiVersionSimpleOperationData = { query?: never; }; -export type GetApiVbyApiVersionSimpleOperationError = ModelWithBoolean; +export type GetApiVbyApiVersionSimpleOperationErrors = { + /** + * Default error response + */ + default: ModelWithBoolean; +}; -export type GetApiVbyApiVersionSimpleOperationResponse = number; +export type GetApiVbyApiVersionSimpleOperationError = GetApiVbyApiVersionSimpleOperationErrors[keyof GetApiVbyApiVersionSimpleOperationErrors]; + +export type GetApiVbyApiVersionSimpleOperationResponses = { + /** + * Response is a simple number + */ + 200: number; +}; + +export type GetApiVbyApiVersionSimpleOperationResponse = GetApiVbyApiVersionSimpleOperationResponses[keyof GetApiVbyApiVersionSimpleOperationResponses]; export type DeleteFooData3 = { body?: never; @@ -1136,7 +1168,18 @@ export type PostCallWithOptionalParamData = { }; }; -export type PostCallWithOptionalParamResponse = number | void; +export type PostCallWithOptionalParamResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; + +export type PostCallWithOptionalParamResponse = PostCallWithOptionalParamResponses[keyof PostCallWithOptionalParamResponses]; export type PostApiVbyApiVersionRequestBodyData = { /** @@ -1259,27 +1302,132 @@ export type CallToTestOrderOfParamsData = { }; }; -export type CallWithNoContentResponseResponse = void; +export type CallWithNoContentResponseResponses = { + /** + * Success + */ + 204: void; +}; -export type CallWithResponseAndNoContentResponseResponse = number | void; +export type CallWithNoContentResponseResponse = CallWithNoContentResponseResponses[keyof CallWithNoContentResponseResponses]; -export type DummyAResponse = _400; +export type CallWithResponseAndNoContentResponseResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; -export type DummyBResponse = void; +export type CallWithResponseAndNoContentResponseResponse = CallWithResponseAndNoContentResponseResponses[keyof CallWithResponseAndNoContentResponseResponses]; -export type CallWithResponseResponse = _import; +export type DummyAResponses = { + 200: _400; +}; -export type CallWithDuplicateResponsesError = ModelWithStringError | DictionaryWithArray | ModelWithBoolean; +export type DummyAResponse = DummyAResponses[keyof DummyAResponses]; -export type CallWithDuplicateResponsesResponse = (ModelWithBoolean & ModelWithInteger) | ModelWithString; +export type DummyBResponses = { + /** + * Success + */ + 204: void; +}; -export type CallWithResponsesError = ModelWithStringError; +export type DummyBResponse = DummyBResponses[keyof DummyBResponses]; -export type CallWithResponsesResponse = { - readonly '@namespace.string'?: string; - readonly '@namespace.integer'?: number; - readonly value?: Array; -} | ModelThatExtends | ModelThatExtendsExtends; +export type CallWithResponseResponses = { + default: _import; +}; + +export type CallWithResponseResponse = CallWithResponseResponses[keyof CallWithResponseResponses]; + +export type CallWithDuplicateResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for 4XX errors + */ + '4XX': DictionaryWithArray; + /** + * Default error response + */ + default: ModelWithBoolean; +}; + +export type CallWithDuplicateResponsesError = CallWithDuplicateResponsesErrors[keyof CallWithDuplicateResponsesErrors]; + +export type CallWithDuplicateResponsesResponses = { + /** + * Message for 200 response + */ + 200: ModelWithBoolean & ModelWithInteger; + /** + * Message for 201 response + */ + 201: ModelWithString; + /** + * Message for 202 response + */ + 202: ModelWithString; +}; + +export type CallWithDuplicateResponsesResponse = CallWithDuplicateResponsesResponses[keyof CallWithDuplicateResponsesResponses]; + +export type CallWithResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for default response + */ + default: ModelWithStringError; +}; + +export type CallWithResponsesError = CallWithResponsesErrors[keyof CallWithResponsesErrors]; + +export type CallWithResponsesResponses = { + /** + * Message for 200 response + */ + 200: { + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; + readonly value?: Array; + }; + /** + * Message for 201 response + */ + 201: ModelThatExtends; + /** + * Message for 202 response + */ + 202: ModelThatExtendsExtends; +}; + +export type CallWithResponsesResponse = CallWithResponsesResponses[keyof CallWithResponsesResponses]; export type CollectionFormatData = { body?: never; @@ -1348,7 +1496,26 @@ export type TypesData = { }; }; -export type TypesResponse = number | string | boolean | {}; +export type TypesResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Response is a simple string + */ + 201: string; + /** + * Response is a simple boolean + */ + 202: boolean; + /** + * Response is a simple object + */ + 203: {}; +}; + +export type TypesResponse = TypesResponses[keyof TypesResponses]; export type UploadFileData = { body: Blob | File; @@ -1361,7 +1528,11 @@ export type UploadFileData = { query?: never; }; -export type UploadFileResponse = boolean; +export type UploadFileResponses = { + 200: boolean; +}; + +export type UploadFileResponse = UploadFileResponses[keyof UploadFileResponses]; export type FileResponseData = { body?: never; @@ -1375,7 +1546,14 @@ export type FileResponseData = { query?: never; }; -export type FileResponseResponse = Blob | File; +export type FileResponseResponses = { + /** + * Success + */ + 200: Blob | File; +}; + +export type FileResponseResponse = FileResponseResponses[keyof FileResponseResponses]; export type ComplexTypesData = { body?: never; @@ -1398,16 +1576,41 @@ export type ComplexTypesData = { }; }; -export type ComplexTypesResponse = Array; +export type ComplexTypesErrors = { + /** + * 400 `server` error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type ComplexTypesResponses = { + /** + * Successful response + */ + 200: Array; +}; -export type MultipartResponseResponse = { - file?: Blob | File; - metadata?: { - foo?: string; - bar?: string; +export type ComplexTypesResponse = ComplexTypesResponses[keyof ComplexTypesResponses]; + +export type MultipartResponseResponses = { + /** + * OK + */ + 200: { + file?: Blob | File; + metadata?: { + foo?: string; + bar?: string; + }; }; }; +export type MultipartResponseResponse = MultipartResponseResponses[keyof MultipartResponseResponses]; + export type MultipartRequestData = { body?: { content?: Blob | File; @@ -1439,7 +1642,32 @@ export type ComplexParamsData = { query?: never; }; -export type ComplexParamsResponse = ModelWithString; +export type ComplexParamsResponses = { + /** + * Success + */ + 200: ModelWithString; +}; + +export type ComplexParamsResponse = ComplexParamsResponses[keyof ComplexParamsResponses]; + +export type CallWithResultFromHeaderErrors = { + /** + * 400 server error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type CallWithResultFromHeaderResponses = { + /** + * Successful response + */ + 200: unknown; +}; export type TestErrorCodeData = { body?: never; @@ -1452,6 +1680,32 @@ export type TestErrorCodeData = { }; }; +export type TestErrorCodeErrors = { + /** + * Custom message: Internal Server Error + */ + 500: unknown; + /** + * Custom message: Not Implemented + */ + 501: unknown; + /** + * Custom message: Bad Gateway + */ + 502: unknown; + /** + * Custom message: Service Unavailable + */ + 503: unknown; +}; + +export type TestErrorCodeResponses = { + /** + * Custom message: Successful response + */ + 200: unknown; +}; + export type NonAsciiæøåÆøÅöôêÊ字符串Data = { body?: never; path?: never; @@ -1463,7 +1717,14 @@ export type NonAsciiæøåÆøÅöôêÊ字符串Data = { }; }; -export type NonAsciiæøåÆøÅöôêÊ字符串Response = Array; +export type NonAsciiæøåÆøÅöôêÊ字符串Responses = { + /** + * Successful response + */ + 200: Array; +}; + +export type NonAsciiæøåÆøÅöôêÊ字符串Response = NonAsciiæøåÆøÅöôêÊ字符串Responses[keyof NonAsciiæøåÆøÅöôêÊ字符串Responses]; export type PutWithFormUrlEncodedData = { body: ArrayWithStrings; 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 b914fd963..37046a7eb 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 @@ -947,9 +947,27 @@ export type ImportData = { body: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; }; -export type ImportResponse = Model_From_Zendesk | ModelWithReadOnlyAndWriteOnly; +export type ImportResponses = { + /** + * Success + */ + 200: Model_From_Zendesk; + /** + * Default success response + */ + default: ModelWithReadOnlyAndWriteOnly; +}; + +export type ImportResponse = ImportResponses[keyof ImportResponses]; + +export type ApiVversionOdataControllerCountResponses = { + /** + * Success + */ + 200: Model_From_Zendesk; +}; -export type ApiVversionOdataControllerCountResponse = Model_From_Zendesk; +export type ApiVversionOdataControllerCountResponse = ApiVversionOdataControllerCountResponses[keyof ApiVversionOdataControllerCountResponses]; export type GetApiVbyApiVersionSimpleOperationData = { body?: never; @@ -962,9 +980,23 @@ export type GetApiVbyApiVersionSimpleOperationData = { query?: never; }; -export type GetApiVbyApiVersionSimpleOperationError = ModelWithBoolean; +export type GetApiVbyApiVersionSimpleOperationErrors = { + /** + * Default error response + */ + default: ModelWithBoolean; +}; -export type GetApiVbyApiVersionSimpleOperationResponse = number; +export type GetApiVbyApiVersionSimpleOperationError = GetApiVbyApiVersionSimpleOperationErrors[keyof GetApiVbyApiVersionSimpleOperationErrors]; + +export type GetApiVbyApiVersionSimpleOperationResponses = { + /** + * Response is a simple number + */ + 200: number; +}; + +export type GetApiVbyApiVersionSimpleOperationResponse = GetApiVbyApiVersionSimpleOperationResponses[keyof GetApiVbyApiVersionSimpleOperationResponses]; export type DeleteFooData3 = { body?: never; @@ -1136,7 +1168,18 @@ export type PostCallWithOptionalParamData = { }; }; -export type PostCallWithOptionalParamResponse = number | void; +export type PostCallWithOptionalParamResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; + +export type PostCallWithOptionalParamResponse = PostCallWithOptionalParamResponses[keyof PostCallWithOptionalParamResponses]; export type PostApiVbyApiVersionRequestBodyData = { /** @@ -1259,27 +1302,132 @@ export type CallToTestOrderOfParamsData = { }; }; -export type CallWithNoContentResponseResponse = void; +export type CallWithNoContentResponseResponses = { + /** + * Success + */ + 204: void; +}; -export type CallWithResponseAndNoContentResponseResponse = number | void; +export type CallWithNoContentResponseResponse = CallWithNoContentResponseResponses[keyof CallWithNoContentResponseResponses]; -export type DummyAResponse = _400; +export type CallWithResponseAndNoContentResponseResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; -export type DummyBResponse = void; +export type CallWithResponseAndNoContentResponseResponse = CallWithResponseAndNoContentResponseResponses[keyof CallWithResponseAndNoContentResponseResponses]; -export type CallWithResponseResponse = _import; +export type DummyAResponses = { + 200: _400; +}; -export type CallWithDuplicateResponsesError = ModelWithStringError | DictionaryWithArray | ModelWithBoolean; +export type DummyAResponse = DummyAResponses[keyof DummyAResponses]; -export type CallWithDuplicateResponsesResponse = (ModelWithBoolean & ModelWithInteger) | ModelWithString; +export type DummyBResponses = { + /** + * Success + */ + 204: void; +}; -export type CallWithResponsesError = ModelWithStringError; +export type DummyBResponse = DummyBResponses[keyof DummyBResponses]; -export type CallWithResponsesResponse = { - readonly '@namespace.string'?: string; - readonly '@namespace.integer'?: number; - readonly value?: Array; -} | ModelThatExtends | ModelThatExtendsExtends; +export type CallWithResponseResponses = { + default: _import; +}; + +export type CallWithResponseResponse = CallWithResponseResponses[keyof CallWithResponseResponses]; + +export type CallWithDuplicateResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for 4XX errors + */ + '4XX': DictionaryWithArray; + /** + * Default error response + */ + default: ModelWithBoolean; +}; + +export type CallWithDuplicateResponsesError = CallWithDuplicateResponsesErrors[keyof CallWithDuplicateResponsesErrors]; + +export type CallWithDuplicateResponsesResponses = { + /** + * Message for 200 response + */ + 200: ModelWithBoolean & ModelWithInteger; + /** + * Message for 201 response + */ + 201: ModelWithString; + /** + * Message for 202 response + */ + 202: ModelWithString; +}; + +export type CallWithDuplicateResponsesResponse = CallWithDuplicateResponsesResponses[keyof CallWithDuplicateResponsesResponses]; + +export type CallWithResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for default response + */ + default: ModelWithStringError; +}; + +export type CallWithResponsesError = CallWithResponsesErrors[keyof CallWithResponsesErrors]; + +export type CallWithResponsesResponses = { + /** + * Message for 200 response + */ + 200: { + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; + readonly value?: Array; + }; + /** + * Message for 201 response + */ + 201: ModelThatExtends; + /** + * Message for 202 response + */ + 202: ModelThatExtendsExtends; +}; + +export type CallWithResponsesResponse = CallWithResponsesResponses[keyof CallWithResponsesResponses]; export type CollectionFormatData = { body?: never; @@ -1348,7 +1496,26 @@ export type TypesData = { }; }; -export type TypesResponse = number | string | boolean | {}; +export type TypesResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Response is a simple string + */ + 201: string; + /** + * Response is a simple boolean + */ + 202: boolean; + /** + * Response is a simple object + */ + 203: {}; +}; + +export type TypesResponse = TypesResponses[keyof TypesResponses]; export type UploadFileData = { body: Blob | File; @@ -1361,7 +1528,11 @@ export type UploadFileData = { query?: never; }; -export type UploadFileResponse = boolean; +export type UploadFileResponses = { + 200: boolean; +}; + +export type UploadFileResponse = UploadFileResponses[keyof UploadFileResponses]; export type FileResponseData = { body?: never; @@ -1375,7 +1546,14 @@ export type FileResponseData = { query?: never; }; -export type FileResponseResponse = Blob | File; +export type FileResponseResponses = { + /** + * Success + */ + 200: Blob | File; +}; + +export type FileResponseResponse = FileResponseResponses[keyof FileResponseResponses]; export type ComplexTypesData = { body?: never; @@ -1398,16 +1576,41 @@ export type ComplexTypesData = { }; }; -export type ComplexTypesResponse = Array; +export type ComplexTypesErrors = { + /** + * 400 `server` error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type ComplexTypesResponses = { + /** + * Successful response + */ + 200: Array; +}; -export type MultipartResponseResponse = { - file?: Blob | File; - metadata?: { - foo?: string; - bar?: string; +export type ComplexTypesResponse = ComplexTypesResponses[keyof ComplexTypesResponses]; + +export type MultipartResponseResponses = { + /** + * OK + */ + 200: { + file?: Blob | File; + metadata?: { + foo?: string; + bar?: string; + }; }; }; +export type MultipartResponseResponse = MultipartResponseResponses[keyof MultipartResponseResponses]; + export type MultipartRequestData = { body?: { content?: Blob | File; @@ -1439,7 +1642,32 @@ export type ComplexParamsData = { query?: never; }; -export type ComplexParamsResponse = ModelWithString; +export type ComplexParamsResponses = { + /** + * Success + */ + 200: ModelWithString; +}; + +export type ComplexParamsResponse = ComplexParamsResponses[keyof ComplexParamsResponses]; + +export type CallWithResultFromHeaderErrors = { + /** + * 400 server error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type CallWithResultFromHeaderResponses = { + /** + * Successful response + */ + 200: unknown; +}; export type TestErrorCodeData = { body?: never; @@ -1452,6 +1680,32 @@ export type TestErrorCodeData = { }; }; +export type TestErrorCodeErrors = { + /** + * Custom message: Internal Server Error + */ + 500: unknown; + /** + * Custom message: Not Implemented + */ + 501: unknown; + /** + * Custom message: Bad Gateway + */ + 502: unknown; + /** + * Custom message: Service Unavailable + */ + 503: unknown; +}; + +export type TestErrorCodeResponses = { + /** + * Custom message: Successful response + */ + 200: unknown; +}; + export type NonAsciiæøåÆøÅöôêÊ字符串Data = { body?: never; path?: never; @@ -1463,7 +1717,14 @@ export type NonAsciiæøåÆøÅöôêÊ字符串Data = { }; }; -export type NonAsciiæøåÆøÅöôêÊ字符串Response = Array; +export type NonAsciiæøåÆøÅöôêÊ字符串Responses = { + /** + * Successful response + */ + 200: Array; +}; + +export type NonAsciiæøåÆøÅöôêÊ字符串Response = NonAsciiæøåÆøÅöôêÊ字符串Responses[keyof NonAsciiæøåÆøÅöôêÊ字符串Responses]; export type PutWithFormUrlEncodedData = { body: ArrayWithStrings; 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 b914fd963..37046a7eb 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 @@ -947,9 +947,27 @@ export type ImportData = { body: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; }; -export type ImportResponse = Model_From_Zendesk | ModelWithReadOnlyAndWriteOnly; +export type ImportResponses = { + /** + * Success + */ + 200: Model_From_Zendesk; + /** + * Default success response + */ + default: ModelWithReadOnlyAndWriteOnly; +}; + +export type ImportResponse = ImportResponses[keyof ImportResponses]; + +export type ApiVversionOdataControllerCountResponses = { + /** + * Success + */ + 200: Model_From_Zendesk; +}; -export type ApiVversionOdataControllerCountResponse = Model_From_Zendesk; +export type ApiVversionOdataControllerCountResponse = ApiVversionOdataControllerCountResponses[keyof ApiVversionOdataControllerCountResponses]; export type GetApiVbyApiVersionSimpleOperationData = { body?: never; @@ -962,9 +980,23 @@ export type GetApiVbyApiVersionSimpleOperationData = { query?: never; }; -export type GetApiVbyApiVersionSimpleOperationError = ModelWithBoolean; +export type GetApiVbyApiVersionSimpleOperationErrors = { + /** + * Default error response + */ + default: ModelWithBoolean; +}; -export type GetApiVbyApiVersionSimpleOperationResponse = number; +export type GetApiVbyApiVersionSimpleOperationError = GetApiVbyApiVersionSimpleOperationErrors[keyof GetApiVbyApiVersionSimpleOperationErrors]; + +export type GetApiVbyApiVersionSimpleOperationResponses = { + /** + * Response is a simple number + */ + 200: number; +}; + +export type GetApiVbyApiVersionSimpleOperationResponse = GetApiVbyApiVersionSimpleOperationResponses[keyof GetApiVbyApiVersionSimpleOperationResponses]; export type DeleteFooData3 = { body?: never; @@ -1136,7 +1168,18 @@ export type PostCallWithOptionalParamData = { }; }; -export type PostCallWithOptionalParamResponse = number | void; +export type PostCallWithOptionalParamResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; + +export type PostCallWithOptionalParamResponse = PostCallWithOptionalParamResponses[keyof PostCallWithOptionalParamResponses]; export type PostApiVbyApiVersionRequestBodyData = { /** @@ -1259,27 +1302,132 @@ export type CallToTestOrderOfParamsData = { }; }; -export type CallWithNoContentResponseResponse = void; +export type CallWithNoContentResponseResponses = { + /** + * Success + */ + 204: void; +}; -export type CallWithResponseAndNoContentResponseResponse = number | void; +export type CallWithNoContentResponseResponse = CallWithNoContentResponseResponses[keyof CallWithNoContentResponseResponses]; -export type DummyAResponse = _400; +export type CallWithResponseAndNoContentResponseResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; -export type DummyBResponse = void; +export type CallWithResponseAndNoContentResponseResponse = CallWithResponseAndNoContentResponseResponses[keyof CallWithResponseAndNoContentResponseResponses]; -export type CallWithResponseResponse = _import; +export type DummyAResponses = { + 200: _400; +}; -export type CallWithDuplicateResponsesError = ModelWithStringError | DictionaryWithArray | ModelWithBoolean; +export type DummyAResponse = DummyAResponses[keyof DummyAResponses]; -export type CallWithDuplicateResponsesResponse = (ModelWithBoolean & ModelWithInteger) | ModelWithString; +export type DummyBResponses = { + /** + * Success + */ + 204: void; +}; -export type CallWithResponsesError = ModelWithStringError; +export type DummyBResponse = DummyBResponses[keyof DummyBResponses]; -export type CallWithResponsesResponse = { - readonly '@namespace.string'?: string; - readonly '@namespace.integer'?: number; - readonly value?: Array; -} | ModelThatExtends | ModelThatExtendsExtends; +export type CallWithResponseResponses = { + default: _import; +}; + +export type CallWithResponseResponse = CallWithResponseResponses[keyof CallWithResponseResponses]; + +export type CallWithDuplicateResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for 4XX errors + */ + '4XX': DictionaryWithArray; + /** + * Default error response + */ + default: ModelWithBoolean; +}; + +export type CallWithDuplicateResponsesError = CallWithDuplicateResponsesErrors[keyof CallWithDuplicateResponsesErrors]; + +export type CallWithDuplicateResponsesResponses = { + /** + * Message for 200 response + */ + 200: ModelWithBoolean & ModelWithInteger; + /** + * Message for 201 response + */ + 201: ModelWithString; + /** + * Message for 202 response + */ + 202: ModelWithString; +}; + +export type CallWithDuplicateResponsesResponse = CallWithDuplicateResponsesResponses[keyof CallWithDuplicateResponsesResponses]; + +export type CallWithResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for default response + */ + default: ModelWithStringError; +}; + +export type CallWithResponsesError = CallWithResponsesErrors[keyof CallWithResponsesErrors]; + +export type CallWithResponsesResponses = { + /** + * Message for 200 response + */ + 200: { + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; + readonly value?: Array; + }; + /** + * Message for 201 response + */ + 201: ModelThatExtends; + /** + * Message for 202 response + */ + 202: ModelThatExtendsExtends; +}; + +export type CallWithResponsesResponse = CallWithResponsesResponses[keyof CallWithResponsesResponses]; export type CollectionFormatData = { body?: never; @@ -1348,7 +1496,26 @@ export type TypesData = { }; }; -export type TypesResponse = number | string | boolean | {}; +export type TypesResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Response is a simple string + */ + 201: string; + /** + * Response is a simple boolean + */ + 202: boolean; + /** + * Response is a simple object + */ + 203: {}; +}; + +export type TypesResponse = TypesResponses[keyof TypesResponses]; export type UploadFileData = { body: Blob | File; @@ -1361,7 +1528,11 @@ export type UploadFileData = { query?: never; }; -export type UploadFileResponse = boolean; +export type UploadFileResponses = { + 200: boolean; +}; + +export type UploadFileResponse = UploadFileResponses[keyof UploadFileResponses]; export type FileResponseData = { body?: never; @@ -1375,7 +1546,14 @@ export type FileResponseData = { query?: never; }; -export type FileResponseResponse = Blob | File; +export type FileResponseResponses = { + /** + * Success + */ + 200: Blob | File; +}; + +export type FileResponseResponse = FileResponseResponses[keyof FileResponseResponses]; export type ComplexTypesData = { body?: never; @@ -1398,16 +1576,41 @@ export type ComplexTypesData = { }; }; -export type ComplexTypesResponse = Array; +export type ComplexTypesErrors = { + /** + * 400 `server` error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type ComplexTypesResponses = { + /** + * Successful response + */ + 200: Array; +}; -export type MultipartResponseResponse = { - file?: Blob | File; - metadata?: { - foo?: string; - bar?: string; +export type ComplexTypesResponse = ComplexTypesResponses[keyof ComplexTypesResponses]; + +export type MultipartResponseResponses = { + /** + * OK + */ + 200: { + file?: Blob | File; + metadata?: { + foo?: string; + bar?: string; + }; }; }; +export type MultipartResponseResponse = MultipartResponseResponses[keyof MultipartResponseResponses]; + export type MultipartRequestData = { body?: { content?: Blob | File; @@ -1439,7 +1642,32 @@ export type ComplexParamsData = { query?: never; }; -export type ComplexParamsResponse = ModelWithString; +export type ComplexParamsResponses = { + /** + * Success + */ + 200: ModelWithString; +}; + +export type ComplexParamsResponse = ComplexParamsResponses[keyof ComplexParamsResponses]; + +export type CallWithResultFromHeaderErrors = { + /** + * 400 server error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type CallWithResultFromHeaderResponses = { + /** + * Successful response + */ + 200: unknown; +}; export type TestErrorCodeData = { body?: never; @@ -1452,6 +1680,32 @@ export type TestErrorCodeData = { }; }; +export type TestErrorCodeErrors = { + /** + * Custom message: Internal Server Error + */ + 500: unknown; + /** + * Custom message: Not Implemented + */ + 501: unknown; + /** + * Custom message: Bad Gateway + */ + 502: unknown; + /** + * Custom message: Service Unavailable + */ + 503: unknown; +}; + +export type TestErrorCodeResponses = { + /** + * Custom message: Successful response + */ + 200: unknown; +}; + export type NonAsciiæøåÆøÅöôêÊ字符串Data = { body?: never; path?: never; @@ -1463,7 +1717,14 @@ export type NonAsciiæøåÆøÅöôêÊ字符串Data = { }; }; -export type NonAsciiæøåÆøÅöôêÊ字符串Response = Array; +export type NonAsciiæøåÆøÅöôêÊ字符串Responses = { + /** + * Successful response + */ + 200: Array; +}; + +export type NonAsciiæøåÆøÅöôêÊ字符串Response = NonAsciiæøåÆøÅöôêÊ字符串Responses[keyof NonAsciiæøåÆøÅöôêÊ字符串Responses]; export type PutWithFormUrlEncodedData = { body: ArrayWithStrings; 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 b914fd963..37046a7eb 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 @@ -947,9 +947,27 @@ export type ImportData = { body: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; }; -export type ImportResponse = Model_From_Zendesk | ModelWithReadOnlyAndWriteOnly; +export type ImportResponses = { + /** + * Success + */ + 200: Model_From_Zendesk; + /** + * Default success response + */ + default: ModelWithReadOnlyAndWriteOnly; +}; + +export type ImportResponse = ImportResponses[keyof ImportResponses]; + +export type ApiVversionOdataControllerCountResponses = { + /** + * Success + */ + 200: Model_From_Zendesk; +}; -export type ApiVversionOdataControllerCountResponse = Model_From_Zendesk; +export type ApiVversionOdataControllerCountResponse = ApiVversionOdataControllerCountResponses[keyof ApiVversionOdataControllerCountResponses]; export type GetApiVbyApiVersionSimpleOperationData = { body?: never; @@ -962,9 +980,23 @@ export type GetApiVbyApiVersionSimpleOperationData = { query?: never; }; -export type GetApiVbyApiVersionSimpleOperationError = ModelWithBoolean; +export type GetApiVbyApiVersionSimpleOperationErrors = { + /** + * Default error response + */ + default: ModelWithBoolean; +}; -export type GetApiVbyApiVersionSimpleOperationResponse = number; +export type GetApiVbyApiVersionSimpleOperationError = GetApiVbyApiVersionSimpleOperationErrors[keyof GetApiVbyApiVersionSimpleOperationErrors]; + +export type GetApiVbyApiVersionSimpleOperationResponses = { + /** + * Response is a simple number + */ + 200: number; +}; + +export type GetApiVbyApiVersionSimpleOperationResponse = GetApiVbyApiVersionSimpleOperationResponses[keyof GetApiVbyApiVersionSimpleOperationResponses]; export type DeleteFooData3 = { body?: never; @@ -1136,7 +1168,18 @@ export type PostCallWithOptionalParamData = { }; }; -export type PostCallWithOptionalParamResponse = number | void; +export type PostCallWithOptionalParamResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; + +export type PostCallWithOptionalParamResponse = PostCallWithOptionalParamResponses[keyof PostCallWithOptionalParamResponses]; export type PostApiVbyApiVersionRequestBodyData = { /** @@ -1259,27 +1302,132 @@ export type CallToTestOrderOfParamsData = { }; }; -export type CallWithNoContentResponseResponse = void; +export type CallWithNoContentResponseResponses = { + /** + * Success + */ + 204: void; +}; -export type CallWithResponseAndNoContentResponseResponse = number | void; +export type CallWithNoContentResponseResponse = CallWithNoContentResponseResponses[keyof CallWithNoContentResponseResponses]; -export type DummyAResponse = _400; +export type CallWithResponseAndNoContentResponseResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; -export type DummyBResponse = void; +export type CallWithResponseAndNoContentResponseResponse = CallWithResponseAndNoContentResponseResponses[keyof CallWithResponseAndNoContentResponseResponses]; -export type CallWithResponseResponse = _import; +export type DummyAResponses = { + 200: _400; +}; -export type CallWithDuplicateResponsesError = ModelWithStringError | DictionaryWithArray | ModelWithBoolean; +export type DummyAResponse = DummyAResponses[keyof DummyAResponses]; -export type CallWithDuplicateResponsesResponse = (ModelWithBoolean & ModelWithInteger) | ModelWithString; +export type DummyBResponses = { + /** + * Success + */ + 204: void; +}; -export type CallWithResponsesError = ModelWithStringError; +export type DummyBResponse = DummyBResponses[keyof DummyBResponses]; -export type CallWithResponsesResponse = { - readonly '@namespace.string'?: string; - readonly '@namespace.integer'?: number; - readonly value?: Array; -} | ModelThatExtends | ModelThatExtendsExtends; +export type CallWithResponseResponses = { + default: _import; +}; + +export type CallWithResponseResponse = CallWithResponseResponses[keyof CallWithResponseResponses]; + +export type CallWithDuplicateResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for 4XX errors + */ + '4XX': DictionaryWithArray; + /** + * Default error response + */ + default: ModelWithBoolean; +}; + +export type CallWithDuplicateResponsesError = CallWithDuplicateResponsesErrors[keyof CallWithDuplicateResponsesErrors]; + +export type CallWithDuplicateResponsesResponses = { + /** + * Message for 200 response + */ + 200: ModelWithBoolean & ModelWithInteger; + /** + * Message for 201 response + */ + 201: ModelWithString; + /** + * Message for 202 response + */ + 202: ModelWithString; +}; + +export type CallWithDuplicateResponsesResponse = CallWithDuplicateResponsesResponses[keyof CallWithDuplicateResponsesResponses]; + +export type CallWithResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for default response + */ + default: ModelWithStringError; +}; + +export type CallWithResponsesError = CallWithResponsesErrors[keyof CallWithResponsesErrors]; + +export type CallWithResponsesResponses = { + /** + * Message for 200 response + */ + 200: { + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; + readonly value?: Array; + }; + /** + * Message for 201 response + */ + 201: ModelThatExtends; + /** + * Message for 202 response + */ + 202: ModelThatExtendsExtends; +}; + +export type CallWithResponsesResponse = CallWithResponsesResponses[keyof CallWithResponsesResponses]; export type CollectionFormatData = { body?: never; @@ -1348,7 +1496,26 @@ export type TypesData = { }; }; -export type TypesResponse = number | string | boolean | {}; +export type TypesResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Response is a simple string + */ + 201: string; + /** + * Response is a simple boolean + */ + 202: boolean; + /** + * Response is a simple object + */ + 203: {}; +}; + +export type TypesResponse = TypesResponses[keyof TypesResponses]; export type UploadFileData = { body: Blob | File; @@ -1361,7 +1528,11 @@ export type UploadFileData = { query?: never; }; -export type UploadFileResponse = boolean; +export type UploadFileResponses = { + 200: boolean; +}; + +export type UploadFileResponse = UploadFileResponses[keyof UploadFileResponses]; export type FileResponseData = { body?: never; @@ -1375,7 +1546,14 @@ export type FileResponseData = { query?: never; }; -export type FileResponseResponse = Blob | File; +export type FileResponseResponses = { + /** + * Success + */ + 200: Blob | File; +}; + +export type FileResponseResponse = FileResponseResponses[keyof FileResponseResponses]; export type ComplexTypesData = { body?: never; @@ -1398,16 +1576,41 @@ export type ComplexTypesData = { }; }; -export type ComplexTypesResponse = Array; +export type ComplexTypesErrors = { + /** + * 400 `server` error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type ComplexTypesResponses = { + /** + * Successful response + */ + 200: Array; +}; -export type MultipartResponseResponse = { - file?: Blob | File; - metadata?: { - foo?: string; - bar?: string; +export type ComplexTypesResponse = ComplexTypesResponses[keyof ComplexTypesResponses]; + +export type MultipartResponseResponses = { + /** + * OK + */ + 200: { + file?: Blob | File; + metadata?: { + foo?: string; + bar?: string; + }; }; }; +export type MultipartResponseResponse = MultipartResponseResponses[keyof MultipartResponseResponses]; + export type MultipartRequestData = { body?: { content?: Blob | File; @@ -1439,7 +1642,32 @@ export type ComplexParamsData = { query?: never; }; -export type ComplexParamsResponse = ModelWithString; +export type ComplexParamsResponses = { + /** + * Success + */ + 200: ModelWithString; +}; + +export type ComplexParamsResponse = ComplexParamsResponses[keyof ComplexParamsResponses]; + +export type CallWithResultFromHeaderErrors = { + /** + * 400 server error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type CallWithResultFromHeaderResponses = { + /** + * Successful response + */ + 200: unknown; +}; export type TestErrorCodeData = { body?: never; @@ -1452,6 +1680,32 @@ export type TestErrorCodeData = { }; }; +export type TestErrorCodeErrors = { + /** + * Custom message: Internal Server Error + */ + 500: unknown; + /** + * Custom message: Not Implemented + */ + 501: unknown; + /** + * Custom message: Bad Gateway + */ + 502: unknown; + /** + * Custom message: Service Unavailable + */ + 503: unknown; +}; + +export type TestErrorCodeResponses = { + /** + * Custom message: Successful response + */ + 200: unknown; +}; + export type NonAsciiæøåÆøÅöôêÊ字符串Data = { body?: never; path?: never; @@ -1463,7 +1717,14 @@ export type NonAsciiæøåÆøÅöôêÊ字符串Data = { }; }; -export type NonAsciiæøåÆøÅöôêÊ字符串Response = Array; +export type NonAsciiæøåÆøÅöôêÊ字符串Responses = { + /** + * Successful response + */ + 200: Array; +}; + +export type NonAsciiæøåÆøÅöôêÊ字符串Response = NonAsciiæøåÆøÅöôêÊ字符串Responses[keyof NonAsciiæøåÆøÅöôêÊ字符串Responses]; export type PutWithFormUrlEncodedData = { body: ArrayWithStrings; 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 b914fd963..37046a7eb 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 @@ -947,9 +947,27 @@ export type ImportData = { body: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; }; -export type ImportResponse = Model_From_Zendesk | ModelWithReadOnlyAndWriteOnly; +export type ImportResponses = { + /** + * Success + */ + 200: Model_From_Zendesk; + /** + * Default success response + */ + default: ModelWithReadOnlyAndWriteOnly; +}; + +export type ImportResponse = ImportResponses[keyof ImportResponses]; + +export type ApiVversionOdataControllerCountResponses = { + /** + * Success + */ + 200: Model_From_Zendesk; +}; -export type ApiVversionOdataControllerCountResponse = Model_From_Zendesk; +export type ApiVversionOdataControllerCountResponse = ApiVversionOdataControllerCountResponses[keyof ApiVversionOdataControllerCountResponses]; export type GetApiVbyApiVersionSimpleOperationData = { body?: never; @@ -962,9 +980,23 @@ export type GetApiVbyApiVersionSimpleOperationData = { query?: never; }; -export type GetApiVbyApiVersionSimpleOperationError = ModelWithBoolean; +export type GetApiVbyApiVersionSimpleOperationErrors = { + /** + * Default error response + */ + default: ModelWithBoolean; +}; -export type GetApiVbyApiVersionSimpleOperationResponse = number; +export type GetApiVbyApiVersionSimpleOperationError = GetApiVbyApiVersionSimpleOperationErrors[keyof GetApiVbyApiVersionSimpleOperationErrors]; + +export type GetApiVbyApiVersionSimpleOperationResponses = { + /** + * Response is a simple number + */ + 200: number; +}; + +export type GetApiVbyApiVersionSimpleOperationResponse = GetApiVbyApiVersionSimpleOperationResponses[keyof GetApiVbyApiVersionSimpleOperationResponses]; export type DeleteFooData3 = { body?: never; @@ -1136,7 +1168,18 @@ export type PostCallWithOptionalParamData = { }; }; -export type PostCallWithOptionalParamResponse = number | void; +export type PostCallWithOptionalParamResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; + +export type PostCallWithOptionalParamResponse = PostCallWithOptionalParamResponses[keyof PostCallWithOptionalParamResponses]; export type PostApiVbyApiVersionRequestBodyData = { /** @@ -1259,27 +1302,132 @@ export type CallToTestOrderOfParamsData = { }; }; -export type CallWithNoContentResponseResponse = void; +export type CallWithNoContentResponseResponses = { + /** + * Success + */ + 204: void; +}; -export type CallWithResponseAndNoContentResponseResponse = number | void; +export type CallWithNoContentResponseResponse = CallWithNoContentResponseResponses[keyof CallWithNoContentResponseResponses]; -export type DummyAResponse = _400; +export type CallWithResponseAndNoContentResponseResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; -export type DummyBResponse = void; +export type CallWithResponseAndNoContentResponseResponse = CallWithResponseAndNoContentResponseResponses[keyof CallWithResponseAndNoContentResponseResponses]; -export type CallWithResponseResponse = _import; +export type DummyAResponses = { + 200: _400; +}; -export type CallWithDuplicateResponsesError = ModelWithStringError | DictionaryWithArray | ModelWithBoolean; +export type DummyAResponse = DummyAResponses[keyof DummyAResponses]; -export type CallWithDuplicateResponsesResponse = (ModelWithBoolean & ModelWithInteger) | ModelWithString; +export type DummyBResponses = { + /** + * Success + */ + 204: void; +}; -export type CallWithResponsesError = ModelWithStringError; +export type DummyBResponse = DummyBResponses[keyof DummyBResponses]; -export type CallWithResponsesResponse = { - readonly '@namespace.string'?: string; - readonly '@namespace.integer'?: number; - readonly value?: Array; -} | ModelThatExtends | ModelThatExtendsExtends; +export type CallWithResponseResponses = { + default: _import; +}; + +export type CallWithResponseResponse = CallWithResponseResponses[keyof CallWithResponseResponses]; + +export type CallWithDuplicateResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for 4XX errors + */ + '4XX': DictionaryWithArray; + /** + * Default error response + */ + default: ModelWithBoolean; +}; + +export type CallWithDuplicateResponsesError = CallWithDuplicateResponsesErrors[keyof CallWithDuplicateResponsesErrors]; + +export type CallWithDuplicateResponsesResponses = { + /** + * Message for 200 response + */ + 200: ModelWithBoolean & ModelWithInteger; + /** + * Message for 201 response + */ + 201: ModelWithString; + /** + * Message for 202 response + */ + 202: ModelWithString; +}; + +export type CallWithDuplicateResponsesResponse = CallWithDuplicateResponsesResponses[keyof CallWithDuplicateResponsesResponses]; + +export type CallWithResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for default response + */ + default: ModelWithStringError; +}; + +export type CallWithResponsesError = CallWithResponsesErrors[keyof CallWithResponsesErrors]; + +export type CallWithResponsesResponses = { + /** + * Message for 200 response + */ + 200: { + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; + readonly value?: Array; + }; + /** + * Message for 201 response + */ + 201: ModelThatExtends; + /** + * Message for 202 response + */ + 202: ModelThatExtendsExtends; +}; + +export type CallWithResponsesResponse = CallWithResponsesResponses[keyof CallWithResponsesResponses]; export type CollectionFormatData = { body?: never; @@ -1348,7 +1496,26 @@ export type TypesData = { }; }; -export type TypesResponse = number | string | boolean | {}; +export type TypesResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Response is a simple string + */ + 201: string; + /** + * Response is a simple boolean + */ + 202: boolean; + /** + * Response is a simple object + */ + 203: {}; +}; + +export type TypesResponse = TypesResponses[keyof TypesResponses]; export type UploadFileData = { body: Blob | File; @@ -1361,7 +1528,11 @@ export type UploadFileData = { query?: never; }; -export type UploadFileResponse = boolean; +export type UploadFileResponses = { + 200: boolean; +}; + +export type UploadFileResponse = UploadFileResponses[keyof UploadFileResponses]; export type FileResponseData = { body?: never; @@ -1375,7 +1546,14 @@ export type FileResponseData = { query?: never; }; -export type FileResponseResponse = Blob | File; +export type FileResponseResponses = { + /** + * Success + */ + 200: Blob | File; +}; + +export type FileResponseResponse = FileResponseResponses[keyof FileResponseResponses]; export type ComplexTypesData = { body?: never; @@ -1398,16 +1576,41 @@ export type ComplexTypesData = { }; }; -export type ComplexTypesResponse = Array; +export type ComplexTypesErrors = { + /** + * 400 `server` error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type ComplexTypesResponses = { + /** + * Successful response + */ + 200: Array; +}; -export type MultipartResponseResponse = { - file?: Blob | File; - metadata?: { - foo?: string; - bar?: string; +export type ComplexTypesResponse = ComplexTypesResponses[keyof ComplexTypesResponses]; + +export type MultipartResponseResponses = { + /** + * OK + */ + 200: { + file?: Blob | File; + metadata?: { + foo?: string; + bar?: string; + }; }; }; +export type MultipartResponseResponse = MultipartResponseResponses[keyof MultipartResponseResponses]; + export type MultipartRequestData = { body?: { content?: Blob | File; @@ -1439,7 +1642,32 @@ export type ComplexParamsData = { query?: never; }; -export type ComplexParamsResponse = ModelWithString; +export type ComplexParamsResponses = { + /** + * Success + */ + 200: ModelWithString; +}; + +export type ComplexParamsResponse = ComplexParamsResponses[keyof ComplexParamsResponses]; + +export type CallWithResultFromHeaderErrors = { + /** + * 400 server error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type CallWithResultFromHeaderResponses = { + /** + * Successful response + */ + 200: unknown; +}; export type TestErrorCodeData = { body?: never; @@ -1452,6 +1680,32 @@ export type TestErrorCodeData = { }; }; +export type TestErrorCodeErrors = { + /** + * Custom message: Internal Server Error + */ + 500: unknown; + /** + * Custom message: Not Implemented + */ + 501: unknown; + /** + * Custom message: Bad Gateway + */ + 502: unknown; + /** + * Custom message: Service Unavailable + */ + 503: unknown; +}; + +export type TestErrorCodeResponses = { + /** + * Custom message: Successful response + */ + 200: unknown; +}; + export type NonAsciiæøåÆøÅöôêÊ字符串Data = { body?: never; path?: never; @@ -1463,7 +1717,14 @@ export type NonAsciiæøåÆøÅöôêÊ字符串Data = { }; }; -export type NonAsciiæøåÆøÅöôêÊ字符串Response = Array; +export type NonAsciiæøåÆøÅöôêÊ字符串Responses = { + /** + * Successful response + */ + 200: Array; +}; + +export type NonAsciiæøåÆøÅöôêÊ字符串Response = NonAsciiæøåÆøÅöôêÊ字符串Responses[keyof NonAsciiæøåÆøÅöôêÊ字符串Responses]; export type PutWithFormUrlEncodedData = { body: ArrayWithStrings; 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 b914fd963..37046a7eb 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 @@ -947,9 +947,27 @@ export type ImportData = { body: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; }; -export type ImportResponse = Model_From_Zendesk | ModelWithReadOnlyAndWriteOnly; +export type ImportResponses = { + /** + * Success + */ + 200: Model_From_Zendesk; + /** + * Default success response + */ + default: ModelWithReadOnlyAndWriteOnly; +}; + +export type ImportResponse = ImportResponses[keyof ImportResponses]; + +export type ApiVversionOdataControllerCountResponses = { + /** + * Success + */ + 200: Model_From_Zendesk; +}; -export type ApiVversionOdataControllerCountResponse = Model_From_Zendesk; +export type ApiVversionOdataControllerCountResponse = ApiVversionOdataControllerCountResponses[keyof ApiVversionOdataControllerCountResponses]; export type GetApiVbyApiVersionSimpleOperationData = { body?: never; @@ -962,9 +980,23 @@ export type GetApiVbyApiVersionSimpleOperationData = { query?: never; }; -export type GetApiVbyApiVersionSimpleOperationError = ModelWithBoolean; +export type GetApiVbyApiVersionSimpleOperationErrors = { + /** + * Default error response + */ + default: ModelWithBoolean; +}; -export type GetApiVbyApiVersionSimpleOperationResponse = number; +export type GetApiVbyApiVersionSimpleOperationError = GetApiVbyApiVersionSimpleOperationErrors[keyof GetApiVbyApiVersionSimpleOperationErrors]; + +export type GetApiVbyApiVersionSimpleOperationResponses = { + /** + * Response is a simple number + */ + 200: number; +}; + +export type GetApiVbyApiVersionSimpleOperationResponse = GetApiVbyApiVersionSimpleOperationResponses[keyof GetApiVbyApiVersionSimpleOperationResponses]; export type DeleteFooData3 = { body?: never; @@ -1136,7 +1168,18 @@ export type PostCallWithOptionalParamData = { }; }; -export type PostCallWithOptionalParamResponse = number | void; +export type PostCallWithOptionalParamResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; + +export type PostCallWithOptionalParamResponse = PostCallWithOptionalParamResponses[keyof PostCallWithOptionalParamResponses]; export type PostApiVbyApiVersionRequestBodyData = { /** @@ -1259,27 +1302,132 @@ export type CallToTestOrderOfParamsData = { }; }; -export type CallWithNoContentResponseResponse = void; +export type CallWithNoContentResponseResponses = { + /** + * Success + */ + 204: void; +}; -export type CallWithResponseAndNoContentResponseResponse = number | void; +export type CallWithNoContentResponseResponse = CallWithNoContentResponseResponses[keyof CallWithNoContentResponseResponses]; -export type DummyAResponse = _400; +export type CallWithResponseAndNoContentResponseResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; -export type DummyBResponse = void; +export type CallWithResponseAndNoContentResponseResponse = CallWithResponseAndNoContentResponseResponses[keyof CallWithResponseAndNoContentResponseResponses]; -export type CallWithResponseResponse = _import; +export type DummyAResponses = { + 200: _400; +}; -export type CallWithDuplicateResponsesError = ModelWithStringError | DictionaryWithArray | ModelWithBoolean; +export type DummyAResponse = DummyAResponses[keyof DummyAResponses]; -export type CallWithDuplicateResponsesResponse = (ModelWithBoolean & ModelWithInteger) | ModelWithString; +export type DummyBResponses = { + /** + * Success + */ + 204: void; +}; -export type CallWithResponsesError = ModelWithStringError; +export type DummyBResponse = DummyBResponses[keyof DummyBResponses]; -export type CallWithResponsesResponse = { - readonly '@namespace.string'?: string; - readonly '@namespace.integer'?: number; - readonly value?: Array; -} | ModelThatExtends | ModelThatExtendsExtends; +export type CallWithResponseResponses = { + default: _import; +}; + +export type CallWithResponseResponse = CallWithResponseResponses[keyof CallWithResponseResponses]; + +export type CallWithDuplicateResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for 4XX errors + */ + '4XX': DictionaryWithArray; + /** + * Default error response + */ + default: ModelWithBoolean; +}; + +export type CallWithDuplicateResponsesError = CallWithDuplicateResponsesErrors[keyof CallWithDuplicateResponsesErrors]; + +export type CallWithDuplicateResponsesResponses = { + /** + * Message for 200 response + */ + 200: ModelWithBoolean & ModelWithInteger; + /** + * Message for 201 response + */ + 201: ModelWithString; + /** + * Message for 202 response + */ + 202: ModelWithString; +}; + +export type CallWithDuplicateResponsesResponse = CallWithDuplicateResponsesResponses[keyof CallWithDuplicateResponsesResponses]; + +export type CallWithResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for default response + */ + default: ModelWithStringError; +}; + +export type CallWithResponsesError = CallWithResponsesErrors[keyof CallWithResponsesErrors]; + +export type CallWithResponsesResponses = { + /** + * Message for 200 response + */ + 200: { + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; + readonly value?: Array; + }; + /** + * Message for 201 response + */ + 201: ModelThatExtends; + /** + * Message for 202 response + */ + 202: ModelThatExtendsExtends; +}; + +export type CallWithResponsesResponse = CallWithResponsesResponses[keyof CallWithResponsesResponses]; export type CollectionFormatData = { body?: never; @@ -1348,7 +1496,26 @@ export type TypesData = { }; }; -export type TypesResponse = number | string | boolean | {}; +export type TypesResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Response is a simple string + */ + 201: string; + /** + * Response is a simple boolean + */ + 202: boolean; + /** + * Response is a simple object + */ + 203: {}; +}; + +export type TypesResponse = TypesResponses[keyof TypesResponses]; export type UploadFileData = { body: Blob | File; @@ -1361,7 +1528,11 @@ export type UploadFileData = { query?: never; }; -export type UploadFileResponse = boolean; +export type UploadFileResponses = { + 200: boolean; +}; + +export type UploadFileResponse = UploadFileResponses[keyof UploadFileResponses]; export type FileResponseData = { body?: never; @@ -1375,7 +1546,14 @@ export type FileResponseData = { query?: never; }; -export type FileResponseResponse = Blob | File; +export type FileResponseResponses = { + /** + * Success + */ + 200: Blob | File; +}; + +export type FileResponseResponse = FileResponseResponses[keyof FileResponseResponses]; export type ComplexTypesData = { body?: never; @@ -1398,16 +1576,41 @@ export type ComplexTypesData = { }; }; -export type ComplexTypesResponse = Array; +export type ComplexTypesErrors = { + /** + * 400 `server` error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type ComplexTypesResponses = { + /** + * Successful response + */ + 200: Array; +}; -export type MultipartResponseResponse = { - file?: Blob | File; - metadata?: { - foo?: string; - bar?: string; +export type ComplexTypesResponse = ComplexTypesResponses[keyof ComplexTypesResponses]; + +export type MultipartResponseResponses = { + /** + * OK + */ + 200: { + file?: Blob | File; + metadata?: { + foo?: string; + bar?: string; + }; }; }; +export type MultipartResponseResponse = MultipartResponseResponses[keyof MultipartResponseResponses]; + export type MultipartRequestData = { body?: { content?: Blob | File; @@ -1439,7 +1642,32 @@ export type ComplexParamsData = { query?: never; }; -export type ComplexParamsResponse = ModelWithString; +export type ComplexParamsResponses = { + /** + * Success + */ + 200: ModelWithString; +}; + +export type ComplexParamsResponse = ComplexParamsResponses[keyof ComplexParamsResponses]; + +export type CallWithResultFromHeaderErrors = { + /** + * 400 server error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type CallWithResultFromHeaderResponses = { + /** + * Successful response + */ + 200: unknown; +}; export type TestErrorCodeData = { body?: never; @@ -1452,6 +1680,32 @@ export type TestErrorCodeData = { }; }; +export type TestErrorCodeErrors = { + /** + * Custom message: Internal Server Error + */ + 500: unknown; + /** + * Custom message: Not Implemented + */ + 501: unknown; + /** + * Custom message: Bad Gateway + */ + 502: unknown; + /** + * Custom message: Service Unavailable + */ + 503: unknown; +}; + +export type TestErrorCodeResponses = { + /** + * Custom message: Successful response + */ + 200: unknown; +}; + export type NonAsciiæøåÆøÅöôêÊ字符串Data = { body?: never; path?: never; @@ -1463,7 +1717,14 @@ export type NonAsciiæøåÆøÅöôêÊ字符串Data = { }; }; -export type NonAsciiæøåÆøÅöôêÊ字符串Response = Array; +export type NonAsciiæøåÆøÅöôêÊ字符串Responses = { + /** + * Successful response + */ + 200: Array; +}; + +export type NonAsciiæøåÆøÅöôêÊ字符串Response = NonAsciiæøåÆøÅöôêÊ字符串Responses[keyof NonAsciiæøåÆøÅöôêÊ字符串Responses]; export type PutWithFormUrlEncodedData = { body: ArrayWithStrings; 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 b914fd963..37046a7eb 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 @@ -947,9 +947,27 @@ export type ImportData = { body: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; }; -export type ImportResponse = Model_From_Zendesk | ModelWithReadOnlyAndWriteOnly; +export type ImportResponses = { + /** + * Success + */ + 200: Model_From_Zendesk; + /** + * Default success response + */ + default: ModelWithReadOnlyAndWriteOnly; +}; + +export type ImportResponse = ImportResponses[keyof ImportResponses]; + +export type ApiVversionOdataControllerCountResponses = { + /** + * Success + */ + 200: Model_From_Zendesk; +}; -export type ApiVversionOdataControllerCountResponse = Model_From_Zendesk; +export type ApiVversionOdataControllerCountResponse = ApiVversionOdataControllerCountResponses[keyof ApiVversionOdataControllerCountResponses]; export type GetApiVbyApiVersionSimpleOperationData = { body?: never; @@ -962,9 +980,23 @@ export type GetApiVbyApiVersionSimpleOperationData = { query?: never; }; -export type GetApiVbyApiVersionSimpleOperationError = ModelWithBoolean; +export type GetApiVbyApiVersionSimpleOperationErrors = { + /** + * Default error response + */ + default: ModelWithBoolean; +}; -export type GetApiVbyApiVersionSimpleOperationResponse = number; +export type GetApiVbyApiVersionSimpleOperationError = GetApiVbyApiVersionSimpleOperationErrors[keyof GetApiVbyApiVersionSimpleOperationErrors]; + +export type GetApiVbyApiVersionSimpleOperationResponses = { + /** + * Response is a simple number + */ + 200: number; +}; + +export type GetApiVbyApiVersionSimpleOperationResponse = GetApiVbyApiVersionSimpleOperationResponses[keyof GetApiVbyApiVersionSimpleOperationResponses]; export type DeleteFooData3 = { body?: never; @@ -1136,7 +1168,18 @@ export type PostCallWithOptionalParamData = { }; }; -export type PostCallWithOptionalParamResponse = number | void; +export type PostCallWithOptionalParamResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; + +export type PostCallWithOptionalParamResponse = PostCallWithOptionalParamResponses[keyof PostCallWithOptionalParamResponses]; export type PostApiVbyApiVersionRequestBodyData = { /** @@ -1259,27 +1302,132 @@ export type CallToTestOrderOfParamsData = { }; }; -export type CallWithNoContentResponseResponse = void; +export type CallWithNoContentResponseResponses = { + /** + * Success + */ + 204: void; +}; -export type CallWithResponseAndNoContentResponseResponse = number | void; +export type CallWithNoContentResponseResponse = CallWithNoContentResponseResponses[keyof CallWithNoContentResponseResponses]; -export type DummyAResponse = _400; +export type CallWithResponseAndNoContentResponseResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; -export type DummyBResponse = void; +export type CallWithResponseAndNoContentResponseResponse = CallWithResponseAndNoContentResponseResponses[keyof CallWithResponseAndNoContentResponseResponses]; -export type CallWithResponseResponse = _import; +export type DummyAResponses = { + 200: _400; +}; -export type CallWithDuplicateResponsesError = ModelWithStringError | DictionaryWithArray | ModelWithBoolean; +export type DummyAResponse = DummyAResponses[keyof DummyAResponses]; -export type CallWithDuplicateResponsesResponse = (ModelWithBoolean & ModelWithInteger) | ModelWithString; +export type DummyBResponses = { + /** + * Success + */ + 204: void; +}; -export type CallWithResponsesError = ModelWithStringError; +export type DummyBResponse = DummyBResponses[keyof DummyBResponses]; -export type CallWithResponsesResponse = { - readonly '@namespace.string'?: string; - readonly '@namespace.integer'?: number; - readonly value?: Array; -} | ModelThatExtends | ModelThatExtendsExtends; +export type CallWithResponseResponses = { + default: _import; +}; + +export type CallWithResponseResponse = CallWithResponseResponses[keyof CallWithResponseResponses]; + +export type CallWithDuplicateResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for 4XX errors + */ + '4XX': DictionaryWithArray; + /** + * Default error response + */ + default: ModelWithBoolean; +}; + +export type CallWithDuplicateResponsesError = CallWithDuplicateResponsesErrors[keyof CallWithDuplicateResponsesErrors]; + +export type CallWithDuplicateResponsesResponses = { + /** + * Message for 200 response + */ + 200: ModelWithBoolean & ModelWithInteger; + /** + * Message for 201 response + */ + 201: ModelWithString; + /** + * Message for 202 response + */ + 202: ModelWithString; +}; + +export type CallWithDuplicateResponsesResponse = CallWithDuplicateResponsesResponses[keyof CallWithDuplicateResponsesResponses]; + +export type CallWithResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for default response + */ + default: ModelWithStringError; +}; + +export type CallWithResponsesError = CallWithResponsesErrors[keyof CallWithResponsesErrors]; + +export type CallWithResponsesResponses = { + /** + * Message for 200 response + */ + 200: { + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; + readonly value?: Array; + }; + /** + * Message for 201 response + */ + 201: ModelThatExtends; + /** + * Message for 202 response + */ + 202: ModelThatExtendsExtends; +}; + +export type CallWithResponsesResponse = CallWithResponsesResponses[keyof CallWithResponsesResponses]; export type CollectionFormatData = { body?: never; @@ -1348,7 +1496,26 @@ export type TypesData = { }; }; -export type TypesResponse = number | string | boolean | {}; +export type TypesResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Response is a simple string + */ + 201: string; + /** + * Response is a simple boolean + */ + 202: boolean; + /** + * Response is a simple object + */ + 203: {}; +}; + +export type TypesResponse = TypesResponses[keyof TypesResponses]; export type UploadFileData = { body: Blob | File; @@ -1361,7 +1528,11 @@ export type UploadFileData = { query?: never; }; -export type UploadFileResponse = boolean; +export type UploadFileResponses = { + 200: boolean; +}; + +export type UploadFileResponse = UploadFileResponses[keyof UploadFileResponses]; export type FileResponseData = { body?: never; @@ -1375,7 +1546,14 @@ export type FileResponseData = { query?: never; }; -export type FileResponseResponse = Blob | File; +export type FileResponseResponses = { + /** + * Success + */ + 200: Blob | File; +}; + +export type FileResponseResponse = FileResponseResponses[keyof FileResponseResponses]; export type ComplexTypesData = { body?: never; @@ -1398,16 +1576,41 @@ export type ComplexTypesData = { }; }; -export type ComplexTypesResponse = Array; +export type ComplexTypesErrors = { + /** + * 400 `server` error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type ComplexTypesResponses = { + /** + * Successful response + */ + 200: Array; +}; -export type MultipartResponseResponse = { - file?: Blob | File; - metadata?: { - foo?: string; - bar?: string; +export type ComplexTypesResponse = ComplexTypesResponses[keyof ComplexTypesResponses]; + +export type MultipartResponseResponses = { + /** + * OK + */ + 200: { + file?: Blob | File; + metadata?: { + foo?: string; + bar?: string; + }; }; }; +export type MultipartResponseResponse = MultipartResponseResponses[keyof MultipartResponseResponses]; + export type MultipartRequestData = { body?: { content?: Blob | File; @@ -1439,7 +1642,32 @@ export type ComplexParamsData = { query?: never; }; -export type ComplexParamsResponse = ModelWithString; +export type ComplexParamsResponses = { + /** + * Success + */ + 200: ModelWithString; +}; + +export type ComplexParamsResponse = ComplexParamsResponses[keyof ComplexParamsResponses]; + +export type CallWithResultFromHeaderErrors = { + /** + * 400 server error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type CallWithResultFromHeaderResponses = { + /** + * Successful response + */ + 200: unknown; +}; export type TestErrorCodeData = { body?: never; @@ -1452,6 +1680,32 @@ export type TestErrorCodeData = { }; }; +export type TestErrorCodeErrors = { + /** + * Custom message: Internal Server Error + */ + 500: unknown; + /** + * Custom message: Not Implemented + */ + 501: unknown; + /** + * Custom message: Bad Gateway + */ + 502: unknown; + /** + * Custom message: Service Unavailable + */ + 503: unknown; +}; + +export type TestErrorCodeResponses = { + /** + * Custom message: Successful response + */ + 200: unknown; +}; + export type NonAsciiæøåÆøÅöôêÊ字符串Data = { body?: never; path?: never; @@ -1463,7 +1717,14 @@ export type NonAsciiæøåÆøÅöôêÊ字符串Data = { }; }; -export type NonAsciiæøåÆøÅöôêÊ字符串Response = Array; +export type NonAsciiæøåÆøÅöôêÊ字符串Responses = { + /** + * Successful response + */ + 200: Array; +}; + +export type NonAsciiæøåÆøÅöôêÊ字符串Response = NonAsciiæøåÆøÅöôêÊ字符串Responses[keyof NonAsciiæøåÆøÅöôêÊ字符串Responses]; export type PutWithFormUrlEncodedData = { body: ArrayWithStrings; 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 b914fd963..37046a7eb 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 @@ -947,9 +947,27 @@ export type ImportData = { body: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; }; -export type ImportResponse = Model_From_Zendesk | ModelWithReadOnlyAndWriteOnly; +export type ImportResponses = { + /** + * Success + */ + 200: Model_From_Zendesk; + /** + * Default success response + */ + default: ModelWithReadOnlyAndWriteOnly; +}; + +export type ImportResponse = ImportResponses[keyof ImportResponses]; + +export type ApiVversionOdataControllerCountResponses = { + /** + * Success + */ + 200: Model_From_Zendesk; +}; -export type ApiVversionOdataControllerCountResponse = Model_From_Zendesk; +export type ApiVversionOdataControllerCountResponse = ApiVversionOdataControllerCountResponses[keyof ApiVversionOdataControllerCountResponses]; export type GetApiVbyApiVersionSimpleOperationData = { body?: never; @@ -962,9 +980,23 @@ export type GetApiVbyApiVersionSimpleOperationData = { query?: never; }; -export type GetApiVbyApiVersionSimpleOperationError = ModelWithBoolean; +export type GetApiVbyApiVersionSimpleOperationErrors = { + /** + * Default error response + */ + default: ModelWithBoolean; +}; -export type GetApiVbyApiVersionSimpleOperationResponse = number; +export type GetApiVbyApiVersionSimpleOperationError = GetApiVbyApiVersionSimpleOperationErrors[keyof GetApiVbyApiVersionSimpleOperationErrors]; + +export type GetApiVbyApiVersionSimpleOperationResponses = { + /** + * Response is a simple number + */ + 200: number; +}; + +export type GetApiVbyApiVersionSimpleOperationResponse = GetApiVbyApiVersionSimpleOperationResponses[keyof GetApiVbyApiVersionSimpleOperationResponses]; export type DeleteFooData3 = { body?: never; @@ -1136,7 +1168,18 @@ export type PostCallWithOptionalParamData = { }; }; -export type PostCallWithOptionalParamResponse = number | void; +export type PostCallWithOptionalParamResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; + +export type PostCallWithOptionalParamResponse = PostCallWithOptionalParamResponses[keyof PostCallWithOptionalParamResponses]; export type PostApiVbyApiVersionRequestBodyData = { /** @@ -1259,27 +1302,132 @@ export type CallToTestOrderOfParamsData = { }; }; -export type CallWithNoContentResponseResponse = void; +export type CallWithNoContentResponseResponses = { + /** + * Success + */ + 204: void; +}; -export type CallWithResponseAndNoContentResponseResponse = number | void; +export type CallWithNoContentResponseResponse = CallWithNoContentResponseResponses[keyof CallWithNoContentResponseResponses]; -export type DummyAResponse = _400; +export type CallWithResponseAndNoContentResponseResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; -export type DummyBResponse = void; +export type CallWithResponseAndNoContentResponseResponse = CallWithResponseAndNoContentResponseResponses[keyof CallWithResponseAndNoContentResponseResponses]; -export type CallWithResponseResponse = _import; +export type DummyAResponses = { + 200: _400; +}; -export type CallWithDuplicateResponsesError = ModelWithStringError | DictionaryWithArray | ModelWithBoolean; +export type DummyAResponse = DummyAResponses[keyof DummyAResponses]; -export type CallWithDuplicateResponsesResponse = (ModelWithBoolean & ModelWithInteger) | ModelWithString; +export type DummyBResponses = { + /** + * Success + */ + 204: void; +}; -export type CallWithResponsesError = ModelWithStringError; +export type DummyBResponse = DummyBResponses[keyof DummyBResponses]; -export type CallWithResponsesResponse = { - readonly '@namespace.string'?: string; - readonly '@namespace.integer'?: number; - readonly value?: Array; -} | ModelThatExtends | ModelThatExtendsExtends; +export type CallWithResponseResponses = { + default: _import; +}; + +export type CallWithResponseResponse = CallWithResponseResponses[keyof CallWithResponseResponses]; + +export type CallWithDuplicateResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for 4XX errors + */ + '4XX': DictionaryWithArray; + /** + * Default error response + */ + default: ModelWithBoolean; +}; + +export type CallWithDuplicateResponsesError = CallWithDuplicateResponsesErrors[keyof CallWithDuplicateResponsesErrors]; + +export type CallWithDuplicateResponsesResponses = { + /** + * Message for 200 response + */ + 200: ModelWithBoolean & ModelWithInteger; + /** + * Message for 201 response + */ + 201: ModelWithString; + /** + * Message for 202 response + */ + 202: ModelWithString; +}; + +export type CallWithDuplicateResponsesResponse = CallWithDuplicateResponsesResponses[keyof CallWithDuplicateResponsesResponses]; + +export type CallWithResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for default response + */ + default: ModelWithStringError; +}; + +export type CallWithResponsesError = CallWithResponsesErrors[keyof CallWithResponsesErrors]; + +export type CallWithResponsesResponses = { + /** + * Message for 200 response + */ + 200: { + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; + readonly value?: Array; + }; + /** + * Message for 201 response + */ + 201: ModelThatExtends; + /** + * Message for 202 response + */ + 202: ModelThatExtendsExtends; +}; + +export type CallWithResponsesResponse = CallWithResponsesResponses[keyof CallWithResponsesResponses]; export type CollectionFormatData = { body?: never; @@ -1348,7 +1496,26 @@ export type TypesData = { }; }; -export type TypesResponse = number | string | boolean | {}; +export type TypesResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Response is a simple string + */ + 201: string; + /** + * Response is a simple boolean + */ + 202: boolean; + /** + * Response is a simple object + */ + 203: {}; +}; + +export type TypesResponse = TypesResponses[keyof TypesResponses]; export type UploadFileData = { body: Blob | File; @@ -1361,7 +1528,11 @@ export type UploadFileData = { query?: never; }; -export type UploadFileResponse = boolean; +export type UploadFileResponses = { + 200: boolean; +}; + +export type UploadFileResponse = UploadFileResponses[keyof UploadFileResponses]; export type FileResponseData = { body?: never; @@ -1375,7 +1546,14 @@ export type FileResponseData = { query?: never; }; -export type FileResponseResponse = Blob | File; +export type FileResponseResponses = { + /** + * Success + */ + 200: Blob | File; +}; + +export type FileResponseResponse = FileResponseResponses[keyof FileResponseResponses]; export type ComplexTypesData = { body?: never; @@ -1398,16 +1576,41 @@ export type ComplexTypesData = { }; }; -export type ComplexTypesResponse = Array; +export type ComplexTypesErrors = { + /** + * 400 `server` error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type ComplexTypesResponses = { + /** + * Successful response + */ + 200: Array; +}; -export type MultipartResponseResponse = { - file?: Blob | File; - metadata?: { - foo?: string; - bar?: string; +export type ComplexTypesResponse = ComplexTypesResponses[keyof ComplexTypesResponses]; + +export type MultipartResponseResponses = { + /** + * OK + */ + 200: { + file?: Blob | File; + metadata?: { + foo?: string; + bar?: string; + }; }; }; +export type MultipartResponseResponse = MultipartResponseResponses[keyof MultipartResponseResponses]; + export type MultipartRequestData = { body?: { content?: Blob | File; @@ -1439,7 +1642,32 @@ export type ComplexParamsData = { query?: never; }; -export type ComplexParamsResponse = ModelWithString; +export type ComplexParamsResponses = { + /** + * Success + */ + 200: ModelWithString; +}; + +export type ComplexParamsResponse = ComplexParamsResponses[keyof ComplexParamsResponses]; + +export type CallWithResultFromHeaderErrors = { + /** + * 400 server error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type CallWithResultFromHeaderResponses = { + /** + * Successful response + */ + 200: unknown; +}; export type TestErrorCodeData = { body?: never; @@ -1452,6 +1680,32 @@ export type TestErrorCodeData = { }; }; +export type TestErrorCodeErrors = { + /** + * Custom message: Internal Server Error + */ + 500: unknown; + /** + * Custom message: Not Implemented + */ + 501: unknown; + /** + * Custom message: Bad Gateway + */ + 502: unknown; + /** + * Custom message: Service Unavailable + */ + 503: unknown; +}; + +export type TestErrorCodeResponses = { + /** + * Custom message: Successful response + */ + 200: unknown; +}; + export type NonAsciiæøåÆøÅöôêÊ字符串Data = { body?: never; path?: never; @@ -1463,7 +1717,14 @@ export type NonAsciiæøåÆøÅöôêÊ字符串Data = { }; }; -export type NonAsciiæøåÆøÅöôêÊ字符串Response = Array; +export type NonAsciiæøåÆøÅöôêÊ字符串Responses = { + /** + * Successful response + */ + 200: Array; +}; + +export type NonAsciiæøåÆøÅöôêÊ字符串Response = NonAsciiæøåÆøÅöôêÊ字符串Responses[keyof NonAsciiæøåÆøÅöôêÊ字符串Responses]; export type PutWithFormUrlEncodedData = { body: ArrayWithStrings; 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 b914fd963..37046a7eb 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 @@ -947,9 +947,27 @@ export type ImportData = { body: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; }; -export type ImportResponse = Model_From_Zendesk | ModelWithReadOnlyAndWriteOnly; +export type ImportResponses = { + /** + * Success + */ + 200: Model_From_Zendesk; + /** + * Default success response + */ + default: ModelWithReadOnlyAndWriteOnly; +}; + +export type ImportResponse = ImportResponses[keyof ImportResponses]; + +export type ApiVversionOdataControllerCountResponses = { + /** + * Success + */ + 200: Model_From_Zendesk; +}; -export type ApiVversionOdataControllerCountResponse = Model_From_Zendesk; +export type ApiVversionOdataControllerCountResponse = ApiVversionOdataControllerCountResponses[keyof ApiVversionOdataControllerCountResponses]; export type GetApiVbyApiVersionSimpleOperationData = { body?: never; @@ -962,9 +980,23 @@ export type GetApiVbyApiVersionSimpleOperationData = { query?: never; }; -export type GetApiVbyApiVersionSimpleOperationError = ModelWithBoolean; +export type GetApiVbyApiVersionSimpleOperationErrors = { + /** + * Default error response + */ + default: ModelWithBoolean; +}; -export type GetApiVbyApiVersionSimpleOperationResponse = number; +export type GetApiVbyApiVersionSimpleOperationError = GetApiVbyApiVersionSimpleOperationErrors[keyof GetApiVbyApiVersionSimpleOperationErrors]; + +export type GetApiVbyApiVersionSimpleOperationResponses = { + /** + * Response is a simple number + */ + 200: number; +}; + +export type GetApiVbyApiVersionSimpleOperationResponse = GetApiVbyApiVersionSimpleOperationResponses[keyof GetApiVbyApiVersionSimpleOperationResponses]; export type DeleteFooData3 = { body?: never; @@ -1136,7 +1168,18 @@ export type PostCallWithOptionalParamData = { }; }; -export type PostCallWithOptionalParamResponse = number | void; +export type PostCallWithOptionalParamResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; + +export type PostCallWithOptionalParamResponse = PostCallWithOptionalParamResponses[keyof PostCallWithOptionalParamResponses]; export type PostApiVbyApiVersionRequestBodyData = { /** @@ -1259,27 +1302,132 @@ export type CallToTestOrderOfParamsData = { }; }; -export type CallWithNoContentResponseResponse = void; +export type CallWithNoContentResponseResponses = { + /** + * Success + */ + 204: void; +}; -export type CallWithResponseAndNoContentResponseResponse = number | void; +export type CallWithNoContentResponseResponse = CallWithNoContentResponseResponses[keyof CallWithNoContentResponseResponses]; -export type DummyAResponse = _400; +export type CallWithResponseAndNoContentResponseResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; -export type DummyBResponse = void; +export type CallWithResponseAndNoContentResponseResponse = CallWithResponseAndNoContentResponseResponses[keyof CallWithResponseAndNoContentResponseResponses]; -export type CallWithResponseResponse = _import; +export type DummyAResponses = { + 200: _400; +}; -export type CallWithDuplicateResponsesError = ModelWithStringError | DictionaryWithArray | ModelWithBoolean; +export type DummyAResponse = DummyAResponses[keyof DummyAResponses]; -export type CallWithDuplicateResponsesResponse = (ModelWithBoolean & ModelWithInteger) | ModelWithString; +export type DummyBResponses = { + /** + * Success + */ + 204: void; +}; -export type CallWithResponsesError = ModelWithStringError; +export type DummyBResponse = DummyBResponses[keyof DummyBResponses]; -export type CallWithResponsesResponse = { - readonly '@namespace.string'?: string; - readonly '@namespace.integer'?: number; - readonly value?: Array; -} | ModelThatExtends | ModelThatExtendsExtends; +export type CallWithResponseResponses = { + default: _import; +}; + +export type CallWithResponseResponse = CallWithResponseResponses[keyof CallWithResponseResponses]; + +export type CallWithDuplicateResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for 4XX errors + */ + '4XX': DictionaryWithArray; + /** + * Default error response + */ + default: ModelWithBoolean; +}; + +export type CallWithDuplicateResponsesError = CallWithDuplicateResponsesErrors[keyof CallWithDuplicateResponsesErrors]; + +export type CallWithDuplicateResponsesResponses = { + /** + * Message for 200 response + */ + 200: ModelWithBoolean & ModelWithInteger; + /** + * Message for 201 response + */ + 201: ModelWithString; + /** + * Message for 202 response + */ + 202: ModelWithString; +}; + +export type CallWithDuplicateResponsesResponse = CallWithDuplicateResponsesResponses[keyof CallWithDuplicateResponsesResponses]; + +export type CallWithResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for default response + */ + default: ModelWithStringError; +}; + +export type CallWithResponsesError = CallWithResponsesErrors[keyof CallWithResponsesErrors]; + +export type CallWithResponsesResponses = { + /** + * Message for 200 response + */ + 200: { + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; + readonly value?: Array; + }; + /** + * Message for 201 response + */ + 201: ModelThatExtends; + /** + * Message for 202 response + */ + 202: ModelThatExtendsExtends; +}; + +export type CallWithResponsesResponse = CallWithResponsesResponses[keyof CallWithResponsesResponses]; export type CollectionFormatData = { body?: never; @@ -1348,7 +1496,26 @@ export type TypesData = { }; }; -export type TypesResponse = number | string | boolean | {}; +export type TypesResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Response is a simple string + */ + 201: string; + /** + * Response is a simple boolean + */ + 202: boolean; + /** + * Response is a simple object + */ + 203: {}; +}; + +export type TypesResponse = TypesResponses[keyof TypesResponses]; export type UploadFileData = { body: Blob | File; @@ -1361,7 +1528,11 @@ export type UploadFileData = { query?: never; }; -export type UploadFileResponse = boolean; +export type UploadFileResponses = { + 200: boolean; +}; + +export type UploadFileResponse = UploadFileResponses[keyof UploadFileResponses]; export type FileResponseData = { body?: never; @@ -1375,7 +1546,14 @@ export type FileResponseData = { query?: never; }; -export type FileResponseResponse = Blob | File; +export type FileResponseResponses = { + /** + * Success + */ + 200: Blob | File; +}; + +export type FileResponseResponse = FileResponseResponses[keyof FileResponseResponses]; export type ComplexTypesData = { body?: never; @@ -1398,16 +1576,41 @@ export type ComplexTypesData = { }; }; -export type ComplexTypesResponse = Array; +export type ComplexTypesErrors = { + /** + * 400 `server` error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type ComplexTypesResponses = { + /** + * Successful response + */ + 200: Array; +}; -export type MultipartResponseResponse = { - file?: Blob | File; - metadata?: { - foo?: string; - bar?: string; +export type ComplexTypesResponse = ComplexTypesResponses[keyof ComplexTypesResponses]; + +export type MultipartResponseResponses = { + /** + * OK + */ + 200: { + file?: Blob | File; + metadata?: { + foo?: string; + bar?: string; + }; }; }; +export type MultipartResponseResponse = MultipartResponseResponses[keyof MultipartResponseResponses]; + export type MultipartRequestData = { body?: { content?: Blob | File; @@ -1439,7 +1642,32 @@ export type ComplexParamsData = { query?: never; }; -export type ComplexParamsResponse = ModelWithString; +export type ComplexParamsResponses = { + /** + * Success + */ + 200: ModelWithString; +}; + +export type ComplexParamsResponse = ComplexParamsResponses[keyof ComplexParamsResponses]; + +export type CallWithResultFromHeaderErrors = { + /** + * 400 server error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type CallWithResultFromHeaderResponses = { + /** + * Successful response + */ + 200: unknown; +}; export type TestErrorCodeData = { body?: never; @@ -1452,6 +1680,32 @@ export type TestErrorCodeData = { }; }; +export type TestErrorCodeErrors = { + /** + * Custom message: Internal Server Error + */ + 500: unknown; + /** + * Custom message: Not Implemented + */ + 501: unknown; + /** + * Custom message: Bad Gateway + */ + 502: unknown; + /** + * Custom message: Service Unavailable + */ + 503: unknown; +}; + +export type TestErrorCodeResponses = { + /** + * Custom message: Successful response + */ + 200: unknown; +}; + export type NonAsciiæøåÆøÅöôêÊ字符串Data = { body?: never; path?: never; @@ -1463,7 +1717,14 @@ export type NonAsciiæøåÆøÅöôêÊ字符串Data = { }; }; -export type NonAsciiæøåÆøÅöôêÊ字符串Response = Array; +export type NonAsciiæøåÆøÅöôêÊ字符串Responses = { + /** + * Successful response + */ + 200: Array; +}; + +export type NonAsciiæøåÆøÅöôêÊ字符串Response = NonAsciiæøåÆøÅöôêÊ字符串Responses[keyof NonAsciiæøåÆøÅöôêÊ字符串Responses]; export type PutWithFormUrlEncodedData = { body: ArrayWithStrings; 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 b914fd963..37046a7eb 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 @@ -947,9 +947,27 @@ export type ImportData = { body: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; }; -export type ImportResponse = Model_From_Zendesk | ModelWithReadOnlyAndWriteOnly; +export type ImportResponses = { + /** + * Success + */ + 200: Model_From_Zendesk; + /** + * Default success response + */ + default: ModelWithReadOnlyAndWriteOnly; +}; + +export type ImportResponse = ImportResponses[keyof ImportResponses]; + +export type ApiVversionOdataControllerCountResponses = { + /** + * Success + */ + 200: Model_From_Zendesk; +}; -export type ApiVversionOdataControllerCountResponse = Model_From_Zendesk; +export type ApiVversionOdataControllerCountResponse = ApiVversionOdataControllerCountResponses[keyof ApiVversionOdataControllerCountResponses]; export type GetApiVbyApiVersionSimpleOperationData = { body?: never; @@ -962,9 +980,23 @@ export type GetApiVbyApiVersionSimpleOperationData = { query?: never; }; -export type GetApiVbyApiVersionSimpleOperationError = ModelWithBoolean; +export type GetApiVbyApiVersionSimpleOperationErrors = { + /** + * Default error response + */ + default: ModelWithBoolean; +}; -export type GetApiVbyApiVersionSimpleOperationResponse = number; +export type GetApiVbyApiVersionSimpleOperationError = GetApiVbyApiVersionSimpleOperationErrors[keyof GetApiVbyApiVersionSimpleOperationErrors]; + +export type GetApiVbyApiVersionSimpleOperationResponses = { + /** + * Response is a simple number + */ + 200: number; +}; + +export type GetApiVbyApiVersionSimpleOperationResponse = GetApiVbyApiVersionSimpleOperationResponses[keyof GetApiVbyApiVersionSimpleOperationResponses]; export type DeleteFooData3 = { body?: never; @@ -1136,7 +1168,18 @@ export type PostCallWithOptionalParamData = { }; }; -export type PostCallWithOptionalParamResponse = number | void; +export type PostCallWithOptionalParamResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; + +export type PostCallWithOptionalParamResponse = PostCallWithOptionalParamResponses[keyof PostCallWithOptionalParamResponses]; export type PostApiVbyApiVersionRequestBodyData = { /** @@ -1259,27 +1302,132 @@ export type CallToTestOrderOfParamsData = { }; }; -export type CallWithNoContentResponseResponse = void; +export type CallWithNoContentResponseResponses = { + /** + * Success + */ + 204: void; +}; -export type CallWithResponseAndNoContentResponseResponse = number | void; +export type CallWithNoContentResponseResponse = CallWithNoContentResponseResponses[keyof CallWithNoContentResponseResponses]; -export type DummyAResponse = _400; +export type CallWithResponseAndNoContentResponseResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; -export type DummyBResponse = void; +export type CallWithResponseAndNoContentResponseResponse = CallWithResponseAndNoContentResponseResponses[keyof CallWithResponseAndNoContentResponseResponses]; -export type CallWithResponseResponse = _import; +export type DummyAResponses = { + 200: _400; +}; -export type CallWithDuplicateResponsesError = ModelWithStringError | DictionaryWithArray | ModelWithBoolean; +export type DummyAResponse = DummyAResponses[keyof DummyAResponses]; -export type CallWithDuplicateResponsesResponse = (ModelWithBoolean & ModelWithInteger) | ModelWithString; +export type DummyBResponses = { + /** + * Success + */ + 204: void; +}; -export type CallWithResponsesError = ModelWithStringError; +export type DummyBResponse = DummyBResponses[keyof DummyBResponses]; -export type CallWithResponsesResponse = { - readonly '@namespace.string'?: string; - readonly '@namespace.integer'?: number; - readonly value?: Array; -} | ModelThatExtends | ModelThatExtendsExtends; +export type CallWithResponseResponses = { + default: _import; +}; + +export type CallWithResponseResponse = CallWithResponseResponses[keyof CallWithResponseResponses]; + +export type CallWithDuplicateResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for 4XX errors + */ + '4XX': DictionaryWithArray; + /** + * Default error response + */ + default: ModelWithBoolean; +}; + +export type CallWithDuplicateResponsesError = CallWithDuplicateResponsesErrors[keyof CallWithDuplicateResponsesErrors]; + +export type CallWithDuplicateResponsesResponses = { + /** + * Message for 200 response + */ + 200: ModelWithBoolean & ModelWithInteger; + /** + * Message for 201 response + */ + 201: ModelWithString; + /** + * Message for 202 response + */ + 202: ModelWithString; +}; + +export type CallWithDuplicateResponsesResponse = CallWithDuplicateResponsesResponses[keyof CallWithDuplicateResponsesResponses]; + +export type CallWithResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for default response + */ + default: ModelWithStringError; +}; + +export type CallWithResponsesError = CallWithResponsesErrors[keyof CallWithResponsesErrors]; + +export type CallWithResponsesResponses = { + /** + * Message for 200 response + */ + 200: { + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; + readonly value?: Array; + }; + /** + * Message for 201 response + */ + 201: ModelThatExtends; + /** + * Message for 202 response + */ + 202: ModelThatExtendsExtends; +}; + +export type CallWithResponsesResponse = CallWithResponsesResponses[keyof CallWithResponsesResponses]; export type CollectionFormatData = { body?: never; @@ -1348,7 +1496,26 @@ export type TypesData = { }; }; -export type TypesResponse = number | string | boolean | {}; +export type TypesResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Response is a simple string + */ + 201: string; + /** + * Response is a simple boolean + */ + 202: boolean; + /** + * Response is a simple object + */ + 203: {}; +}; + +export type TypesResponse = TypesResponses[keyof TypesResponses]; export type UploadFileData = { body: Blob | File; @@ -1361,7 +1528,11 @@ export type UploadFileData = { query?: never; }; -export type UploadFileResponse = boolean; +export type UploadFileResponses = { + 200: boolean; +}; + +export type UploadFileResponse = UploadFileResponses[keyof UploadFileResponses]; export type FileResponseData = { body?: never; @@ -1375,7 +1546,14 @@ export type FileResponseData = { query?: never; }; -export type FileResponseResponse = Blob | File; +export type FileResponseResponses = { + /** + * Success + */ + 200: Blob | File; +}; + +export type FileResponseResponse = FileResponseResponses[keyof FileResponseResponses]; export type ComplexTypesData = { body?: never; @@ -1398,16 +1576,41 @@ export type ComplexTypesData = { }; }; -export type ComplexTypesResponse = Array; +export type ComplexTypesErrors = { + /** + * 400 `server` error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type ComplexTypesResponses = { + /** + * Successful response + */ + 200: Array; +}; -export type MultipartResponseResponse = { - file?: Blob | File; - metadata?: { - foo?: string; - bar?: string; +export type ComplexTypesResponse = ComplexTypesResponses[keyof ComplexTypesResponses]; + +export type MultipartResponseResponses = { + /** + * OK + */ + 200: { + file?: Blob | File; + metadata?: { + foo?: string; + bar?: string; + }; }; }; +export type MultipartResponseResponse = MultipartResponseResponses[keyof MultipartResponseResponses]; + export type MultipartRequestData = { body?: { content?: Blob | File; @@ -1439,7 +1642,32 @@ export type ComplexParamsData = { query?: never; }; -export type ComplexParamsResponse = ModelWithString; +export type ComplexParamsResponses = { + /** + * Success + */ + 200: ModelWithString; +}; + +export type ComplexParamsResponse = ComplexParamsResponses[keyof ComplexParamsResponses]; + +export type CallWithResultFromHeaderErrors = { + /** + * 400 server error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type CallWithResultFromHeaderResponses = { + /** + * Successful response + */ + 200: unknown; +}; export type TestErrorCodeData = { body?: never; @@ -1452,6 +1680,32 @@ export type TestErrorCodeData = { }; }; +export type TestErrorCodeErrors = { + /** + * Custom message: Internal Server Error + */ + 500: unknown; + /** + * Custom message: Not Implemented + */ + 501: unknown; + /** + * Custom message: Bad Gateway + */ + 502: unknown; + /** + * Custom message: Service Unavailable + */ + 503: unknown; +}; + +export type TestErrorCodeResponses = { + /** + * Custom message: Successful response + */ + 200: unknown; +}; + export type NonAsciiæøåÆøÅöôêÊ字符串Data = { body?: never; path?: never; @@ -1463,7 +1717,14 @@ export type NonAsciiæøåÆøÅöôêÊ字符串Data = { }; }; -export type NonAsciiæøåÆøÅöôêÊ字符串Response = Array; +export type NonAsciiæøåÆøÅöôêÊ字符串Responses = { + /** + * Successful response + */ + 200: Array; +}; + +export type NonAsciiæøåÆøÅöôêÊ字符串Response = NonAsciiæøåÆøÅöôêÊ字符串Responses[keyof NonAsciiæøåÆøÅöôêÊ字符串Responses]; export type PutWithFormUrlEncodedData = { body: ArrayWithStrings; 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 b914fd963..37046a7eb 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 @@ -947,9 +947,27 @@ export type ImportData = { body: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; }; -export type ImportResponse = Model_From_Zendesk | ModelWithReadOnlyAndWriteOnly; +export type ImportResponses = { + /** + * Success + */ + 200: Model_From_Zendesk; + /** + * Default success response + */ + default: ModelWithReadOnlyAndWriteOnly; +}; + +export type ImportResponse = ImportResponses[keyof ImportResponses]; + +export type ApiVversionOdataControllerCountResponses = { + /** + * Success + */ + 200: Model_From_Zendesk; +}; -export type ApiVversionOdataControllerCountResponse = Model_From_Zendesk; +export type ApiVversionOdataControllerCountResponse = ApiVversionOdataControllerCountResponses[keyof ApiVversionOdataControllerCountResponses]; export type GetApiVbyApiVersionSimpleOperationData = { body?: never; @@ -962,9 +980,23 @@ export type GetApiVbyApiVersionSimpleOperationData = { query?: never; }; -export type GetApiVbyApiVersionSimpleOperationError = ModelWithBoolean; +export type GetApiVbyApiVersionSimpleOperationErrors = { + /** + * Default error response + */ + default: ModelWithBoolean; +}; -export type GetApiVbyApiVersionSimpleOperationResponse = number; +export type GetApiVbyApiVersionSimpleOperationError = GetApiVbyApiVersionSimpleOperationErrors[keyof GetApiVbyApiVersionSimpleOperationErrors]; + +export type GetApiVbyApiVersionSimpleOperationResponses = { + /** + * Response is a simple number + */ + 200: number; +}; + +export type GetApiVbyApiVersionSimpleOperationResponse = GetApiVbyApiVersionSimpleOperationResponses[keyof GetApiVbyApiVersionSimpleOperationResponses]; export type DeleteFooData3 = { body?: never; @@ -1136,7 +1168,18 @@ export type PostCallWithOptionalParamData = { }; }; -export type PostCallWithOptionalParamResponse = number | void; +export type PostCallWithOptionalParamResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; + +export type PostCallWithOptionalParamResponse = PostCallWithOptionalParamResponses[keyof PostCallWithOptionalParamResponses]; export type PostApiVbyApiVersionRequestBodyData = { /** @@ -1259,27 +1302,132 @@ export type CallToTestOrderOfParamsData = { }; }; -export type CallWithNoContentResponseResponse = void; +export type CallWithNoContentResponseResponses = { + /** + * Success + */ + 204: void; +}; -export type CallWithResponseAndNoContentResponseResponse = number | void; +export type CallWithNoContentResponseResponse = CallWithNoContentResponseResponses[keyof CallWithNoContentResponseResponses]; -export type DummyAResponse = _400; +export type CallWithResponseAndNoContentResponseResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; -export type DummyBResponse = void; +export type CallWithResponseAndNoContentResponseResponse = CallWithResponseAndNoContentResponseResponses[keyof CallWithResponseAndNoContentResponseResponses]; -export type CallWithResponseResponse = _import; +export type DummyAResponses = { + 200: _400; +}; -export type CallWithDuplicateResponsesError = ModelWithStringError | DictionaryWithArray | ModelWithBoolean; +export type DummyAResponse = DummyAResponses[keyof DummyAResponses]; -export type CallWithDuplicateResponsesResponse = (ModelWithBoolean & ModelWithInteger) | ModelWithString; +export type DummyBResponses = { + /** + * Success + */ + 204: void; +}; -export type CallWithResponsesError = ModelWithStringError; +export type DummyBResponse = DummyBResponses[keyof DummyBResponses]; -export type CallWithResponsesResponse = { - readonly '@namespace.string'?: string; - readonly '@namespace.integer'?: number; - readonly value?: Array; -} | ModelThatExtends | ModelThatExtendsExtends; +export type CallWithResponseResponses = { + default: _import; +}; + +export type CallWithResponseResponse = CallWithResponseResponses[keyof CallWithResponseResponses]; + +export type CallWithDuplicateResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for 4XX errors + */ + '4XX': DictionaryWithArray; + /** + * Default error response + */ + default: ModelWithBoolean; +}; + +export type CallWithDuplicateResponsesError = CallWithDuplicateResponsesErrors[keyof CallWithDuplicateResponsesErrors]; + +export type CallWithDuplicateResponsesResponses = { + /** + * Message for 200 response + */ + 200: ModelWithBoolean & ModelWithInteger; + /** + * Message for 201 response + */ + 201: ModelWithString; + /** + * Message for 202 response + */ + 202: ModelWithString; +}; + +export type CallWithDuplicateResponsesResponse = CallWithDuplicateResponsesResponses[keyof CallWithDuplicateResponsesResponses]; + +export type CallWithResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for default response + */ + default: ModelWithStringError; +}; + +export type CallWithResponsesError = CallWithResponsesErrors[keyof CallWithResponsesErrors]; + +export type CallWithResponsesResponses = { + /** + * Message for 200 response + */ + 200: { + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; + readonly value?: Array; + }; + /** + * Message for 201 response + */ + 201: ModelThatExtends; + /** + * Message for 202 response + */ + 202: ModelThatExtendsExtends; +}; + +export type CallWithResponsesResponse = CallWithResponsesResponses[keyof CallWithResponsesResponses]; export type CollectionFormatData = { body?: never; @@ -1348,7 +1496,26 @@ export type TypesData = { }; }; -export type TypesResponse = number | string | boolean | {}; +export type TypesResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Response is a simple string + */ + 201: string; + /** + * Response is a simple boolean + */ + 202: boolean; + /** + * Response is a simple object + */ + 203: {}; +}; + +export type TypesResponse = TypesResponses[keyof TypesResponses]; export type UploadFileData = { body: Blob | File; @@ -1361,7 +1528,11 @@ export type UploadFileData = { query?: never; }; -export type UploadFileResponse = boolean; +export type UploadFileResponses = { + 200: boolean; +}; + +export type UploadFileResponse = UploadFileResponses[keyof UploadFileResponses]; export type FileResponseData = { body?: never; @@ -1375,7 +1546,14 @@ export type FileResponseData = { query?: never; }; -export type FileResponseResponse = Blob | File; +export type FileResponseResponses = { + /** + * Success + */ + 200: Blob | File; +}; + +export type FileResponseResponse = FileResponseResponses[keyof FileResponseResponses]; export type ComplexTypesData = { body?: never; @@ -1398,16 +1576,41 @@ export type ComplexTypesData = { }; }; -export type ComplexTypesResponse = Array; +export type ComplexTypesErrors = { + /** + * 400 `server` error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type ComplexTypesResponses = { + /** + * Successful response + */ + 200: Array; +}; -export type MultipartResponseResponse = { - file?: Blob | File; - metadata?: { - foo?: string; - bar?: string; +export type ComplexTypesResponse = ComplexTypesResponses[keyof ComplexTypesResponses]; + +export type MultipartResponseResponses = { + /** + * OK + */ + 200: { + file?: Blob | File; + metadata?: { + foo?: string; + bar?: string; + }; }; }; +export type MultipartResponseResponse = MultipartResponseResponses[keyof MultipartResponseResponses]; + export type MultipartRequestData = { body?: { content?: Blob | File; @@ -1439,7 +1642,32 @@ export type ComplexParamsData = { query?: never; }; -export type ComplexParamsResponse = ModelWithString; +export type ComplexParamsResponses = { + /** + * Success + */ + 200: ModelWithString; +}; + +export type ComplexParamsResponse = ComplexParamsResponses[keyof ComplexParamsResponses]; + +export type CallWithResultFromHeaderErrors = { + /** + * 400 server error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type CallWithResultFromHeaderResponses = { + /** + * Successful response + */ + 200: unknown; +}; export type TestErrorCodeData = { body?: never; @@ -1452,6 +1680,32 @@ export type TestErrorCodeData = { }; }; +export type TestErrorCodeErrors = { + /** + * Custom message: Internal Server Error + */ + 500: unknown; + /** + * Custom message: Not Implemented + */ + 501: unknown; + /** + * Custom message: Bad Gateway + */ + 502: unknown; + /** + * Custom message: Service Unavailable + */ + 503: unknown; +}; + +export type TestErrorCodeResponses = { + /** + * Custom message: Successful response + */ + 200: unknown; +}; + export type NonAsciiæøåÆøÅöôêÊ字符串Data = { body?: never; path?: never; @@ -1463,7 +1717,14 @@ export type NonAsciiæøåÆøÅöôêÊ字符串Data = { }; }; -export type NonAsciiæøåÆøÅöôêÊ字符串Response = Array; +export type NonAsciiæøåÆøÅöôêÊ字符串Responses = { + /** + * Successful response + */ + 200: Array; +}; + +export type NonAsciiæøåÆøÅöôêÊ字符串Response = NonAsciiæøåÆøÅöôêÊ字符串Responses[keyof NonAsciiæøåÆøÅöôêÊ字符串Responses]; export type PutWithFormUrlEncodedData = { body: ArrayWithStrings; 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 b914fd963..37046a7eb 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 @@ -947,9 +947,27 @@ export type ImportData = { body: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; }; -export type ImportResponse = Model_From_Zendesk | ModelWithReadOnlyAndWriteOnly; +export type ImportResponses = { + /** + * Success + */ + 200: Model_From_Zendesk; + /** + * Default success response + */ + default: ModelWithReadOnlyAndWriteOnly; +}; + +export type ImportResponse = ImportResponses[keyof ImportResponses]; + +export type ApiVversionOdataControllerCountResponses = { + /** + * Success + */ + 200: Model_From_Zendesk; +}; -export type ApiVversionOdataControllerCountResponse = Model_From_Zendesk; +export type ApiVversionOdataControllerCountResponse = ApiVversionOdataControllerCountResponses[keyof ApiVversionOdataControllerCountResponses]; export type GetApiVbyApiVersionSimpleOperationData = { body?: never; @@ -962,9 +980,23 @@ export type GetApiVbyApiVersionSimpleOperationData = { query?: never; }; -export type GetApiVbyApiVersionSimpleOperationError = ModelWithBoolean; +export type GetApiVbyApiVersionSimpleOperationErrors = { + /** + * Default error response + */ + default: ModelWithBoolean; +}; -export type GetApiVbyApiVersionSimpleOperationResponse = number; +export type GetApiVbyApiVersionSimpleOperationError = GetApiVbyApiVersionSimpleOperationErrors[keyof GetApiVbyApiVersionSimpleOperationErrors]; + +export type GetApiVbyApiVersionSimpleOperationResponses = { + /** + * Response is a simple number + */ + 200: number; +}; + +export type GetApiVbyApiVersionSimpleOperationResponse = GetApiVbyApiVersionSimpleOperationResponses[keyof GetApiVbyApiVersionSimpleOperationResponses]; export type DeleteFooData3 = { body?: never; @@ -1136,7 +1168,18 @@ export type PostCallWithOptionalParamData = { }; }; -export type PostCallWithOptionalParamResponse = number | void; +export type PostCallWithOptionalParamResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; + +export type PostCallWithOptionalParamResponse = PostCallWithOptionalParamResponses[keyof PostCallWithOptionalParamResponses]; export type PostApiVbyApiVersionRequestBodyData = { /** @@ -1259,27 +1302,132 @@ export type CallToTestOrderOfParamsData = { }; }; -export type CallWithNoContentResponseResponse = void; +export type CallWithNoContentResponseResponses = { + /** + * Success + */ + 204: void; +}; -export type CallWithResponseAndNoContentResponseResponse = number | void; +export type CallWithNoContentResponseResponse = CallWithNoContentResponseResponses[keyof CallWithNoContentResponseResponses]; -export type DummyAResponse = _400; +export type CallWithResponseAndNoContentResponseResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; -export type DummyBResponse = void; +export type CallWithResponseAndNoContentResponseResponse = CallWithResponseAndNoContentResponseResponses[keyof CallWithResponseAndNoContentResponseResponses]; -export type CallWithResponseResponse = _import; +export type DummyAResponses = { + 200: _400; +}; -export type CallWithDuplicateResponsesError = ModelWithStringError | DictionaryWithArray | ModelWithBoolean; +export type DummyAResponse = DummyAResponses[keyof DummyAResponses]; -export type CallWithDuplicateResponsesResponse = (ModelWithBoolean & ModelWithInteger) | ModelWithString; +export type DummyBResponses = { + /** + * Success + */ + 204: void; +}; -export type CallWithResponsesError = ModelWithStringError; +export type DummyBResponse = DummyBResponses[keyof DummyBResponses]; -export type CallWithResponsesResponse = { - readonly '@namespace.string'?: string; - readonly '@namespace.integer'?: number; - readonly value?: Array; -} | ModelThatExtends | ModelThatExtendsExtends; +export type CallWithResponseResponses = { + default: _import; +}; + +export type CallWithResponseResponse = CallWithResponseResponses[keyof CallWithResponseResponses]; + +export type CallWithDuplicateResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for 4XX errors + */ + '4XX': DictionaryWithArray; + /** + * Default error response + */ + default: ModelWithBoolean; +}; + +export type CallWithDuplicateResponsesError = CallWithDuplicateResponsesErrors[keyof CallWithDuplicateResponsesErrors]; + +export type CallWithDuplicateResponsesResponses = { + /** + * Message for 200 response + */ + 200: ModelWithBoolean & ModelWithInteger; + /** + * Message for 201 response + */ + 201: ModelWithString; + /** + * Message for 202 response + */ + 202: ModelWithString; +}; + +export type CallWithDuplicateResponsesResponse = CallWithDuplicateResponsesResponses[keyof CallWithDuplicateResponsesResponses]; + +export type CallWithResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for default response + */ + default: ModelWithStringError; +}; + +export type CallWithResponsesError = CallWithResponsesErrors[keyof CallWithResponsesErrors]; + +export type CallWithResponsesResponses = { + /** + * Message for 200 response + */ + 200: { + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; + readonly value?: Array; + }; + /** + * Message for 201 response + */ + 201: ModelThatExtends; + /** + * Message for 202 response + */ + 202: ModelThatExtendsExtends; +}; + +export type CallWithResponsesResponse = CallWithResponsesResponses[keyof CallWithResponsesResponses]; export type CollectionFormatData = { body?: never; @@ -1348,7 +1496,26 @@ export type TypesData = { }; }; -export type TypesResponse = number | string | boolean | {}; +export type TypesResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Response is a simple string + */ + 201: string; + /** + * Response is a simple boolean + */ + 202: boolean; + /** + * Response is a simple object + */ + 203: {}; +}; + +export type TypesResponse = TypesResponses[keyof TypesResponses]; export type UploadFileData = { body: Blob | File; @@ -1361,7 +1528,11 @@ export type UploadFileData = { query?: never; }; -export type UploadFileResponse = boolean; +export type UploadFileResponses = { + 200: boolean; +}; + +export type UploadFileResponse = UploadFileResponses[keyof UploadFileResponses]; export type FileResponseData = { body?: never; @@ -1375,7 +1546,14 @@ export type FileResponseData = { query?: never; }; -export type FileResponseResponse = Blob | File; +export type FileResponseResponses = { + /** + * Success + */ + 200: Blob | File; +}; + +export type FileResponseResponse = FileResponseResponses[keyof FileResponseResponses]; export type ComplexTypesData = { body?: never; @@ -1398,16 +1576,41 @@ export type ComplexTypesData = { }; }; -export type ComplexTypesResponse = Array; +export type ComplexTypesErrors = { + /** + * 400 `server` error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type ComplexTypesResponses = { + /** + * Successful response + */ + 200: Array; +}; -export type MultipartResponseResponse = { - file?: Blob | File; - metadata?: { - foo?: string; - bar?: string; +export type ComplexTypesResponse = ComplexTypesResponses[keyof ComplexTypesResponses]; + +export type MultipartResponseResponses = { + /** + * OK + */ + 200: { + file?: Blob | File; + metadata?: { + foo?: string; + bar?: string; + }; }; }; +export type MultipartResponseResponse = MultipartResponseResponses[keyof MultipartResponseResponses]; + export type MultipartRequestData = { body?: { content?: Blob | File; @@ -1439,7 +1642,32 @@ export type ComplexParamsData = { query?: never; }; -export type ComplexParamsResponse = ModelWithString; +export type ComplexParamsResponses = { + /** + * Success + */ + 200: ModelWithString; +}; + +export type ComplexParamsResponse = ComplexParamsResponses[keyof ComplexParamsResponses]; + +export type CallWithResultFromHeaderErrors = { + /** + * 400 server error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type CallWithResultFromHeaderResponses = { + /** + * Successful response + */ + 200: unknown; +}; export type TestErrorCodeData = { body?: never; @@ -1452,6 +1680,32 @@ export type TestErrorCodeData = { }; }; +export type TestErrorCodeErrors = { + /** + * Custom message: Internal Server Error + */ + 500: unknown; + /** + * Custom message: Not Implemented + */ + 501: unknown; + /** + * Custom message: Bad Gateway + */ + 502: unknown; + /** + * Custom message: Service Unavailable + */ + 503: unknown; +}; + +export type TestErrorCodeResponses = { + /** + * Custom message: Successful response + */ + 200: unknown; +}; + export type NonAsciiæøåÆøÅöôêÊ字符串Data = { body?: never; path?: never; @@ -1463,7 +1717,14 @@ export type NonAsciiæøåÆøÅöôêÊ字符串Data = { }; }; -export type NonAsciiæøåÆøÅöôêÊ字符串Response = Array; +export type NonAsciiæøåÆøÅöôêÊ字符串Responses = { + /** + * Successful response + */ + 200: Array; +}; + +export type NonAsciiæøåÆøÅöôêÊ字符串Response = NonAsciiæøåÆøÅöôêÊ字符串Responses[keyof NonAsciiæøåÆøÅöôêÊ字符串Responses]; export type PutWithFormUrlEncodedData = { body: ArrayWithStrings; 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 b914fd963..37046a7eb 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 @@ -947,9 +947,27 @@ export type ImportData = { body: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; }; -export type ImportResponse = Model_From_Zendesk | ModelWithReadOnlyAndWriteOnly; +export type ImportResponses = { + /** + * Success + */ + 200: Model_From_Zendesk; + /** + * Default success response + */ + default: ModelWithReadOnlyAndWriteOnly; +}; + +export type ImportResponse = ImportResponses[keyof ImportResponses]; + +export type ApiVversionOdataControllerCountResponses = { + /** + * Success + */ + 200: Model_From_Zendesk; +}; -export type ApiVversionOdataControllerCountResponse = Model_From_Zendesk; +export type ApiVversionOdataControllerCountResponse = ApiVversionOdataControllerCountResponses[keyof ApiVversionOdataControllerCountResponses]; export type GetApiVbyApiVersionSimpleOperationData = { body?: never; @@ -962,9 +980,23 @@ export type GetApiVbyApiVersionSimpleOperationData = { query?: never; }; -export type GetApiVbyApiVersionSimpleOperationError = ModelWithBoolean; +export type GetApiVbyApiVersionSimpleOperationErrors = { + /** + * Default error response + */ + default: ModelWithBoolean; +}; -export type GetApiVbyApiVersionSimpleOperationResponse = number; +export type GetApiVbyApiVersionSimpleOperationError = GetApiVbyApiVersionSimpleOperationErrors[keyof GetApiVbyApiVersionSimpleOperationErrors]; + +export type GetApiVbyApiVersionSimpleOperationResponses = { + /** + * Response is a simple number + */ + 200: number; +}; + +export type GetApiVbyApiVersionSimpleOperationResponse = GetApiVbyApiVersionSimpleOperationResponses[keyof GetApiVbyApiVersionSimpleOperationResponses]; export type DeleteFooData3 = { body?: never; @@ -1136,7 +1168,18 @@ export type PostCallWithOptionalParamData = { }; }; -export type PostCallWithOptionalParamResponse = number | void; +export type PostCallWithOptionalParamResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; + +export type PostCallWithOptionalParamResponse = PostCallWithOptionalParamResponses[keyof PostCallWithOptionalParamResponses]; export type PostApiVbyApiVersionRequestBodyData = { /** @@ -1259,27 +1302,132 @@ export type CallToTestOrderOfParamsData = { }; }; -export type CallWithNoContentResponseResponse = void; +export type CallWithNoContentResponseResponses = { + /** + * Success + */ + 204: void; +}; -export type CallWithResponseAndNoContentResponseResponse = number | void; +export type CallWithNoContentResponseResponse = CallWithNoContentResponseResponses[keyof CallWithNoContentResponseResponses]; -export type DummyAResponse = _400; +export type CallWithResponseAndNoContentResponseResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; -export type DummyBResponse = void; +export type CallWithResponseAndNoContentResponseResponse = CallWithResponseAndNoContentResponseResponses[keyof CallWithResponseAndNoContentResponseResponses]; -export type CallWithResponseResponse = _import; +export type DummyAResponses = { + 200: _400; +}; -export type CallWithDuplicateResponsesError = ModelWithStringError | DictionaryWithArray | ModelWithBoolean; +export type DummyAResponse = DummyAResponses[keyof DummyAResponses]; -export type CallWithDuplicateResponsesResponse = (ModelWithBoolean & ModelWithInteger) | ModelWithString; +export type DummyBResponses = { + /** + * Success + */ + 204: void; +}; -export type CallWithResponsesError = ModelWithStringError; +export type DummyBResponse = DummyBResponses[keyof DummyBResponses]; -export type CallWithResponsesResponse = { - readonly '@namespace.string'?: string; - readonly '@namespace.integer'?: number; - readonly value?: Array; -} | ModelThatExtends | ModelThatExtendsExtends; +export type CallWithResponseResponses = { + default: _import; +}; + +export type CallWithResponseResponse = CallWithResponseResponses[keyof CallWithResponseResponses]; + +export type CallWithDuplicateResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for 4XX errors + */ + '4XX': DictionaryWithArray; + /** + * Default error response + */ + default: ModelWithBoolean; +}; + +export type CallWithDuplicateResponsesError = CallWithDuplicateResponsesErrors[keyof CallWithDuplicateResponsesErrors]; + +export type CallWithDuplicateResponsesResponses = { + /** + * Message for 200 response + */ + 200: ModelWithBoolean & ModelWithInteger; + /** + * Message for 201 response + */ + 201: ModelWithString; + /** + * Message for 202 response + */ + 202: ModelWithString; +}; + +export type CallWithDuplicateResponsesResponse = CallWithDuplicateResponsesResponses[keyof CallWithDuplicateResponsesResponses]; + +export type CallWithResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for default response + */ + default: ModelWithStringError; +}; + +export type CallWithResponsesError = CallWithResponsesErrors[keyof CallWithResponsesErrors]; + +export type CallWithResponsesResponses = { + /** + * Message for 200 response + */ + 200: { + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; + readonly value?: Array; + }; + /** + * Message for 201 response + */ + 201: ModelThatExtends; + /** + * Message for 202 response + */ + 202: ModelThatExtendsExtends; +}; + +export type CallWithResponsesResponse = CallWithResponsesResponses[keyof CallWithResponsesResponses]; export type CollectionFormatData = { body?: never; @@ -1348,7 +1496,26 @@ export type TypesData = { }; }; -export type TypesResponse = number | string | boolean | {}; +export type TypesResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Response is a simple string + */ + 201: string; + /** + * Response is a simple boolean + */ + 202: boolean; + /** + * Response is a simple object + */ + 203: {}; +}; + +export type TypesResponse = TypesResponses[keyof TypesResponses]; export type UploadFileData = { body: Blob | File; @@ -1361,7 +1528,11 @@ export type UploadFileData = { query?: never; }; -export type UploadFileResponse = boolean; +export type UploadFileResponses = { + 200: boolean; +}; + +export type UploadFileResponse = UploadFileResponses[keyof UploadFileResponses]; export type FileResponseData = { body?: never; @@ -1375,7 +1546,14 @@ export type FileResponseData = { query?: never; }; -export type FileResponseResponse = Blob | File; +export type FileResponseResponses = { + /** + * Success + */ + 200: Blob | File; +}; + +export type FileResponseResponse = FileResponseResponses[keyof FileResponseResponses]; export type ComplexTypesData = { body?: never; @@ -1398,16 +1576,41 @@ export type ComplexTypesData = { }; }; -export type ComplexTypesResponse = Array; +export type ComplexTypesErrors = { + /** + * 400 `server` error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type ComplexTypesResponses = { + /** + * Successful response + */ + 200: Array; +}; -export type MultipartResponseResponse = { - file?: Blob | File; - metadata?: { - foo?: string; - bar?: string; +export type ComplexTypesResponse = ComplexTypesResponses[keyof ComplexTypesResponses]; + +export type MultipartResponseResponses = { + /** + * OK + */ + 200: { + file?: Blob | File; + metadata?: { + foo?: string; + bar?: string; + }; }; }; +export type MultipartResponseResponse = MultipartResponseResponses[keyof MultipartResponseResponses]; + export type MultipartRequestData = { body?: { content?: Blob | File; @@ -1439,7 +1642,32 @@ export type ComplexParamsData = { query?: never; }; -export type ComplexParamsResponse = ModelWithString; +export type ComplexParamsResponses = { + /** + * Success + */ + 200: ModelWithString; +}; + +export type ComplexParamsResponse = ComplexParamsResponses[keyof ComplexParamsResponses]; + +export type CallWithResultFromHeaderErrors = { + /** + * 400 server error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type CallWithResultFromHeaderResponses = { + /** + * Successful response + */ + 200: unknown; +}; export type TestErrorCodeData = { body?: never; @@ -1452,6 +1680,32 @@ export type TestErrorCodeData = { }; }; +export type TestErrorCodeErrors = { + /** + * Custom message: Internal Server Error + */ + 500: unknown; + /** + * Custom message: Not Implemented + */ + 501: unknown; + /** + * Custom message: Bad Gateway + */ + 502: unknown; + /** + * Custom message: Service Unavailable + */ + 503: unknown; +}; + +export type TestErrorCodeResponses = { + /** + * Custom message: Successful response + */ + 200: unknown; +}; + export type NonAsciiæøåÆøÅöôêÊ字符串Data = { body?: never; path?: never; @@ -1463,7 +1717,14 @@ export type NonAsciiæøåÆøÅöôêÊ字符串Data = { }; }; -export type NonAsciiæøåÆøÅöôêÊ字符串Response = Array; +export type NonAsciiæøåÆøÅöôêÊ字符串Responses = { + /** + * Successful response + */ + 200: Array; +}; + +export type NonAsciiæøåÆøÅöôêÊ字符串Response = NonAsciiæøåÆøÅöôêÊ字符串Responses[keyof NonAsciiæøåÆøÅöôêÊ字符串Responses]; export type PutWithFormUrlEncodedData = { body: ArrayWithStrings; 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 b914fd963..37046a7eb 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 @@ -947,9 +947,27 @@ export type ImportData = { body: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; }; -export type ImportResponse = Model_From_Zendesk | ModelWithReadOnlyAndWriteOnly; +export type ImportResponses = { + /** + * Success + */ + 200: Model_From_Zendesk; + /** + * Default success response + */ + default: ModelWithReadOnlyAndWriteOnly; +}; + +export type ImportResponse = ImportResponses[keyof ImportResponses]; + +export type ApiVversionOdataControllerCountResponses = { + /** + * Success + */ + 200: Model_From_Zendesk; +}; -export type ApiVversionOdataControllerCountResponse = Model_From_Zendesk; +export type ApiVversionOdataControllerCountResponse = ApiVversionOdataControllerCountResponses[keyof ApiVversionOdataControllerCountResponses]; export type GetApiVbyApiVersionSimpleOperationData = { body?: never; @@ -962,9 +980,23 @@ export type GetApiVbyApiVersionSimpleOperationData = { query?: never; }; -export type GetApiVbyApiVersionSimpleOperationError = ModelWithBoolean; +export type GetApiVbyApiVersionSimpleOperationErrors = { + /** + * Default error response + */ + default: ModelWithBoolean; +}; -export type GetApiVbyApiVersionSimpleOperationResponse = number; +export type GetApiVbyApiVersionSimpleOperationError = GetApiVbyApiVersionSimpleOperationErrors[keyof GetApiVbyApiVersionSimpleOperationErrors]; + +export type GetApiVbyApiVersionSimpleOperationResponses = { + /** + * Response is a simple number + */ + 200: number; +}; + +export type GetApiVbyApiVersionSimpleOperationResponse = GetApiVbyApiVersionSimpleOperationResponses[keyof GetApiVbyApiVersionSimpleOperationResponses]; export type DeleteFooData3 = { body?: never; @@ -1136,7 +1168,18 @@ export type PostCallWithOptionalParamData = { }; }; -export type PostCallWithOptionalParamResponse = number | void; +export type PostCallWithOptionalParamResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; + +export type PostCallWithOptionalParamResponse = PostCallWithOptionalParamResponses[keyof PostCallWithOptionalParamResponses]; export type PostApiVbyApiVersionRequestBodyData = { /** @@ -1259,27 +1302,132 @@ export type CallToTestOrderOfParamsData = { }; }; -export type CallWithNoContentResponseResponse = void; +export type CallWithNoContentResponseResponses = { + /** + * Success + */ + 204: void; +}; -export type CallWithResponseAndNoContentResponseResponse = number | void; +export type CallWithNoContentResponseResponse = CallWithNoContentResponseResponses[keyof CallWithNoContentResponseResponses]; -export type DummyAResponse = _400; +export type CallWithResponseAndNoContentResponseResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; -export type DummyBResponse = void; +export type CallWithResponseAndNoContentResponseResponse = CallWithResponseAndNoContentResponseResponses[keyof CallWithResponseAndNoContentResponseResponses]; -export type CallWithResponseResponse = _import; +export type DummyAResponses = { + 200: _400; +}; -export type CallWithDuplicateResponsesError = ModelWithStringError | DictionaryWithArray | ModelWithBoolean; +export type DummyAResponse = DummyAResponses[keyof DummyAResponses]; -export type CallWithDuplicateResponsesResponse = (ModelWithBoolean & ModelWithInteger) | ModelWithString; +export type DummyBResponses = { + /** + * Success + */ + 204: void; +}; -export type CallWithResponsesError = ModelWithStringError; +export type DummyBResponse = DummyBResponses[keyof DummyBResponses]; -export type CallWithResponsesResponse = { - readonly '@namespace.string'?: string; - readonly '@namespace.integer'?: number; - readonly value?: Array; -} | ModelThatExtends | ModelThatExtendsExtends; +export type CallWithResponseResponses = { + default: _import; +}; + +export type CallWithResponseResponse = CallWithResponseResponses[keyof CallWithResponseResponses]; + +export type CallWithDuplicateResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for 4XX errors + */ + '4XX': DictionaryWithArray; + /** + * Default error response + */ + default: ModelWithBoolean; +}; + +export type CallWithDuplicateResponsesError = CallWithDuplicateResponsesErrors[keyof CallWithDuplicateResponsesErrors]; + +export type CallWithDuplicateResponsesResponses = { + /** + * Message for 200 response + */ + 200: ModelWithBoolean & ModelWithInteger; + /** + * Message for 201 response + */ + 201: ModelWithString; + /** + * Message for 202 response + */ + 202: ModelWithString; +}; + +export type CallWithDuplicateResponsesResponse = CallWithDuplicateResponsesResponses[keyof CallWithDuplicateResponsesResponses]; + +export type CallWithResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for default response + */ + default: ModelWithStringError; +}; + +export type CallWithResponsesError = CallWithResponsesErrors[keyof CallWithResponsesErrors]; + +export type CallWithResponsesResponses = { + /** + * Message for 200 response + */ + 200: { + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; + readonly value?: Array; + }; + /** + * Message for 201 response + */ + 201: ModelThatExtends; + /** + * Message for 202 response + */ + 202: ModelThatExtendsExtends; +}; + +export type CallWithResponsesResponse = CallWithResponsesResponses[keyof CallWithResponsesResponses]; export type CollectionFormatData = { body?: never; @@ -1348,7 +1496,26 @@ export type TypesData = { }; }; -export type TypesResponse = number | string | boolean | {}; +export type TypesResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Response is a simple string + */ + 201: string; + /** + * Response is a simple boolean + */ + 202: boolean; + /** + * Response is a simple object + */ + 203: {}; +}; + +export type TypesResponse = TypesResponses[keyof TypesResponses]; export type UploadFileData = { body: Blob | File; @@ -1361,7 +1528,11 @@ export type UploadFileData = { query?: never; }; -export type UploadFileResponse = boolean; +export type UploadFileResponses = { + 200: boolean; +}; + +export type UploadFileResponse = UploadFileResponses[keyof UploadFileResponses]; export type FileResponseData = { body?: never; @@ -1375,7 +1546,14 @@ export type FileResponseData = { query?: never; }; -export type FileResponseResponse = Blob | File; +export type FileResponseResponses = { + /** + * Success + */ + 200: Blob | File; +}; + +export type FileResponseResponse = FileResponseResponses[keyof FileResponseResponses]; export type ComplexTypesData = { body?: never; @@ -1398,16 +1576,41 @@ export type ComplexTypesData = { }; }; -export type ComplexTypesResponse = Array; +export type ComplexTypesErrors = { + /** + * 400 `server` error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type ComplexTypesResponses = { + /** + * Successful response + */ + 200: Array; +}; -export type MultipartResponseResponse = { - file?: Blob | File; - metadata?: { - foo?: string; - bar?: string; +export type ComplexTypesResponse = ComplexTypesResponses[keyof ComplexTypesResponses]; + +export type MultipartResponseResponses = { + /** + * OK + */ + 200: { + file?: Blob | File; + metadata?: { + foo?: string; + bar?: string; + }; }; }; +export type MultipartResponseResponse = MultipartResponseResponses[keyof MultipartResponseResponses]; + export type MultipartRequestData = { body?: { content?: Blob | File; @@ -1439,7 +1642,32 @@ export type ComplexParamsData = { query?: never; }; -export type ComplexParamsResponse = ModelWithString; +export type ComplexParamsResponses = { + /** + * Success + */ + 200: ModelWithString; +}; + +export type ComplexParamsResponse = ComplexParamsResponses[keyof ComplexParamsResponses]; + +export type CallWithResultFromHeaderErrors = { + /** + * 400 server error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type CallWithResultFromHeaderResponses = { + /** + * Successful response + */ + 200: unknown; +}; export type TestErrorCodeData = { body?: never; @@ -1452,6 +1680,32 @@ export type TestErrorCodeData = { }; }; +export type TestErrorCodeErrors = { + /** + * Custom message: Internal Server Error + */ + 500: unknown; + /** + * Custom message: Not Implemented + */ + 501: unknown; + /** + * Custom message: Bad Gateway + */ + 502: unknown; + /** + * Custom message: Service Unavailable + */ + 503: unknown; +}; + +export type TestErrorCodeResponses = { + /** + * Custom message: Successful response + */ + 200: unknown; +}; + export type NonAsciiæøåÆøÅöôêÊ字符串Data = { body?: never; path?: never; @@ -1463,7 +1717,14 @@ export type NonAsciiæøåÆøÅöôêÊ字符串Data = { }; }; -export type NonAsciiæøåÆøÅöôêÊ字符串Response = Array; +export type NonAsciiæøåÆøÅöôêÊ字符串Responses = { + /** + * Successful response + */ + 200: Array; +}; + +export type NonAsciiæøåÆøÅöôêÊ字符串Response = NonAsciiæøåÆøÅöôêÊ字符串Responses[keyof NonAsciiæøåÆøÅöôêÊ字符串Responses]; export type PutWithFormUrlEncodedData = { body: ArrayWithStrings; 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 b914fd963..37046a7eb 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 @@ -947,9 +947,27 @@ export type ImportData = { body: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; }; -export type ImportResponse = Model_From_Zendesk | ModelWithReadOnlyAndWriteOnly; +export type ImportResponses = { + /** + * Success + */ + 200: Model_From_Zendesk; + /** + * Default success response + */ + default: ModelWithReadOnlyAndWriteOnly; +}; + +export type ImportResponse = ImportResponses[keyof ImportResponses]; + +export type ApiVversionOdataControllerCountResponses = { + /** + * Success + */ + 200: Model_From_Zendesk; +}; -export type ApiVversionOdataControllerCountResponse = Model_From_Zendesk; +export type ApiVversionOdataControllerCountResponse = ApiVversionOdataControllerCountResponses[keyof ApiVversionOdataControllerCountResponses]; export type GetApiVbyApiVersionSimpleOperationData = { body?: never; @@ -962,9 +980,23 @@ export type GetApiVbyApiVersionSimpleOperationData = { query?: never; }; -export type GetApiVbyApiVersionSimpleOperationError = ModelWithBoolean; +export type GetApiVbyApiVersionSimpleOperationErrors = { + /** + * Default error response + */ + default: ModelWithBoolean; +}; -export type GetApiVbyApiVersionSimpleOperationResponse = number; +export type GetApiVbyApiVersionSimpleOperationError = GetApiVbyApiVersionSimpleOperationErrors[keyof GetApiVbyApiVersionSimpleOperationErrors]; + +export type GetApiVbyApiVersionSimpleOperationResponses = { + /** + * Response is a simple number + */ + 200: number; +}; + +export type GetApiVbyApiVersionSimpleOperationResponse = GetApiVbyApiVersionSimpleOperationResponses[keyof GetApiVbyApiVersionSimpleOperationResponses]; export type DeleteFooData3 = { body?: never; @@ -1136,7 +1168,18 @@ export type PostCallWithOptionalParamData = { }; }; -export type PostCallWithOptionalParamResponse = number | void; +export type PostCallWithOptionalParamResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; + +export type PostCallWithOptionalParamResponse = PostCallWithOptionalParamResponses[keyof PostCallWithOptionalParamResponses]; export type PostApiVbyApiVersionRequestBodyData = { /** @@ -1259,27 +1302,132 @@ export type CallToTestOrderOfParamsData = { }; }; -export type CallWithNoContentResponseResponse = void; +export type CallWithNoContentResponseResponses = { + /** + * Success + */ + 204: void; +}; -export type CallWithResponseAndNoContentResponseResponse = number | void; +export type CallWithNoContentResponseResponse = CallWithNoContentResponseResponses[keyof CallWithNoContentResponseResponses]; -export type DummyAResponse = _400; +export type CallWithResponseAndNoContentResponseResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; -export type DummyBResponse = void; +export type CallWithResponseAndNoContentResponseResponse = CallWithResponseAndNoContentResponseResponses[keyof CallWithResponseAndNoContentResponseResponses]; -export type CallWithResponseResponse = _import; +export type DummyAResponses = { + 200: _400; +}; -export type CallWithDuplicateResponsesError = ModelWithStringError | DictionaryWithArray | ModelWithBoolean; +export type DummyAResponse = DummyAResponses[keyof DummyAResponses]; -export type CallWithDuplicateResponsesResponse = (ModelWithBoolean & ModelWithInteger) | ModelWithString; +export type DummyBResponses = { + /** + * Success + */ + 204: void; +}; -export type CallWithResponsesError = ModelWithStringError; +export type DummyBResponse = DummyBResponses[keyof DummyBResponses]; -export type CallWithResponsesResponse = { - readonly '@namespace.string'?: string; - readonly '@namespace.integer'?: number; - readonly value?: Array; -} | ModelThatExtends | ModelThatExtendsExtends; +export type CallWithResponseResponses = { + default: _import; +}; + +export type CallWithResponseResponse = CallWithResponseResponses[keyof CallWithResponseResponses]; + +export type CallWithDuplicateResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for 4XX errors + */ + '4XX': DictionaryWithArray; + /** + * Default error response + */ + default: ModelWithBoolean; +}; + +export type CallWithDuplicateResponsesError = CallWithDuplicateResponsesErrors[keyof CallWithDuplicateResponsesErrors]; + +export type CallWithDuplicateResponsesResponses = { + /** + * Message for 200 response + */ + 200: ModelWithBoolean & ModelWithInteger; + /** + * Message for 201 response + */ + 201: ModelWithString; + /** + * Message for 202 response + */ + 202: ModelWithString; +}; + +export type CallWithDuplicateResponsesResponse = CallWithDuplicateResponsesResponses[keyof CallWithDuplicateResponsesResponses]; + +export type CallWithResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for default response + */ + default: ModelWithStringError; +}; + +export type CallWithResponsesError = CallWithResponsesErrors[keyof CallWithResponsesErrors]; + +export type CallWithResponsesResponses = { + /** + * Message for 200 response + */ + 200: { + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; + readonly value?: Array; + }; + /** + * Message for 201 response + */ + 201: ModelThatExtends; + /** + * Message for 202 response + */ + 202: ModelThatExtendsExtends; +}; + +export type CallWithResponsesResponse = CallWithResponsesResponses[keyof CallWithResponsesResponses]; export type CollectionFormatData = { body?: never; @@ -1348,7 +1496,26 @@ export type TypesData = { }; }; -export type TypesResponse = number | string | boolean | {}; +export type TypesResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Response is a simple string + */ + 201: string; + /** + * Response is a simple boolean + */ + 202: boolean; + /** + * Response is a simple object + */ + 203: {}; +}; + +export type TypesResponse = TypesResponses[keyof TypesResponses]; export type UploadFileData = { body: Blob | File; @@ -1361,7 +1528,11 @@ export type UploadFileData = { query?: never; }; -export type UploadFileResponse = boolean; +export type UploadFileResponses = { + 200: boolean; +}; + +export type UploadFileResponse = UploadFileResponses[keyof UploadFileResponses]; export type FileResponseData = { body?: never; @@ -1375,7 +1546,14 @@ export type FileResponseData = { query?: never; }; -export type FileResponseResponse = Blob | File; +export type FileResponseResponses = { + /** + * Success + */ + 200: Blob | File; +}; + +export type FileResponseResponse = FileResponseResponses[keyof FileResponseResponses]; export type ComplexTypesData = { body?: never; @@ -1398,16 +1576,41 @@ export type ComplexTypesData = { }; }; -export type ComplexTypesResponse = Array; +export type ComplexTypesErrors = { + /** + * 400 `server` error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type ComplexTypesResponses = { + /** + * Successful response + */ + 200: Array; +}; -export type MultipartResponseResponse = { - file?: Blob | File; - metadata?: { - foo?: string; - bar?: string; +export type ComplexTypesResponse = ComplexTypesResponses[keyof ComplexTypesResponses]; + +export type MultipartResponseResponses = { + /** + * OK + */ + 200: { + file?: Blob | File; + metadata?: { + foo?: string; + bar?: string; + }; }; }; +export type MultipartResponseResponse = MultipartResponseResponses[keyof MultipartResponseResponses]; + export type MultipartRequestData = { body?: { content?: Blob | File; @@ -1439,7 +1642,32 @@ export type ComplexParamsData = { query?: never; }; -export type ComplexParamsResponse = ModelWithString; +export type ComplexParamsResponses = { + /** + * Success + */ + 200: ModelWithString; +}; + +export type ComplexParamsResponse = ComplexParamsResponses[keyof ComplexParamsResponses]; + +export type CallWithResultFromHeaderErrors = { + /** + * 400 server error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type CallWithResultFromHeaderResponses = { + /** + * Successful response + */ + 200: unknown; +}; export type TestErrorCodeData = { body?: never; @@ -1452,6 +1680,32 @@ export type TestErrorCodeData = { }; }; +export type TestErrorCodeErrors = { + /** + * Custom message: Internal Server Error + */ + 500: unknown; + /** + * Custom message: Not Implemented + */ + 501: unknown; + /** + * Custom message: Bad Gateway + */ + 502: unknown; + /** + * Custom message: Service Unavailable + */ + 503: unknown; +}; + +export type TestErrorCodeResponses = { + /** + * Custom message: Successful response + */ + 200: unknown; +}; + export type NonAsciiæøåÆøÅöôêÊ字符串Data = { body?: never; path?: never; @@ -1463,7 +1717,14 @@ export type NonAsciiæøåÆøÅöôêÊ字符串Data = { }; }; -export type NonAsciiæøåÆøÅöôêÊ字符串Response = Array; +export type NonAsciiæøåÆøÅöôêÊ字符串Responses = { + /** + * Successful response + */ + 200: Array; +}; + +export type NonAsciiæøåÆøÅöôêÊ字符串Response = NonAsciiæøåÆøÅöôêÊ字符串Responses[keyof NonAsciiæøåÆøÅöôêÊ字符串Responses]; export type PutWithFormUrlEncodedData = { body: ArrayWithStrings; diff --git a/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/fastify/default/fastify.gen.ts b/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/fastify/default/fastify.gen.ts index 586d7eb87..b075b001e 100644 --- a/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/fastify/default/fastify.gen.ts +++ b/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/fastify/default/fastify.gen.ts @@ -1,977 +1,20 @@ // This file is auto-generated by @hey-api/openapi-ts +import type { ImportData, ImportResponses, ApiVversionOdataControllerCountResponses, GetApiVbyApiVersionSimpleOperationData, GetApiVbyApiVersionSimpleOperationErrors, GetApiVbyApiVersionSimpleOperationResponses, DeleteFooData3, CallWithDescriptionsData, DeprecatedCallData, CallWithParametersData, CallWithWeirdParameterNamesData, GetCallWithOptionalParamData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponses, PostApiVbyApiVersionRequestBodyData, PostApiVbyApiVersionFormDataData, CallWithDefaultParametersData, CallWithDefaultOptionalParametersData, CallToTestOrderOfParamsData, CallWithNoContentResponseResponses, CallWithResponseAndNoContentResponseResponses, DummyAResponses, DummyBResponses, CallWithResponseResponses, CallWithDuplicateResponsesErrors, CallWithDuplicateResponsesResponses, CallWithResponsesErrors, CallWithResponsesResponses, CollectionFormatData, TypesData, TypesResponses, UploadFileData, UploadFileResponses, FileResponseData, FileResponseResponses, ComplexTypesData, ComplexTypesErrors, ComplexTypesResponses, MultipartResponseResponses, MultipartRequestData, ComplexParamsData, ComplexParamsResponses, CallWithResultFromHeaderErrors, CallWithResultFromHeaderResponses, TestErrorCodeData, TestErrorCodeErrors, TestErrorCodeResponses, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Responses, PutWithFormUrlEncodedData } from './types.gen'; import type { RouteHandler } from 'fastify'; -import type { ImportData, GetApiVbyApiVersionSimpleOperationData, DeleteFooData3, CallWithDescriptionsData, DeprecatedCallData, CallWithParametersData, CallWithWeirdParameterNamesData, GetCallWithOptionalParamData, PostCallWithOptionalParamData, PostApiVbyApiVersionRequestBodyData, PostApiVbyApiVersionFormDataData, CallWithDefaultParametersData, CallWithDefaultOptionalParametersData, CallToTestOrderOfParamsData, CollectionFormatData, TypesData, UploadFileData, FileResponseData, ComplexTypesData, MultipartRequestData, ComplexParamsData, TestErrorCodeData, NonAsciiæøåÆøÅöôêÊ字符串Data, PutWithFormUrlEncodedData } from './types.gen'; - -/** - * Model with number-only name - */ -export type _400 = string; - -/** - * Testing multiline comments in string: First line - * Second line - * - * Fourth line - */ -export type camelCaseCommentWithBreaks = number; - -/** - * Testing multiline comments in string: First line - * Second line - * - * Fourth line - */ -export type CommentWithBreaks = number; - -/** - * Testing backticks in string: `backticks` and ```multiple backticks``` should work - */ -export type CommentWithBackticks = number; - -/** - * Testing backticks and quotes in string: `backticks`, 'quotes', "double quotes" and ```multiple backticks``` should work - */ -export type CommentWithBackticksAndQuotes = number; - -/** - * Testing slashes in string: \backwards\\\ and /forwards/// should work - */ -export type CommentWithSlashes = number; - -/** - * Testing expression placeholders in string: ${expression} should work - */ -export type CommentWithExpressionPlaceholders = number; - -/** - * Testing quotes in string: 'single quote''' and "double quotes""" should work - */ -export type CommentWithQuotes = number; - -/** - * Testing reserved characters in string: * inline * and ** inline ** should work - */ -export type CommentWithReservedCharacters = number; - -/** - * This is a simple number - */ -export type SimpleInteger = number; - -/** - * This is a simple boolean - */ -export type SimpleBoolean = boolean; - -/** - * This is a simple string - */ -export type SimpleString = string; - -/** - * A string with non-ascii (unicode) characters valid in typescript identifiers (æøåÆØÅöÔèÈ字符串) - */ -export type NonAsciiStringæøåÆØÅöôêÊ字符串 = string; - -/** - * This is a simple file - */ -export type SimpleFile = Blob | File; - -/** - * This is a simple reference - */ -export type SimpleReference = ModelWithString; - -/** - * This is a simple string - */ -export type SimpleStringWithPattern = string | null; - -/** - * This is a simple enum with strings - */ -export type EnumWithStrings = 'Success' | 'Warning' | 'Error' | "'Single Quote'" | '"Double Quotes"' | 'Non-ascii: øæåôöØÆÅÔÖ字符串'; - -export type EnumWithReplacedCharacters = "'Single Quote'" | '"Double Quotes"' | 'øæåôöØÆÅÔÖ字符串' | 3.1 | ''; - -/** - * This is a simple enum with numbers - */ -export type EnumWithNumbers = 1 | 2 | 3 | 1.1 | 1.2 | 1.3 | 100 | 200 | 300 | -100 | -200 | -300 | -1.1 | -1.2 | -1.3; - -/** - * Success=1,Warning=2,Error=3 - */ -export type EnumFromDescription = number; - -/** - * This is a simple enum with numbers - */ -export type EnumWithExtensions = 200 | 400 | 500; - -export type EnumWithXEnumNames = 0 | 1 | 2; - -/** - * This is a simple array with numbers - */ -export type ArrayWithNumbers = Array; - -/** - * This is a simple array with booleans - */ -export type ArrayWithBooleans = Array; - -/** - * This is a simple array with strings - */ -export type ArrayWithStrings = Array; - -/** - * This is a simple array with references - */ -export type ArrayWithReferences = Array; - -/** - * This is a simple array containing an array - */ -export type ArrayWithArray = Array>; - -/** - * This is a simple array with properties - */ -export type ArrayWithProperties = Array<{ - '16x16'?: camelCaseCommentWithBreaks; - bar?: string; -}>; - -/** - * This is a simple array with any of properties - */ -export type ArrayWithAnyOfProperties = Array<{ - foo?: string; -} | { - bar?: string; -}>; - -export type AnyOfAnyAndNull = { - data?: unknown; -}; - -/** - * This is a simple array with any of properties - */ -export type AnyOfArrays = { - results?: Array<{ - foo?: string; - } | { - bar?: string; - }>; -}; - -/** - * This is a string dictionary - */ -export type DictionaryWithString = { - [key: string]: string; -}; - -export type DictionaryWithPropertiesAndAdditionalProperties = { - foo?: number; - bar?: boolean; - [key: string]: string | number | boolean | undefined; -}; - -/** - * This is a string reference - */ -export type DictionaryWithReference = { - [key: string]: ModelWithString; -}; - -/** - * This is a complex dictionary - */ -export type DictionaryWithArray = { - [key: string]: Array; -}; - -/** - * This is a string dictionary - */ -export type DictionaryWithDictionary = { - [key: string]: { - [key: string]: string; - }; -}; - -/** - * This is a complex dictionary - */ -export type DictionaryWithProperties = { - [key: string]: { - foo?: string; - bar?: string; - }; -}; - -/** - * This is a model with one number property - */ -export type ModelWithInteger = { - /** - * This is a simple number property - */ - prop?: number; -}; - -/** - * This is a model with one boolean property - */ -export type ModelWithBoolean = { - /** - * This is a simple boolean property - */ - prop?: boolean; -}; - -/** - * This is a model with one string property - */ -export type ModelWithString = { - /** - * This is a simple string property - */ - prop?: string; -}; - -/** - * This is a model with one string property - */ -export type ModelWithStringError = { - /** - * This is a simple string property - */ - prop?: string; -}; - -/** - * `Comment` or `VoiceComment`. The JSON object for adding voice comments to tickets is different. See [Adding voice comments to tickets](/documentation/ticketing/managing-tickets/adding-voice-comments-to-tickets) - */ -export type Model_From_Zendesk = string; - -/** - * This is a model with one string property - */ -export type ModelWithNullableString = { - /** - * This is a simple string property - */ - nullableProp1?: string | null; - /** - * This is a simple string property - */ - nullableRequiredProp1: string | null; - /** - * This is a simple string property - */ - nullableProp2?: string | null; - /** - * This is a simple string property - */ - nullableRequiredProp2: string | null; - /** - * This is a simple enum with strings - */ - 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; -}; - -/** - * This is a model with one enum - */ -export type ModelWithEnum = { - /** - * This is a simple enum with strings - */ - 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; - /** - * These are the HTTP error code enums - */ - statusCode?: '100' | '200 FOO' | '300 FOO_BAR' | '400 foo-bar' | '500 foo.bar' | '600 foo&bar'; - /** - * Simple boolean enum - */ - bool?: true; -}; - -/** - * This is a model with one enum with escaped name - */ -export type ModelWithEnumWithHyphen = { - 'foo-bar-baz-qux'?: '3.0'; -}; - -/** - * This is a model with one enum - */ -export type ModelWithEnumFromDescription = { - /** - * Success=1,Warning=2,Error=3 - */ - test?: number; -}; - -/** - * This is a model with nested enums - */ -export type ModelWithNestedEnums = { - dictionaryWithEnum?: { - [key: string]: 'Success' | 'Warning' | 'Error'; - }; - dictionaryWithEnumFromDescription?: { - [key: string]: number; - }; - arrayWithEnum?: Array<'Success' | 'Warning' | 'Error'>; - arrayWithDescription?: Array; - /** - * This is a simple enum with strings - */ - 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; -}; - -/** - * This is a model with one property containing a reference - */ -export type ModelWithReference = { - prop?: ModelWithProperties; -}; - -/** - * This is a model with one property containing an array - */ -export type ModelWithArrayReadOnlyAndWriteOnly = { - prop?: Array; - propWithFile?: Array; - propWithNumber?: Array; -}; - -/** - * This is a model with one property containing an array - */ -export type ModelWithArray = { - prop?: Array; - propWithFile?: Array; - propWithNumber?: Array; -}; - -/** - * This is a model with one property containing a dictionary - */ -export type ModelWithDictionary = { - prop?: { - [key: string]: string; - }; -}; - -/** - * This is a deprecated model with a deprecated property - * @deprecated - */ -export type DeprecatedModel = { - /** - * This is a deprecated property - * @deprecated - */ - prop?: string; -}; - -/** - * This is a model with one property containing a circular reference - */ -export type ModelWithCircularReference = { - prop?: ModelWithCircularReference; -}; - -/** - * This is a model with one property with a 'one of' relationship - */ -export type CompositionWithOneOf = { - propA?: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; -}; - -/** - * This is a model with one property with a 'one of' relationship where the options are not $ref - */ -export type CompositionWithOneOfAnonymous = { - propA?: { - propA?: string; - } | string | number; -}; - -/** - * Circle - */ -export type ModelCircle = { - kind: string; - radius?: number; -}; - -/** - * Square - */ -export type ModelSquare = { - kind: string; - sideLength?: number; -}; - -/** - * This is a model with one property with a 'one of' relationship where the options are not $ref - */ -export type CompositionWithOneOfDiscriminator = ({ - kind?: 'circle'; -} & ModelCircle) | ({ - kind?: 'square'; -} & ModelSquare); - -/** - * This is a model with one property with a 'any of' relationship - */ -export type CompositionWithAnyOf = { - propA?: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; -}; - -/** - * This is a model with one property with a 'any of' relationship where the options are not $ref - */ -export type CompositionWithAnyOfAnonymous = { - propA?: { - propA?: string; - } | string | number; -}; - -/** - * This is a model with nested 'any of' property with a type null - */ -export type CompositionWithNestedAnyAndTypeNull = { - propA?: Array | Array; -}; - -export type _3e_num_1Период = 'Bird' | 'Dog'; - -export type ConstValue = 'ConstValue'; - -/** - * This is a model with one property with a 'any of' relationship where the options are not $ref - */ -export type CompositionWithNestedAnyOfAndNull = { - propA?: Array<_3e_num_1Период | ConstValue> | null; -}; - -/** - * This is a model with one property with a 'one of' relationship - */ -export type CompositionWithOneOfAndNullable = { - propA?: { - boolean?: boolean; - } | ModelWithEnum | ModelWithArray | ModelWithDictionary | null; -}; - -/** - * This is a model that contains a simple dictionary within composition - */ -export type CompositionWithOneOfAndSimpleDictionary = { - propA?: boolean | { - [key: string]: number; - }; -}; - -/** - * This is a model that contains a dictionary of simple arrays within composition - */ -export type CompositionWithOneOfAndSimpleArrayDictionary = { - propA?: boolean | { - [key: string]: Array; - }; -}; - -/** - * This is a model that contains a dictionary of complex arrays (composited) within composition - */ -export type CompositionWithOneOfAndComplexArrayDictionary = { - propA?: boolean | { - [key: string]: Array; - }; -}; - -/** - * This is a model with one property with a 'all of' relationship - */ -export type CompositionWithAllOfAndNullable = { - propA?: ({ - boolean?: boolean; - } & ModelWithEnum & ModelWithArray & ModelWithDictionary) | null; -}; - -/** - * This is a model with one property with a 'any of' relationship - */ -export type CompositionWithAnyOfAndNullable = { - propA?: { - boolean?: boolean; - } | ModelWithEnum | ModelWithArray | ModelWithDictionary | null; -}; - -/** - * This is a base model with two simple optional properties - */ -export type CompositionBaseModel = { - firstName?: string; - lastname?: string; -}; - -/** - * This is a model that extends the base model - */ -export type CompositionExtendedModel = CompositionBaseModel & { - age: number; - firstName: string; - lastname: string; -}; - -/** - * This is a model with one nested property - */ -export type ModelWithProperties = { - required: string; - readonly requiredAndReadOnly: string; - requiredAndNullable: string | null; - string?: string; - number?: number; - boolean?: boolean; - reference?: ModelWithString; - 'property with space'?: string; - default?: string; - try?: string; - readonly '@namespace.string'?: string; - readonly '@namespace.integer'?: number; -}; - -/** - * This is a model with one nested property - */ -export type ModelWithNestedProperties = { - readonly first: { - readonly second: { - readonly third: string | null; - } | null; - } | null; -}; - -/** - * This is a model with duplicated properties - */ -export type ModelWithDuplicateProperties = { - prop?: ModelWithString; -}; - -/** - * This is a model with ordered properties - */ -export type ModelWithOrderedProperties = { - zebra?: string; - apple?: string; - hawaii?: string; -}; - -/** - * This is a model with duplicated imports - */ -export type ModelWithDuplicateImports = { - propA?: ModelWithString; - propB?: ModelWithString; - propC?: ModelWithString; -}; - -/** - * This is a model that extends another model - */ -export type ModelThatExtends = ModelWithString & { - propExtendsA?: string; - propExtendsB?: ModelWithString; -}; - -/** - * This is a model that extends another model - */ -export type ModelThatExtendsExtends = ModelWithString & ModelThatExtends & { - propExtendsC?: string; - propExtendsD?: ModelWithString; -}; - -/** - * This is a model that contains a some patterns - */ -export type ModelWithPattern = { - key: string; - name: string; - readonly enabled?: boolean; - readonly modified?: string; - id?: string; - text?: string; - patternWithSingleQuotes?: string; - patternWithNewline?: string; - patternWithBacktick?: string; -}; - -export type File = { - readonly id?: string; - readonly updated_at?: string; - readonly created_at?: string; - mime: string; - readonly file?: string; -}; - -export type _default = { - name?: string; -}; - -export type Pageable = { - page?: number; - size?: number; - sort?: Array; -}; - -/** - * This is a free-form object without additionalProperties. - */ -export type FreeFormObjectWithoutAdditionalProperties = {}; - -/** - * This is a free-form object with additionalProperties: true. - */ -export type FreeFormObjectWithAdditionalPropertiesEqTrue = { - [key: string]: unknown; -}; - -/** - * This is a free-form object with additionalProperties: {}. - */ -export type FreeFormObjectWithAdditionalPropertiesEqEmptyObject = {}; - -export type ModelWithConst = { - String?: 'String'; - number?: 0; - null?: unknown; - withType?: 'Some string'; -}; - -/** - * This is a model with one property and additionalProperties: true - */ -export type ModelWithAdditionalPropertiesEqTrue = { - /** - * This is a simple string property - */ - prop?: string; - [key: string]: unknown | string | undefined; -}; - -export type NestedAnyOfArraysNullable = { - nullableArray?: Array | null; -}; - -export type CompositionWithOneOfAndProperties = ({ - foo: SimpleParameter; -} | { - bar: NonAsciiStringæøåÆØÅöôêÊ字符串; -}) & { - baz: number | null; - qux: number; -}; - -/** - * An object that can be null - */ -export type NullableObject = { - foo?: string; -} | null; - -/** - * Some % character - */ -export type CharactersInDescription = string; - -export type ModelWithNullableObject = { - data?: NullableObject; -}; - -export type ModelWithOneOfEnum = { - foo: 'Bar'; -} | { - foo: 'Baz'; -} | { - foo: 'Qux'; -} | { - content: string; - foo: 'Quux'; -} | { - content: [ - string, - string - ]; - foo: 'Corge'; -}; - -export type ModelWithNestedArrayEnumsDataFoo = 'foo' | 'bar'; - -export type ModelWithNestedArrayEnumsDataBar = 'baz' | 'qux'; - -export type ModelWithNestedArrayEnumsData = { - foo?: Array; - bar?: Array; -}; - -export type ModelWithNestedArrayEnums = { - array_strings?: Array; - data?: ModelWithNestedArrayEnumsData; -}; - -export type ModelWithNestedCompositionEnums = { - foo?: ModelWithNestedArrayEnumsDataFoo; -}; - -export type ModelWithReadOnlyAndWriteOnly = { - foo: string; - readonly bar: string; - baz: string; -}; - -export type ModelWithConstantSizeArray = [ - number, - number -]; - -export type ModelWithAnyOfConstantSizeArray = [ - number | string, - number | string, - number | string -]; - -export type ModelWithPrefixItemsConstantSizeArray = Array; - -export type ModelWithAnyOfConstantSizeArrayNullable = [ - number | null | string, - number | null | string, - number | null | string -]; - -export type ModelWithAnyOfConstantSizeArrayWithNSizeAndOptions = [ - number | _import, - number | _import -]; - -export type ModelWithAnyOfConstantSizeArrayAndIntersect = [ - number & string, - number & string -]; - -export type ModelWithNumericEnumUnion = { - /** - * Период - */ - value?: -10 | -1 | 0 | 1 | 3 | 6 | 12; -}; - -/** - * Some description with `back ticks` - */ -export type ModelWithBackticksInDescription = { - /** - * The template `that` should be used for parsing and importing the contents of the CSV file. - * - *

There is one placeholder currently supported:

  • ${x} - refers to the n-th column in the CSV file, e.g. ${1}, ${2}, ...)

Example of a correct JSON template:

- *
-     * [
-     * {
-     * "resourceType": "Asset",
-     * "identifier": {
-     * "name": "${1}",
-     * "domain": {
-     * "name": "${2}",
-     * "community": {
-     * "name": "Some Community"
-     * }
-     * }
-     * },
-     * "attributes" : {
-     * "00000000-0000-0000-0000-000000003115" : [ {
-     * "value" : "${3}"
-     * } ],
-     * "00000000-0000-0000-0000-000000000222" : [ {
-     * "value" : "${4}"
-     * } ]
-     * }
-     * }
-     * ]
-     * 
- */ - template?: string; -}; - -export type ModelWithOneOfAndProperties = (SimpleParameter | NonAsciiStringæøåÆØÅöôêÊ字符串) & { - baz: number | null; - qux: number; -}; - -/** - * Model used to test deduplication strategy (unused) - */ -export type ParameterSimpleParameterUnused = string; - -/** - * Model used to test deduplication strategy - */ -export type PostServiceWithEmptyTagResponse = string; - -/** - * Model used to test deduplication strategy - */ -export type PostServiceWithEmptyTagResponse2 = string; - -/** - * Model used to test deduplication strategy - */ -export type DeleteFooData = string; - -/** - * Model used to test deduplication strategy - */ -export type DeleteFooData2 = string; - -/** - * Model with restricted keyword name - */ -export type _import = string; - -export type SchemaWithFormRestrictedKeys = { - description?: string; - 'x-enum-descriptions'?: string; - 'x-enum-varnames'?: string; - 'x-enumNames'?: string; - title?: string; - object?: { - description?: string; - 'x-enum-descriptions'?: string; - 'x-enum-varnames'?: string; - 'x-enumNames'?: string; - title?: string; - }; - array?: Array<{ - description?: string; - 'x-enum-descriptions'?: string; - 'x-enum-varnames'?: string; - 'x-enumNames'?: string; - title?: string; - }>; -}; - -/** - * This schema was giving PascalCase transformations a hard time - */ -export type io_k8s_apimachinery_pkg_apis_meta_v1_DeleteOptions = { - /** - * Must be fulfilled before a deletion is carried out. If not possible, a 409 Conflict status will be returned. - */ - preconditions?: io_k8s_apimachinery_pkg_apis_meta_v1_Preconditions; -}; - -/** - * This schema was giving PascalCase transformations a hard time - */ -export type io_k8s_apimachinery_pkg_apis_meta_v1_Preconditions = { - /** - * Specifies the target ResourceVersion - */ - resourceVersion?: string; - /** - * Specifies the target UID. - */ - uid?: string; -}; - -export type AdditionalPropertiesUnknownIssue = { - [key: string]: string | number; -}; - -export type AdditionalPropertiesUnknownIssue2 = { - [key: string]: string | number; -}; - -export type AdditionalPropertiesUnknownIssue3 = string & { - entries: { - [key: string]: AdditionalPropertiesUnknownIssue; - }; -}; - -export type AdditionalPropertiesIntegerIssue = { - value: number; - [key: string]: number; -}; - -export type OneOfAllOfIssue = ((ConstValue | Generic_Schema_Duplicate_Issue_1_System_Boolean_) & _3e_num_1Период) | Generic_Schema_Duplicate_Issue_1_System_String_; - -export type Generic_Schema_Duplicate_Issue_1_System_Boolean_ = { - item?: boolean; - error?: string | null; - readonly hasError?: boolean; - data?: { - [key: string]: never; - }; -}; - -export type Generic_Schema_Duplicate_Issue_1_System_String_ = { - item?: string | null; - error?: string | null; - readonly hasError?: boolean; -}; - -/** - * This is a reusable parameter - */ -export type SimpleParameter = string; - -/** - * Parameter with illegal characters - */ -export type x_Foo_Bar = ModelWithString; export type RouteHandlers = { - export: RouteHandler<{}>; import: RouteHandler<{ Body: ImportData['body']; - Reply: { - '200': Model_From_Zendesk; - }; + Reply: ImportResponses; }>; apiVVersionOdataControllerCount: RouteHandler<{ - Reply: { - '200': Model_From_Zendesk; - }; + Reply: ApiVversionOdataControllerCountResponses; }>; getApiVbyApiVersionSimpleOperation: RouteHandler<{ Params: GetApiVbyApiVersionSimpleOperationData['path']; - Reply: { - '200': number; - }; + Reply: GetApiVbyApiVersionSimpleOperationErrors & GetApiVbyApiVersionSimpleOperationResponses; }>; - deleteCallWithoutParametersAndResponse: RouteHandler<{}>; - getCallWithoutParametersAndResponse: RouteHandler<{}>; - headCallWithoutParametersAndResponse: RouteHandler<{}>; - optionsCallWithoutParametersAndResponse: RouteHandler<{}>; - patchCallWithoutParametersAndResponse: RouteHandler<{}>; - postCallWithoutParametersAndResponse: RouteHandler<{}>; - putCallWithoutParametersAndResponse: RouteHandler<{}>; deleteFoo: RouteHandler<{ Headers: DeleteFooData3['headers']; Params: DeleteFooData3['path']; @@ -1001,10 +44,7 @@ export type RouteHandlers = { postCallWithOptionalParam: RouteHandler<{ Body: PostCallWithOptionalParamData['body']; Querystring: PostCallWithOptionalParamData['query']; - Reply: { - '200': number; - '204': void; - }; + Reply: PostCallWithOptionalParamResponses; }>; postApiVbyApiVersionRequestBody: RouteHandler<{ Body: PostApiVbyApiVersionRequestBodyData['body']; @@ -1023,58 +63,26 @@ export type RouteHandlers = { callToTestOrderOfParams: RouteHandler<{ Querystring: CallToTestOrderOfParamsData['query']; }>; - duplicateName: RouteHandler<{}>; - duplicateName2: RouteHandler<{}>; - duplicateName3: RouteHandler<{}>; - duplicateName4: RouteHandler<{}>; callWithNoContentResponse: RouteHandler<{ - Reply: { - '204': void; - }; + Reply: CallWithNoContentResponseResponses; }>; callWithResponseAndNoContentResponse: RouteHandler<{ - Reply: { - '200': number; - '204': void; - }; + Reply: CallWithResponseAndNoContentResponseResponses; }>; dummyA: RouteHandler<{ - Reply: { - '200': _400; - }; + Reply: DummyAResponses; }>; dummyB: RouteHandler<{ - Reply: { - '204': void; - }; + Reply: DummyBResponses; }>; callWithResponse: RouteHandler<{ - Reply: {}; + Reply: CallWithResponseResponses; }>; callWithDuplicateResponses: RouteHandler<{ - Reply: { - '200': ModelWithBoolean & ModelWithInteger; - '201': ModelWithString; - '202': ModelWithString; - '500': ModelWithStringError; - '501': ModelWithStringError; - '502': ModelWithStringError; - '4XX': DictionaryWithArray; - }; + Reply: CallWithDuplicateResponsesErrors & CallWithDuplicateResponsesResponses; }>; callWithResponses: RouteHandler<{ - Reply: { - '200': { - readonly '@namespace.string'?: string; - readonly '@namespace.integer'?: number; - readonly value?: Array; - }; - '201': ModelThatExtends; - '202': ModelThatExtendsExtends; - '500': ModelWithStringError; - '501': ModelWithStringError; - '502': ModelWithStringError; - }; + Reply: CallWithResponsesErrors & CallWithResponsesResponses; }>; collectionFormat: RouteHandler<{ Querystring: CollectionFormatData['query']; @@ -1082,44 +90,23 @@ export type RouteHandlers = { types: RouteHandler<{ Params?: TypesData['path']; Querystring: TypesData['query']; - Reply: { - '200': number; - '201': string; - '202': boolean; - '203': {}; - }; + Reply: TypesResponses; }>; uploadFile: RouteHandler<{ Body: UploadFileData['body']; Params: UploadFileData['path']; - Reply: { - '200': boolean; - }; + Reply: UploadFileResponses; }>; fileResponse: RouteHandler<{ Params: FileResponseData['path']; - Reply: { - '200': Blob | File; - }; + Reply: FileResponseResponses; }>; complexTypes: RouteHandler<{ Querystring: ComplexTypesData['query']; - Reply: { - '200': Array; - '400': unknown; - '500': unknown; - }; + Reply: ComplexTypesErrors & ComplexTypesResponses; }>; multipartResponse: RouteHandler<{ - Reply: { - '200': { - file?: Blob | File; - metadata?: { - foo?: string; - bar?: string; - }; - }; - }; + Reply: MultipartResponseResponses; }>; multipartRequest: RouteHandler<{ Body: MultipartRequestData['body']; @@ -1127,32 +114,18 @@ export type RouteHandlers = { complexParams: RouteHandler<{ Body: ComplexParamsData['body']; Params: ComplexParamsData['path']; - Reply: { - '200': ModelWithString; - }; + Reply: ComplexParamsResponses; }>; callWithResultFromHeader: RouteHandler<{ - Reply: { - '200': unknown; - '400': unknown; - '500': unknown; - }; + Reply: CallWithResultFromHeaderErrors & CallWithResultFromHeaderResponses; }>; testErrorCode: RouteHandler<{ Querystring: TestErrorCodeData['query']; - Reply: { - '200': unknown; - '500': unknown; - '501': unknown; - '502': unknown; - '503': unknown; - }; + Reply: TestErrorCodeErrors & TestErrorCodeResponses; }>; nonAsciiæøåÆøÅöôêÊ字符串: RouteHandler<{ Querystring: NonAsciiæøåÆøÅöôêÊ字符串Data['query']; - Reply: { - '200': Array; - }; + Reply: NonAsciiæøåÆøÅöôêÊ字符串Responses; }>; putWithFormUrlEncoded: RouteHandler<{ Body: PutWithFormUrlEncodedData['body']; 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 b914fd963..37046a7eb 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 @@ -947,9 +947,27 @@ export type ImportData = { body: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; }; -export type ImportResponse = Model_From_Zendesk | ModelWithReadOnlyAndWriteOnly; +export type ImportResponses = { + /** + * Success + */ + 200: Model_From_Zendesk; + /** + * Default success response + */ + default: ModelWithReadOnlyAndWriteOnly; +}; + +export type ImportResponse = ImportResponses[keyof ImportResponses]; + +export type ApiVversionOdataControllerCountResponses = { + /** + * Success + */ + 200: Model_From_Zendesk; +}; -export type ApiVversionOdataControllerCountResponse = Model_From_Zendesk; +export type ApiVversionOdataControllerCountResponse = ApiVversionOdataControllerCountResponses[keyof ApiVversionOdataControllerCountResponses]; export type GetApiVbyApiVersionSimpleOperationData = { body?: never; @@ -962,9 +980,23 @@ export type GetApiVbyApiVersionSimpleOperationData = { query?: never; }; -export type GetApiVbyApiVersionSimpleOperationError = ModelWithBoolean; +export type GetApiVbyApiVersionSimpleOperationErrors = { + /** + * Default error response + */ + default: ModelWithBoolean; +}; -export type GetApiVbyApiVersionSimpleOperationResponse = number; +export type GetApiVbyApiVersionSimpleOperationError = GetApiVbyApiVersionSimpleOperationErrors[keyof GetApiVbyApiVersionSimpleOperationErrors]; + +export type GetApiVbyApiVersionSimpleOperationResponses = { + /** + * Response is a simple number + */ + 200: number; +}; + +export type GetApiVbyApiVersionSimpleOperationResponse = GetApiVbyApiVersionSimpleOperationResponses[keyof GetApiVbyApiVersionSimpleOperationResponses]; export type DeleteFooData3 = { body?: never; @@ -1136,7 +1168,18 @@ export type PostCallWithOptionalParamData = { }; }; -export type PostCallWithOptionalParamResponse = number | void; +export type PostCallWithOptionalParamResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; + +export type PostCallWithOptionalParamResponse = PostCallWithOptionalParamResponses[keyof PostCallWithOptionalParamResponses]; export type PostApiVbyApiVersionRequestBodyData = { /** @@ -1259,27 +1302,132 @@ export type CallToTestOrderOfParamsData = { }; }; -export type CallWithNoContentResponseResponse = void; +export type CallWithNoContentResponseResponses = { + /** + * Success + */ + 204: void; +}; -export type CallWithResponseAndNoContentResponseResponse = number | void; +export type CallWithNoContentResponseResponse = CallWithNoContentResponseResponses[keyof CallWithNoContentResponseResponses]; -export type DummyAResponse = _400; +export type CallWithResponseAndNoContentResponseResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; -export type DummyBResponse = void; +export type CallWithResponseAndNoContentResponseResponse = CallWithResponseAndNoContentResponseResponses[keyof CallWithResponseAndNoContentResponseResponses]; -export type CallWithResponseResponse = _import; +export type DummyAResponses = { + 200: _400; +}; -export type CallWithDuplicateResponsesError = ModelWithStringError | DictionaryWithArray | ModelWithBoolean; +export type DummyAResponse = DummyAResponses[keyof DummyAResponses]; -export type CallWithDuplicateResponsesResponse = (ModelWithBoolean & ModelWithInteger) | ModelWithString; +export type DummyBResponses = { + /** + * Success + */ + 204: void; +}; -export type CallWithResponsesError = ModelWithStringError; +export type DummyBResponse = DummyBResponses[keyof DummyBResponses]; -export type CallWithResponsesResponse = { - readonly '@namespace.string'?: string; - readonly '@namespace.integer'?: number; - readonly value?: Array; -} | ModelThatExtends | ModelThatExtendsExtends; +export type CallWithResponseResponses = { + default: _import; +}; + +export type CallWithResponseResponse = CallWithResponseResponses[keyof CallWithResponseResponses]; + +export type CallWithDuplicateResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for 4XX errors + */ + '4XX': DictionaryWithArray; + /** + * Default error response + */ + default: ModelWithBoolean; +}; + +export type CallWithDuplicateResponsesError = CallWithDuplicateResponsesErrors[keyof CallWithDuplicateResponsesErrors]; + +export type CallWithDuplicateResponsesResponses = { + /** + * Message for 200 response + */ + 200: ModelWithBoolean & ModelWithInteger; + /** + * Message for 201 response + */ + 201: ModelWithString; + /** + * Message for 202 response + */ + 202: ModelWithString; +}; + +export type CallWithDuplicateResponsesResponse = CallWithDuplicateResponsesResponses[keyof CallWithDuplicateResponsesResponses]; + +export type CallWithResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for default response + */ + default: ModelWithStringError; +}; + +export type CallWithResponsesError = CallWithResponsesErrors[keyof CallWithResponsesErrors]; + +export type CallWithResponsesResponses = { + /** + * Message for 200 response + */ + 200: { + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; + readonly value?: Array; + }; + /** + * Message for 201 response + */ + 201: ModelThatExtends; + /** + * Message for 202 response + */ + 202: ModelThatExtendsExtends; +}; + +export type CallWithResponsesResponse = CallWithResponsesResponses[keyof CallWithResponsesResponses]; export type CollectionFormatData = { body?: never; @@ -1348,7 +1496,26 @@ export type TypesData = { }; }; -export type TypesResponse = number | string | boolean | {}; +export type TypesResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Response is a simple string + */ + 201: string; + /** + * Response is a simple boolean + */ + 202: boolean; + /** + * Response is a simple object + */ + 203: {}; +}; + +export type TypesResponse = TypesResponses[keyof TypesResponses]; export type UploadFileData = { body: Blob | File; @@ -1361,7 +1528,11 @@ export type UploadFileData = { query?: never; }; -export type UploadFileResponse = boolean; +export type UploadFileResponses = { + 200: boolean; +}; + +export type UploadFileResponse = UploadFileResponses[keyof UploadFileResponses]; export type FileResponseData = { body?: never; @@ -1375,7 +1546,14 @@ export type FileResponseData = { query?: never; }; -export type FileResponseResponse = Blob | File; +export type FileResponseResponses = { + /** + * Success + */ + 200: Blob | File; +}; + +export type FileResponseResponse = FileResponseResponses[keyof FileResponseResponses]; export type ComplexTypesData = { body?: never; @@ -1398,16 +1576,41 @@ export type ComplexTypesData = { }; }; -export type ComplexTypesResponse = Array; +export type ComplexTypesErrors = { + /** + * 400 `server` error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type ComplexTypesResponses = { + /** + * Successful response + */ + 200: Array; +}; -export type MultipartResponseResponse = { - file?: Blob | File; - metadata?: { - foo?: string; - bar?: string; +export type ComplexTypesResponse = ComplexTypesResponses[keyof ComplexTypesResponses]; + +export type MultipartResponseResponses = { + /** + * OK + */ + 200: { + file?: Blob | File; + metadata?: { + foo?: string; + bar?: string; + }; }; }; +export type MultipartResponseResponse = MultipartResponseResponses[keyof MultipartResponseResponses]; + export type MultipartRequestData = { body?: { content?: Blob | File; @@ -1439,7 +1642,32 @@ export type ComplexParamsData = { query?: never; }; -export type ComplexParamsResponse = ModelWithString; +export type ComplexParamsResponses = { + /** + * Success + */ + 200: ModelWithString; +}; + +export type ComplexParamsResponse = ComplexParamsResponses[keyof ComplexParamsResponses]; + +export type CallWithResultFromHeaderErrors = { + /** + * 400 server error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type CallWithResultFromHeaderResponses = { + /** + * Successful response + */ + 200: unknown; +}; export type TestErrorCodeData = { body?: never; @@ -1452,6 +1680,32 @@ export type TestErrorCodeData = { }; }; +export type TestErrorCodeErrors = { + /** + * Custom message: Internal Server Error + */ + 500: unknown; + /** + * Custom message: Not Implemented + */ + 501: unknown; + /** + * Custom message: Bad Gateway + */ + 502: unknown; + /** + * Custom message: Service Unavailable + */ + 503: unknown; +}; + +export type TestErrorCodeResponses = { + /** + * Custom message: Successful response + */ + 200: unknown; +}; + export type NonAsciiæøåÆøÅöôêÊ字符串Data = { body?: never; path?: never; @@ -1463,7 +1717,14 @@ export type NonAsciiæøåÆøÅöôêÊ字符串Data = { }; }; -export type NonAsciiæøåÆøÅöôêÊ字符串Response = Array; +export type NonAsciiæøåÆøÅöôêÊ字符串Responses = { + /** + * Successful response + */ + 200: Array; +}; + +export type NonAsciiæøåÆøÅöôêÊ字符串Response = NonAsciiæøåÆøÅöôêÊ字符串Responses[keyof NonAsciiæøåÆøÅöôêÊ字符串Responses]; export type PutWithFormUrlEncodedData = { body: ArrayWithStrings; diff --git a/packages/openapi-ts/test/__snapshots__/3.1.x/operation-204/types.gen.ts b/packages/openapi-ts/test/__snapshots__/3.1.x/operation-204/types.gen.ts index 82480d759..c3706fce7 100644 --- a/packages/openapi-ts/test/__snapshots__/3.1.x/operation-204/types.gen.ts +++ b/packages/openapi-ts/test/__snapshots__/3.1.x/operation-204/types.gen.ts @@ -1,3 +1,14 @@ // This file is auto-generated by @hey-api/openapi-ts -export type PostFooResponse = string | void; \ No newline at end of file +export type PostFooResponses = { + /** + * OK + */ + 200: string; + /** + * Created + */ + 204: void; +}; + +export type PostFooResponse = PostFooResponses[keyof PostFooResponses]; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/3.1.x/parameter-explode-false/types.gen.ts b/packages/openapi-ts/test/__snapshots__/3.1.x/parameter-explode-false/types.gen.ts index 2003ec4a4..6cd720ee8 100644 --- a/packages/openapi-ts/test/__snapshots__/3.1.x/parameter-explode-false/types.gen.ts +++ b/packages/openapi-ts/test/__snapshots__/3.1.x/parameter-explode-false/types.gen.ts @@ -6,4 +6,11 @@ export type PostFooData = { query?: { foo?: Array; }; +}; + +export type PostFooResponses = { + /** + * OK + */ + default: unknown; }; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/@hey-api/services/default/types.gen.ts b/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/@hey-api/services/default/types.gen.ts index 2f6b56c07..0478efcec 100644 --- a/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/@hey-api/services/default/types.gen.ts +++ b/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/@hey-api/services/default/types.gen.ts @@ -951,9 +951,27 @@ export type ImportData = { body: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; }; -export type ImportResponse = Model_From_Zendesk | ModelWithReadOnlyAndWriteOnly; +export type ImportResponses = { + /** + * Success + */ + 200: Model_From_Zendesk; + /** + * Default success response + */ + default: ModelWithReadOnlyAndWriteOnly; +}; + +export type ImportResponse = ImportResponses[keyof ImportResponses]; + +export type ApiVversionOdataControllerCountResponses = { + /** + * Success + */ + 200: Model_From_Zendesk; +}; -export type ApiVversionOdataControllerCountResponse = Model_From_Zendesk; +export type ApiVversionOdataControllerCountResponse = ApiVversionOdataControllerCountResponses[keyof ApiVversionOdataControllerCountResponses]; export type GetApiVbyApiVersionSimpleOperationData = { body?: never; @@ -966,9 +984,23 @@ export type GetApiVbyApiVersionSimpleOperationData = { query?: never; }; -export type GetApiVbyApiVersionSimpleOperationError = ModelWithBoolean; +export type GetApiVbyApiVersionSimpleOperationErrors = { + /** + * Default error response + */ + default: ModelWithBoolean; +}; -export type GetApiVbyApiVersionSimpleOperationResponse = number; +export type GetApiVbyApiVersionSimpleOperationError = GetApiVbyApiVersionSimpleOperationErrors[keyof GetApiVbyApiVersionSimpleOperationErrors]; + +export type GetApiVbyApiVersionSimpleOperationResponses = { + /** + * Response is a simple number + */ + 200: number; +}; + +export type GetApiVbyApiVersionSimpleOperationResponse = GetApiVbyApiVersionSimpleOperationResponses[keyof GetApiVbyApiVersionSimpleOperationResponses]; export type DeleteFooData3 = { body?: never; @@ -1140,7 +1172,18 @@ export type PostCallWithOptionalParamData = { }; }; -export type PostCallWithOptionalParamResponse = number | void; +export type PostCallWithOptionalParamResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; + +export type PostCallWithOptionalParamResponse = PostCallWithOptionalParamResponses[keyof PostCallWithOptionalParamResponses]; export type PostApiVbyApiVersionRequestBodyData = { /** @@ -1263,27 +1306,132 @@ export type CallToTestOrderOfParamsData = { }; }; -export type CallWithNoContentResponseResponse = void; +export type CallWithNoContentResponseResponses = { + /** + * Success + */ + 204: void; +}; -export type CallWithResponseAndNoContentResponseResponse = number | void; +export type CallWithNoContentResponseResponse = CallWithNoContentResponseResponses[keyof CallWithNoContentResponseResponses]; -export type DummyAResponse = _400; +export type CallWithResponseAndNoContentResponseResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; -export type DummyBResponse = void; +export type CallWithResponseAndNoContentResponseResponse = CallWithResponseAndNoContentResponseResponses[keyof CallWithResponseAndNoContentResponseResponses]; -export type CallWithResponseResponse = _import; +export type DummyAResponses = { + 200: _400; +}; -export type CallWithDuplicateResponsesError = ModelWithStringError | DictionaryWithArray | ModelWithBoolean; +export type DummyAResponse = DummyAResponses[keyof DummyAResponses]; -export type CallWithDuplicateResponsesResponse = (ModelWithBoolean & ModelWithInteger) | ModelWithString; +export type DummyBResponses = { + /** + * Success + */ + 204: void; +}; -export type CallWithResponsesError = ModelWithStringError; +export type DummyBResponse = DummyBResponses[keyof DummyBResponses]; -export type CallWithResponsesResponse = { - readonly '@namespace.string'?: string; - readonly '@namespace.integer'?: number; - readonly value?: Array; -} | ModelThatExtends | ModelThatExtendsExtends; +export type CallWithResponseResponses = { + default: _import; +}; + +export type CallWithResponseResponse = CallWithResponseResponses[keyof CallWithResponseResponses]; + +export type CallWithDuplicateResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for 4XX errors + */ + '4XX': DictionaryWithArray; + /** + * Default error response + */ + default: ModelWithBoolean; +}; + +export type CallWithDuplicateResponsesError = CallWithDuplicateResponsesErrors[keyof CallWithDuplicateResponsesErrors]; + +export type CallWithDuplicateResponsesResponses = { + /** + * Message for 200 response + */ + 200: ModelWithBoolean & ModelWithInteger; + /** + * Message for 201 response + */ + 201: ModelWithString; + /** + * Message for 202 response + */ + 202: ModelWithString; +}; + +export type CallWithDuplicateResponsesResponse = CallWithDuplicateResponsesResponses[keyof CallWithDuplicateResponsesResponses]; + +export type CallWithResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for default response + */ + default: ModelWithStringError; +}; + +export type CallWithResponsesError = CallWithResponsesErrors[keyof CallWithResponsesErrors]; + +export type CallWithResponsesResponses = { + /** + * Message for 200 response + */ + 200: { + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; + readonly value?: Array; + }; + /** + * Message for 201 response + */ + 201: ModelThatExtends; + /** + * Message for 202 response + */ + 202: ModelThatExtendsExtends; +}; + +export type CallWithResponsesResponse = CallWithResponsesResponses[keyof CallWithResponsesResponses]; export type CollectionFormatData = { body?: never; @@ -1352,7 +1500,26 @@ export type TypesData = { }; }; -export type TypesResponse = number | string | boolean | {}; +export type TypesResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Response is a simple string + */ + 201: string; + /** + * Response is a simple boolean + */ + 202: boolean; + /** + * Response is a simple object + */ + 203: {}; +}; + +export type TypesResponse = TypesResponses[keyof TypesResponses]; export type UploadFileData = { body: Blob | File; @@ -1365,7 +1532,11 @@ export type UploadFileData = { query?: never; }; -export type UploadFileResponse = boolean; +export type UploadFileResponses = { + 200: boolean; +}; + +export type UploadFileResponse = UploadFileResponses[keyof UploadFileResponses]; export type FileResponseData = { body?: never; @@ -1379,7 +1550,14 @@ export type FileResponseData = { query?: never; }; -export type FileResponseResponse = Blob | File; +export type FileResponseResponses = { + /** + * Success + */ + 200: Blob | File; +}; + +export type FileResponseResponse = FileResponseResponses[keyof FileResponseResponses]; export type ComplexTypesData = { body?: never; @@ -1402,16 +1580,41 @@ export type ComplexTypesData = { }; }; -export type ComplexTypesResponse = Array; +export type ComplexTypesErrors = { + /** + * 400 `server` error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type ComplexTypesResponses = { + /** + * Successful response + */ + 200: Array; +}; -export type MultipartResponseResponse = { - file?: Blob | File; - metadata?: { - foo?: string; - bar?: string; +export type ComplexTypesResponse = ComplexTypesResponses[keyof ComplexTypesResponses]; + +export type MultipartResponseResponses = { + /** + * OK + */ + 200: { + file?: Blob | File; + metadata?: { + foo?: string; + bar?: string; + }; }; }; +export type MultipartResponseResponse = MultipartResponseResponses[keyof MultipartResponseResponses]; + export type MultipartRequestData = { body?: { content?: Blob | File; @@ -1443,7 +1646,32 @@ export type ComplexParamsData = { query?: never; }; -export type ComplexParamsResponse = ModelWithString; +export type ComplexParamsResponses = { + /** + * Success + */ + 200: ModelWithString; +}; + +export type ComplexParamsResponse = ComplexParamsResponses[keyof ComplexParamsResponses]; + +export type CallWithResultFromHeaderErrors = { + /** + * 400 server error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type CallWithResultFromHeaderResponses = { + /** + * Successful response + */ + 200: unknown; +}; export type TestErrorCodeData = { body?: never; @@ -1456,6 +1684,32 @@ export type TestErrorCodeData = { }; }; +export type TestErrorCodeErrors = { + /** + * Custom message: Internal Server Error + */ + 500: unknown; + /** + * Custom message: Not Implemented + */ + 501: unknown; + /** + * Custom message: Bad Gateway + */ + 502: unknown; + /** + * Custom message: Service Unavailable + */ + 503: unknown; +}; + +export type TestErrorCodeResponses = { + /** + * Custom message: Successful response + */ + 200: unknown; +}; + export type NonAsciiæøåÆøÅöôêÊ字符串Data = { body?: never; path?: never; @@ -1467,7 +1721,14 @@ export type NonAsciiæøåÆøÅöôêÊ字符串Data = { }; }; -export type NonAsciiæøåÆøÅöôêÊ字符串Response = Array; +export type NonAsciiæøåÆøÅöôêÊ字符串Responses = { + /** + * Successful response + */ + 200: Array; +}; + +export type NonAsciiæøåÆøÅöôêÊ字符串Response = NonAsciiæøåÆøÅöôêÊ字符串Responses[keyof NonAsciiæøåÆøÅöôêÊ字符串Responses]; export type PutWithFormUrlEncodedData = { body: ArrayWithStrings; 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 2f6b56c07..0478efcec 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 @@ -951,9 +951,27 @@ export type ImportData = { body: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; }; -export type ImportResponse = Model_From_Zendesk | ModelWithReadOnlyAndWriteOnly; +export type ImportResponses = { + /** + * Success + */ + 200: Model_From_Zendesk; + /** + * Default success response + */ + default: ModelWithReadOnlyAndWriteOnly; +}; + +export type ImportResponse = ImportResponses[keyof ImportResponses]; + +export type ApiVversionOdataControllerCountResponses = { + /** + * Success + */ + 200: Model_From_Zendesk; +}; -export type ApiVversionOdataControllerCountResponse = Model_From_Zendesk; +export type ApiVversionOdataControllerCountResponse = ApiVversionOdataControllerCountResponses[keyof ApiVversionOdataControllerCountResponses]; export type GetApiVbyApiVersionSimpleOperationData = { body?: never; @@ -966,9 +984,23 @@ export type GetApiVbyApiVersionSimpleOperationData = { query?: never; }; -export type GetApiVbyApiVersionSimpleOperationError = ModelWithBoolean; +export type GetApiVbyApiVersionSimpleOperationErrors = { + /** + * Default error response + */ + default: ModelWithBoolean; +}; -export type GetApiVbyApiVersionSimpleOperationResponse = number; +export type GetApiVbyApiVersionSimpleOperationError = GetApiVbyApiVersionSimpleOperationErrors[keyof GetApiVbyApiVersionSimpleOperationErrors]; + +export type GetApiVbyApiVersionSimpleOperationResponses = { + /** + * Response is a simple number + */ + 200: number; +}; + +export type GetApiVbyApiVersionSimpleOperationResponse = GetApiVbyApiVersionSimpleOperationResponses[keyof GetApiVbyApiVersionSimpleOperationResponses]; export type DeleteFooData3 = { body?: never; @@ -1140,7 +1172,18 @@ export type PostCallWithOptionalParamData = { }; }; -export type PostCallWithOptionalParamResponse = number | void; +export type PostCallWithOptionalParamResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; + +export type PostCallWithOptionalParamResponse = PostCallWithOptionalParamResponses[keyof PostCallWithOptionalParamResponses]; export type PostApiVbyApiVersionRequestBodyData = { /** @@ -1263,27 +1306,132 @@ export type CallToTestOrderOfParamsData = { }; }; -export type CallWithNoContentResponseResponse = void; +export type CallWithNoContentResponseResponses = { + /** + * Success + */ + 204: void; +}; -export type CallWithResponseAndNoContentResponseResponse = number | void; +export type CallWithNoContentResponseResponse = CallWithNoContentResponseResponses[keyof CallWithNoContentResponseResponses]; -export type DummyAResponse = _400; +export type CallWithResponseAndNoContentResponseResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; -export type DummyBResponse = void; +export type CallWithResponseAndNoContentResponseResponse = CallWithResponseAndNoContentResponseResponses[keyof CallWithResponseAndNoContentResponseResponses]; -export type CallWithResponseResponse = _import; +export type DummyAResponses = { + 200: _400; +}; -export type CallWithDuplicateResponsesError = ModelWithStringError | DictionaryWithArray | ModelWithBoolean; +export type DummyAResponse = DummyAResponses[keyof DummyAResponses]; -export type CallWithDuplicateResponsesResponse = (ModelWithBoolean & ModelWithInteger) | ModelWithString; +export type DummyBResponses = { + /** + * Success + */ + 204: void; +}; -export type CallWithResponsesError = ModelWithStringError; +export type DummyBResponse = DummyBResponses[keyof DummyBResponses]; -export type CallWithResponsesResponse = { - readonly '@namespace.string'?: string; - readonly '@namespace.integer'?: number; - readonly value?: Array; -} | ModelThatExtends | ModelThatExtendsExtends; +export type CallWithResponseResponses = { + default: _import; +}; + +export type CallWithResponseResponse = CallWithResponseResponses[keyof CallWithResponseResponses]; + +export type CallWithDuplicateResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for 4XX errors + */ + '4XX': DictionaryWithArray; + /** + * Default error response + */ + default: ModelWithBoolean; +}; + +export type CallWithDuplicateResponsesError = CallWithDuplicateResponsesErrors[keyof CallWithDuplicateResponsesErrors]; + +export type CallWithDuplicateResponsesResponses = { + /** + * Message for 200 response + */ + 200: ModelWithBoolean & ModelWithInteger; + /** + * Message for 201 response + */ + 201: ModelWithString; + /** + * Message for 202 response + */ + 202: ModelWithString; +}; + +export type CallWithDuplicateResponsesResponse = CallWithDuplicateResponsesResponses[keyof CallWithDuplicateResponsesResponses]; + +export type CallWithResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for default response + */ + default: ModelWithStringError; +}; + +export type CallWithResponsesError = CallWithResponsesErrors[keyof CallWithResponsesErrors]; + +export type CallWithResponsesResponses = { + /** + * Message for 200 response + */ + 200: { + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; + readonly value?: Array; + }; + /** + * Message for 201 response + */ + 201: ModelThatExtends; + /** + * Message for 202 response + */ + 202: ModelThatExtendsExtends; +}; + +export type CallWithResponsesResponse = CallWithResponsesResponses[keyof CallWithResponsesResponses]; export type CollectionFormatData = { body?: never; @@ -1352,7 +1500,26 @@ export type TypesData = { }; }; -export type TypesResponse = number | string | boolean | {}; +export type TypesResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Response is a simple string + */ + 201: string; + /** + * Response is a simple boolean + */ + 202: boolean; + /** + * Response is a simple object + */ + 203: {}; +}; + +export type TypesResponse = TypesResponses[keyof TypesResponses]; export type UploadFileData = { body: Blob | File; @@ -1365,7 +1532,11 @@ export type UploadFileData = { query?: never; }; -export type UploadFileResponse = boolean; +export type UploadFileResponses = { + 200: boolean; +}; + +export type UploadFileResponse = UploadFileResponses[keyof UploadFileResponses]; export type FileResponseData = { body?: never; @@ -1379,7 +1550,14 @@ export type FileResponseData = { query?: never; }; -export type FileResponseResponse = Blob | File; +export type FileResponseResponses = { + /** + * Success + */ + 200: Blob | File; +}; + +export type FileResponseResponse = FileResponseResponses[keyof FileResponseResponses]; export type ComplexTypesData = { body?: never; @@ -1402,16 +1580,41 @@ export type ComplexTypesData = { }; }; -export type ComplexTypesResponse = Array; +export type ComplexTypesErrors = { + /** + * 400 `server` error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type ComplexTypesResponses = { + /** + * Successful response + */ + 200: Array; +}; -export type MultipartResponseResponse = { - file?: Blob | File; - metadata?: { - foo?: string; - bar?: string; +export type ComplexTypesResponse = ComplexTypesResponses[keyof ComplexTypesResponses]; + +export type MultipartResponseResponses = { + /** + * OK + */ + 200: { + file?: Blob | File; + metadata?: { + foo?: string; + bar?: string; + }; }; }; +export type MultipartResponseResponse = MultipartResponseResponses[keyof MultipartResponseResponses]; + export type MultipartRequestData = { body?: { content?: Blob | File; @@ -1443,7 +1646,32 @@ export type ComplexParamsData = { query?: never; }; -export type ComplexParamsResponse = ModelWithString; +export type ComplexParamsResponses = { + /** + * Success + */ + 200: ModelWithString; +}; + +export type ComplexParamsResponse = ComplexParamsResponses[keyof ComplexParamsResponses]; + +export type CallWithResultFromHeaderErrors = { + /** + * 400 server error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type CallWithResultFromHeaderResponses = { + /** + * Successful response + */ + 200: unknown; +}; export type TestErrorCodeData = { body?: never; @@ -1456,6 +1684,32 @@ export type TestErrorCodeData = { }; }; +export type TestErrorCodeErrors = { + /** + * Custom message: Internal Server Error + */ + 500: unknown; + /** + * Custom message: Not Implemented + */ + 501: unknown; + /** + * Custom message: Bad Gateway + */ + 502: unknown; + /** + * Custom message: Service Unavailable + */ + 503: unknown; +}; + +export type TestErrorCodeResponses = { + /** + * Custom message: Successful response + */ + 200: unknown; +}; + export type NonAsciiæøåÆøÅöôêÊ字符串Data = { body?: never; path?: never; @@ -1467,7 +1721,14 @@ export type NonAsciiæøåÆøÅöôêÊ字符串Data = { }; }; -export type NonAsciiæøåÆøÅöôêÊ字符串Response = Array; +export type NonAsciiæøåÆøÅöôêÊ字符串Responses = { + /** + * Successful response + */ + 200: Array; +}; + +export type NonAsciiæøåÆøÅöôêÊ字符串Response = NonAsciiæøåÆøÅöôêÊ字符串Responses[keyof NonAsciiæøåÆøÅöôêÊ字符串Responses]; export type PutWithFormUrlEncodedData = { body: ArrayWithStrings; 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 2f6b56c07..0478efcec 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 @@ -951,9 +951,27 @@ export type ImportData = { body: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; }; -export type ImportResponse = Model_From_Zendesk | ModelWithReadOnlyAndWriteOnly; +export type ImportResponses = { + /** + * Success + */ + 200: Model_From_Zendesk; + /** + * Default success response + */ + default: ModelWithReadOnlyAndWriteOnly; +}; + +export type ImportResponse = ImportResponses[keyof ImportResponses]; + +export type ApiVversionOdataControllerCountResponses = { + /** + * Success + */ + 200: Model_From_Zendesk; +}; -export type ApiVversionOdataControllerCountResponse = Model_From_Zendesk; +export type ApiVversionOdataControllerCountResponse = ApiVversionOdataControllerCountResponses[keyof ApiVversionOdataControllerCountResponses]; export type GetApiVbyApiVersionSimpleOperationData = { body?: never; @@ -966,9 +984,23 @@ export type GetApiVbyApiVersionSimpleOperationData = { query?: never; }; -export type GetApiVbyApiVersionSimpleOperationError = ModelWithBoolean; +export type GetApiVbyApiVersionSimpleOperationErrors = { + /** + * Default error response + */ + default: ModelWithBoolean; +}; -export type GetApiVbyApiVersionSimpleOperationResponse = number; +export type GetApiVbyApiVersionSimpleOperationError = GetApiVbyApiVersionSimpleOperationErrors[keyof GetApiVbyApiVersionSimpleOperationErrors]; + +export type GetApiVbyApiVersionSimpleOperationResponses = { + /** + * Response is a simple number + */ + 200: number; +}; + +export type GetApiVbyApiVersionSimpleOperationResponse = GetApiVbyApiVersionSimpleOperationResponses[keyof GetApiVbyApiVersionSimpleOperationResponses]; export type DeleteFooData3 = { body?: never; @@ -1140,7 +1172,18 @@ export type PostCallWithOptionalParamData = { }; }; -export type PostCallWithOptionalParamResponse = number | void; +export type PostCallWithOptionalParamResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; + +export type PostCallWithOptionalParamResponse = PostCallWithOptionalParamResponses[keyof PostCallWithOptionalParamResponses]; export type PostApiVbyApiVersionRequestBodyData = { /** @@ -1263,27 +1306,132 @@ export type CallToTestOrderOfParamsData = { }; }; -export type CallWithNoContentResponseResponse = void; +export type CallWithNoContentResponseResponses = { + /** + * Success + */ + 204: void; +}; -export type CallWithResponseAndNoContentResponseResponse = number | void; +export type CallWithNoContentResponseResponse = CallWithNoContentResponseResponses[keyof CallWithNoContentResponseResponses]; -export type DummyAResponse = _400; +export type CallWithResponseAndNoContentResponseResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; -export type DummyBResponse = void; +export type CallWithResponseAndNoContentResponseResponse = CallWithResponseAndNoContentResponseResponses[keyof CallWithResponseAndNoContentResponseResponses]; -export type CallWithResponseResponse = _import; +export type DummyAResponses = { + 200: _400; +}; -export type CallWithDuplicateResponsesError = ModelWithStringError | DictionaryWithArray | ModelWithBoolean; +export type DummyAResponse = DummyAResponses[keyof DummyAResponses]; -export type CallWithDuplicateResponsesResponse = (ModelWithBoolean & ModelWithInteger) | ModelWithString; +export type DummyBResponses = { + /** + * Success + */ + 204: void; +}; -export type CallWithResponsesError = ModelWithStringError; +export type DummyBResponse = DummyBResponses[keyof DummyBResponses]; -export type CallWithResponsesResponse = { - readonly '@namespace.string'?: string; - readonly '@namespace.integer'?: number; - readonly value?: Array; -} | ModelThatExtends | ModelThatExtendsExtends; +export type CallWithResponseResponses = { + default: _import; +}; + +export type CallWithResponseResponse = CallWithResponseResponses[keyof CallWithResponseResponses]; + +export type CallWithDuplicateResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for 4XX errors + */ + '4XX': DictionaryWithArray; + /** + * Default error response + */ + default: ModelWithBoolean; +}; + +export type CallWithDuplicateResponsesError = CallWithDuplicateResponsesErrors[keyof CallWithDuplicateResponsesErrors]; + +export type CallWithDuplicateResponsesResponses = { + /** + * Message for 200 response + */ + 200: ModelWithBoolean & ModelWithInteger; + /** + * Message for 201 response + */ + 201: ModelWithString; + /** + * Message for 202 response + */ + 202: ModelWithString; +}; + +export type CallWithDuplicateResponsesResponse = CallWithDuplicateResponsesResponses[keyof CallWithDuplicateResponsesResponses]; + +export type CallWithResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for default response + */ + default: ModelWithStringError; +}; + +export type CallWithResponsesError = CallWithResponsesErrors[keyof CallWithResponsesErrors]; + +export type CallWithResponsesResponses = { + /** + * Message for 200 response + */ + 200: { + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; + readonly value?: Array; + }; + /** + * Message for 201 response + */ + 201: ModelThatExtends; + /** + * Message for 202 response + */ + 202: ModelThatExtendsExtends; +}; + +export type CallWithResponsesResponse = CallWithResponsesResponses[keyof CallWithResponsesResponses]; export type CollectionFormatData = { body?: never; @@ -1352,7 +1500,26 @@ export type TypesData = { }; }; -export type TypesResponse = number | string | boolean | {}; +export type TypesResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Response is a simple string + */ + 201: string; + /** + * Response is a simple boolean + */ + 202: boolean; + /** + * Response is a simple object + */ + 203: {}; +}; + +export type TypesResponse = TypesResponses[keyof TypesResponses]; export type UploadFileData = { body: Blob | File; @@ -1365,7 +1532,11 @@ export type UploadFileData = { query?: never; }; -export type UploadFileResponse = boolean; +export type UploadFileResponses = { + 200: boolean; +}; + +export type UploadFileResponse = UploadFileResponses[keyof UploadFileResponses]; export type FileResponseData = { body?: never; @@ -1379,7 +1550,14 @@ export type FileResponseData = { query?: never; }; -export type FileResponseResponse = Blob | File; +export type FileResponseResponses = { + /** + * Success + */ + 200: Blob | File; +}; + +export type FileResponseResponse = FileResponseResponses[keyof FileResponseResponses]; export type ComplexTypesData = { body?: never; @@ -1402,16 +1580,41 @@ export type ComplexTypesData = { }; }; -export type ComplexTypesResponse = Array; +export type ComplexTypesErrors = { + /** + * 400 `server` error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type ComplexTypesResponses = { + /** + * Successful response + */ + 200: Array; +}; -export type MultipartResponseResponse = { - file?: Blob | File; - metadata?: { - foo?: string; - bar?: string; +export type ComplexTypesResponse = ComplexTypesResponses[keyof ComplexTypesResponses]; + +export type MultipartResponseResponses = { + /** + * OK + */ + 200: { + file?: Blob | File; + metadata?: { + foo?: string; + bar?: string; + }; }; }; +export type MultipartResponseResponse = MultipartResponseResponses[keyof MultipartResponseResponses]; + export type MultipartRequestData = { body?: { content?: Blob | File; @@ -1443,7 +1646,32 @@ export type ComplexParamsData = { query?: never; }; -export type ComplexParamsResponse = ModelWithString; +export type ComplexParamsResponses = { + /** + * Success + */ + 200: ModelWithString; +}; + +export type ComplexParamsResponse = ComplexParamsResponses[keyof ComplexParamsResponses]; + +export type CallWithResultFromHeaderErrors = { + /** + * 400 server error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type CallWithResultFromHeaderResponses = { + /** + * Successful response + */ + 200: unknown; +}; export type TestErrorCodeData = { body?: never; @@ -1456,6 +1684,32 @@ export type TestErrorCodeData = { }; }; +export type TestErrorCodeErrors = { + /** + * Custom message: Internal Server Error + */ + 500: unknown; + /** + * Custom message: Not Implemented + */ + 501: unknown; + /** + * Custom message: Bad Gateway + */ + 502: unknown; + /** + * Custom message: Service Unavailable + */ + 503: unknown; +}; + +export type TestErrorCodeResponses = { + /** + * Custom message: Successful response + */ + 200: unknown; +}; + export type NonAsciiæøåÆøÅöôêÊ字符串Data = { body?: never; path?: never; @@ -1467,7 +1721,14 @@ export type NonAsciiæøåÆøÅöôêÊ字符串Data = { }; }; -export type NonAsciiæøåÆøÅöôêÊ字符串Response = Array; +export type NonAsciiæøåÆøÅöôêÊ字符串Responses = { + /** + * Successful response + */ + 200: Array; +}; + +export type NonAsciiæøåÆøÅöôêÊ字符串Response = NonAsciiæøåÆøÅöôêÊ字符串Responses[keyof NonAsciiæøåÆøÅöôêÊ字符串Responses]; export type PutWithFormUrlEncodedData = { body: ArrayWithStrings; 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 2f6b56c07..0478efcec 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 @@ -951,9 +951,27 @@ export type ImportData = { body: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; }; -export type ImportResponse = Model_From_Zendesk | ModelWithReadOnlyAndWriteOnly; +export type ImportResponses = { + /** + * Success + */ + 200: Model_From_Zendesk; + /** + * Default success response + */ + default: ModelWithReadOnlyAndWriteOnly; +}; + +export type ImportResponse = ImportResponses[keyof ImportResponses]; + +export type ApiVversionOdataControllerCountResponses = { + /** + * Success + */ + 200: Model_From_Zendesk; +}; -export type ApiVversionOdataControllerCountResponse = Model_From_Zendesk; +export type ApiVversionOdataControllerCountResponse = ApiVversionOdataControllerCountResponses[keyof ApiVversionOdataControllerCountResponses]; export type GetApiVbyApiVersionSimpleOperationData = { body?: never; @@ -966,9 +984,23 @@ export type GetApiVbyApiVersionSimpleOperationData = { query?: never; }; -export type GetApiVbyApiVersionSimpleOperationError = ModelWithBoolean; +export type GetApiVbyApiVersionSimpleOperationErrors = { + /** + * Default error response + */ + default: ModelWithBoolean; +}; -export type GetApiVbyApiVersionSimpleOperationResponse = number; +export type GetApiVbyApiVersionSimpleOperationError = GetApiVbyApiVersionSimpleOperationErrors[keyof GetApiVbyApiVersionSimpleOperationErrors]; + +export type GetApiVbyApiVersionSimpleOperationResponses = { + /** + * Response is a simple number + */ + 200: number; +}; + +export type GetApiVbyApiVersionSimpleOperationResponse = GetApiVbyApiVersionSimpleOperationResponses[keyof GetApiVbyApiVersionSimpleOperationResponses]; export type DeleteFooData3 = { body?: never; @@ -1140,7 +1172,18 @@ export type PostCallWithOptionalParamData = { }; }; -export type PostCallWithOptionalParamResponse = number | void; +export type PostCallWithOptionalParamResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; + +export type PostCallWithOptionalParamResponse = PostCallWithOptionalParamResponses[keyof PostCallWithOptionalParamResponses]; export type PostApiVbyApiVersionRequestBodyData = { /** @@ -1263,27 +1306,132 @@ export type CallToTestOrderOfParamsData = { }; }; -export type CallWithNoContentResponseResponse = void; +export type CallWithNoContentResponseResponses = { + /** + * Success + */ + 204: void; +}; -export type CallWithResponseAndNoContentResponseResponse = number | void; +export type CallWithNoContentResponseResponse = CallWithNoContentResponseResponses[keyof CallWithNoContentResponseResponses]; -export type DummyAResponse = _400; +export type CallWithResponseAndNoContentResponseResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; -export type DummyBResponse = void; +export type CallWithResponseAndNoContentResponseResponse = CallWithResponseAndNoContentResponseResponses[keyof CallWithResponseAndNoContentResponseResponses]; -export type CallWithResponseResponse = _import; +export type DummyAResponses = { + 200: _400; +}; -export type CallWithDuplicateResponsesError = ModelWithStringError | DictionaryWithArray | ModelWithBoolean; +export type DummyAResponse = DummyAResponses[keyof DummyAResponses]; -export type CallWithDuplicateResponsesResponse = (ModelWithBoolean & ModelWithInteger) | ModelWithString; +export type DummyBResponses = { + /** + * Success + */ + 204: void; +}; -export type CallWithResponsesError = ModelWithStringError; +export type DummyBResponse = DummyBResponses[keyof DummyBResponses]; -export type CallWithResponsesResponse = { - readonly '@namespace.string'?: string; - readonly '@namespace.integer'?: number; - readonly value?: Array; -} | ModelThatExtends | ModelThatExtendsExtends; +export type CallWithResponseResponses = { + default: _import; +}; + +export type CallWithResponseResponse = CallWithResponseResponses[keyof CallWithResponseResponses]; + +export type CallWithDuplicateResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for 4XX errors + */ + '4XX': DictionaryWithArray; + /** + * Default error response + */ + default: ModelWithBoolean; +}; + +export type CallWithDuplicateResponsesError = CallWithDuplicateResponsesErrors[keyof CallWithDuplicateResponsesErrors]; + +export type CallWithDuplicateResponsesResponses = { + /** + * Message for 200 response + */ + 200: ModelWithBoolean & ModelWithInteger; + /** + * Message for 201 response + */ + 201: ModelWithString; + /** + * Message for 202 response + */ + 202: ModelWithString; +}; + +export type CallWithDuplicateResponsesResponse = CallWithDuplicateResponsesResponses[keyof CallWithDuplicateResponsesResponses]; + +export type CallWithResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for default response + */ + default: ModelWithStringError; +}; + +export type CallWithResponsesError = CallWithResponsesErrors[keyof CallWithResponsesErrors]; + +export type CallWithResponsesResponses = { + /** + * Message for 200 response + */ + 200: { + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; + readonly value?: Array; + }; + /** + * Message for 201 response + */ + 201: ModelThatExtends; + /** + * Message for 202 response + */ + 202: ModelThatExtendsExtends; +}; + +export type CallWithResponsesResponse = CallWithResponsesResponses[keyof CallWithResponsesResponses]; export type CollectionFormatData = { body?: never; @@ -1352,7 +1500,26 @@ export type TypesData = { }; }; -export type TypesResponse = number | string | boolean | {}; +export type TypesResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Response is a simple string + */ + 201: string; + /** + * Response is a simple boolean + */ + 202: boolean; + /** + * Response is a simple object + */ + 203: {}; +}; + +export type TypesResponse = TypesResponses[keyof TypesResponses]; export type UploadFileData = { body: Blob | File; @@ -1365,7 +1532,11 @@ export type UploadFileData = { query?: never; }; -export type UploadFileResponse = boolean; +export type UploadFileResponses = { + 200: boolean; +}; + +export type UploadFileResponse = UploadFileResponses[keyof UploadFileResponses]; export type FileResponseData = { body?: never; @@ -1379,7 +1550,14 @@ export type FileResponseData = { query?: never; }; -export type FileResponseResponse = Blob | File; +export type FileResponseResponses = { + /** + * Success + */ + 200: Blob | File; +}; + +export type FileResponseResponse = FileResponseResponses[keyof FileResponseResponses]; export type ComplexTypesData = { body?: never; @@ -1402,16 +1580,41 @@ export type ComplexTypesData = { }; }; -export type ComplexTypesResponse = Array; +export type ComplexTypesErrors = { + /** + * 400 `server` error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type ComplexTypesResponses = { + /** + * Successful response + */ + 200: Array; +}; -export type MultipartResponseResponse = { - file?: Blob | File; - metadata?: { - foo?: string; - bar?: string; +export type ComplexTypesResponse = ComplexTypesResponses[keyof ComplexTypesResponses]; + +export type MultipartResponseResponses = { + /** + * OK + */ + 200: { + file?: Blob | File; + metadata?: { + foo?: string; + bar?: string; + }; }; }; +export type MultipartResponseResponse = MultipartResponseResponses[keyof MultipartResponseResponses]; + export type MultipartRequestData = { body?: { content?: Blob | File; @@ -1443,7 +1646,32 @@ export type ComplexParamsData = { query?: never; }; -export type ComplexParamsResponse = ModelWithString; +export type ComplexParamsResponses = { + /** + * Success + */ + 200: ModelWithString; +}; + +export type ComplexParamsResponse = ComplexParamsResponses[keyof ComplexParamsResponses]; + +export type CallWithResultFromHeaderErrors = { + /** + * 400 server error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type CallWithResultFromHeaderResponses = { + /** + * Successful response + */ + 200: unknown; +}; export type TestErrorCodeData = { body?: never; @@ -1456,6 +1684,32 @@ export type TestErrorCodeData = { }; }; +export type TestErrorCodeErrors = { + /** + * Custom message: Internal Server Error + */ + 500: unknown; + /** + * Custom message: Not Implemented + */ + 501: unknown; + /** + * Custom message: Bad Gateway + */ + 502: unknown; + /** + * Custom message: Service Unavailable + */ + 503: unknown; +}; + +export type TestErrorCodeResponses = { + /** + * Custom message: Successful response + */ + 200: unknown; +}; + export type NonAsciiæøåÆøÅöôêÊ字符串Data = { body?: never; path?: never; @@ -1467,7 +1721,14 @@ export type NonAsciiæøåÆøÅöôêÊ字符串Data = { }; }; -export type NonAsciiæøåÆøÅöôêÊ字符串Response = Array; +export type NonAsciiæøåÆøÅöôêÊ字符串Responses = { + /** + * Successful response + */ + 200: Array; +}; + +export type NonAsciiæøåÆøÅöôêÊ字符串Response = NonAsciiæøåÆøÅöôêÊ字符串Responses[keyof NonAsciiæøåÆøÅöôêÊ字符串Responses]; export type PutWithFormUrlEncodedData = { body: ArrayWithStrings; 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 2f6b56c07..0478efcec 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 @@ -951,9 +951,27 @@ export type ImportData = { body: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; }; -export type ImportResponse = Model_From_Zendesk | ModelWithReadOnlyAndWriteOnly; +export type ImportResponses = { + /** + * Success + */ + 200: Model_From_Zendesk; + /** + * Default success response + */ + default: ModelWithReadOnlyAndWriteOnly; +}; + +export type ImportResponse = ImportResponses[keyof ImportResponses]; + +export type ApiVversionOdataControllerCountResponses = { + /** + * Success + */ + 200: Model_From_Zendesk; +}; -export type ApiVversionOdataControllerCountResponse = Model_From_Zendesk; +export type ApiVversionOdataControllerCountResponse = ApiVversionOdataControllerCountResponses[keyof ApiVversionOdataControllerCountResponses]; export type GetApiVbyApiVersionSimpleOperationData = { body?: never; @@ -966,9 +984,23 @@ export type GetApiVbyApiVersionSimpleOperationData = { query?: never; }; -export type GetApiVbyApiVersionSimpleOperationError = ModelWithBoolean; +export type GetApiVbyApiVersionSimpleOperationErrors = { + /** + * Default error response + */ + default: ModelWithBoolean; +}; -export type GetApiVbyApiVersionSimpleOperationResponse = number; +export type GetApiVbyApiVersionSimpleOperationError = GetApiVbyApiVersionSimpleOperationErrors[keyof GetApiVbyApiVersionSimpleOperationErrors]; + +export type GetApiVbyApiVersionSimpleOperationResponses = { + /** + * Response is a simple number + */ + 200: number; +}; + +export type GetApiVbyApiVersionSimpleOperationResponse = GetApiVbyApiVersionSimpleOperationResponses[keyof GetApiVbyApiVersionSimpleOperationResponses]; export type DeleteFooData3 = { body?: never; @@ -1140,7 +1172,18 @@ export type PostCallWithOptionalParamData = { }; }; -export type PostCallWithOptionalParamResponse = number | void; +export type PostCallWithOptionalParamResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; + +export type PostCallWithOptionalParamResponse = PostCallWithOptionalParamResponses[keyof PostCallWithOptionalParamResponses]; export type PostApiVbyApiVersionRequestBodyData = { /** @@ -1263,27 +1306,132 @@ export type CallToTestOrderOfParamsData = { }; }; -export type CallWithNoContentResponseResponse = void; +export type CallWithNoContentResponseResponses = { + /** + * Success + */ + 204: void; +}; -export type CallWithResponseAndNoContentResponseResponse = number | void; +export type CallWithNoContentResponseResponse = CallWithNoContentResponseResponses[keyof CallWithNoContentResponseResponses]; -export type DummyAResponse = _400; +export type CallWithResponseAndNoContentResponseResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; -export type DummyBResponse = void; +export type CallWithResponseAndNoContentResponseResponse = CallWithResponseAndNoContentResponseResponses[keyof CallWithResponseAndNoContentResponseResponses]; -export type CallWithResponseResponse = _import; +export type DummyAResponses = { + 200: _400; +}; -export type CallWithDuplicateResponsesError = ModelWithStringError | DictionaryWithArray | ModelWithBoolean; +export type DummyAResponse = DummyAResponses[keyof DummyAResponses]; -export type CallWithDuplicateResponsesResponse = (ModelWithBoolean & ModelWithInteger) | ModelWithString; +export type DummyBResponses = { + /** + * Success + */ + 204: void; +}; -export type CallWithResponsesError = ModelWithStringError; +export type DummyBResponse = DummyBResponses[keyof DummyBResponses]; -export type CallWithResponsesResponse = { - readonly '@namespace.string'?: string; - readonly '@namespace.integer'?: number; - readonly value?: Array; -} | ModelThatExtends | ModelThatExtendsExtends; +export type CallWithResponseResponses = { + default: _import; +}; + +export type CallWithResponseResponse = CallWithResponseResponses[keyof CallWithResponseResponses]; + +export type CallWithDuplicateResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for 4XX errors + */ + '4XX': DictionaryWithArray; + /** + * Default error response + */ + default: ModelWithBoolean; +}; + +export type CallWithDuplicateResponsesError = CallWithDuplicateResponsesErrors[keyof CallWithDuplicateResponsesErrors]; + +export type CallWithDuplicateResponsesResponses = { + /** + * Message for 200 response + */ + 200: ModelWithBoolean & ModelWithInteger; + /** + * Message for 201 response + */ + 201: ModelWithString; + /** + * Message for 202 response + */ + 202: ModelWithString; +}; + +export type CallWithDuplicateResponsesResponse = CallWithDuplicateResponsesResponses[keyof CallWithDuplicateResponsesResponses]; + +export type CallWithResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for default response + */ + default: ModelWithStringError; +}; + +export type CallWithResponsesError = CallWithResponsesErrors[keyof CallWithResponsesErrors]; + +export type CallWithResponsesResponses = { + /** + * Message for 200 response + */ + 200: { + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; + readonly value?: Array; + }; + /** + * Message for 201 response + */ + 201: ModelThatExtends; + /** + * Message for 202 response + */ + 202: ModelThatExtendsExtends; +}; + +export type CallWithResponsesResponse = CallWithResponsesResponses[keyof CallWithResponsesResponses]; export type CollectionFormatData = { body?: never; @@ -1352,7 +1500,26 @@ export type TypesData = { }; }; -export type TypesResponse = number | string | boolean | {}; +export type TypesResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Response is a simple string + */ + 201: string; + /** + * Response is a simple boolean + */ + 202: boolean; + /** + * Response is a simple object + */ + 203: {}; +}; + +export type TypesResponse = TypesResponses[keyof TypesResponses]; export type UploadFileData = { body: Blob | File; @@ -1365,7 +1532,11 @@ export type UploadFileData = { query?: never; }; -export type UploadFileResponse = boolean; +export type UploadFileResponses = { + 200: boolean; +}; + +export type UploadFileResponse = UploadFileResponses[keyof UploadFileResponses]; export type FileResponseData = { body?: never; @@ -1379,7 +1550,14 @@ export type FileResponseData = { query?: never; }; -export type FileResponseResponse = Blob | File; +export type FileResponseResponses = { + /** + * Success + */ + 200: Blob | File; +}; + +export type FileResponseResponse = FileResponseResponses[keyof FileResponseResponses]; export type ComplexTypesData = { body?: never; @@ -1402,16 +1580,41 @@ export type ComplexTypesData = { }; }; -export type ComplexTypesResponse = Array; +export type ComplexTypesErrors = { + /** + * 400 `server` error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type ComplexTypesResponses = { + /** + * Successful response + */ + 200: Array; +}; -export type MultipartResponseResponse = { - file?: Blob | File; - metadata?: { - foo?: string; - bar?: string; +export type ComplexTypesResponse = ComplexTypesResponses[keyof ComplexTypesResponses]; + +export type MultipartResponseResponses = { + /** + * OK + */ + 200: { + file?: Blob | File; + metadata?: { + foo?: string; + bar?: string; + }; }; }; +export type MultipartResponseResponse = MultipartResponseResponses[keyof MultipartResponseResponses]; + export type MultipartRequestData = { body?: { content?: Blob | File; @@ -1443,7 +1646,32 @@ export type ComplexParamsData = { query?: never; }; -export type ComplexParamsResponse = ModelWithString; +export type ComplexParamsResponses = { + /** + * Success + */ + 200: ModelWithString; +}; + +export type ComplexParamsResponse = ComplexParamsResponses[keyof ComplexParamsResponses]; + +export type CallWithResultFromHeaderErrors = { + /** + * 400 server error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type CallWithResultFromHeaderResponses = { + /** + * Successful response + */ + 200: unknown; +}; export type TestErrorCodeData = { body?: never; @@ -1456,6 +1684,32 @@ export type TestErrorCodeData = { }; }; +export type TestErrorCodeErrors = { + /** + * Custom message: Internal Server Error + */ + 500: unknown; + /** + * Custom message: Not Implemented + */ + 501: unknown; + /** + * Custom message: Bad Gateway + */ + 502: unknown; + /** + * Custom message: Service Unavailable + */ + 503: unknown; +}; + +export type TestErrorCodeResponses = { + /** + * Custom message: Successful response + */ + 200: unknown; +}; + export type NonAsciiæøåÆøÅöôêÊ字符串Data = { body?: never; path?: never; @@ -1467,7 +1721,14 @@ export type NonAsciiæøåÆøÅöôêÊ字符串Data = { }; }; -export type NonAsciiæøåÆøÅöôêÊ字符串Response = Array; +export type NonAsciiæøåÆøÅöôêÊ字符串Responses = { + /** + * Successful response + */ + 200: Array; +}; + +export type NonAsciiæøåÆøÅöôêÊ字符串Response = NonAsciiæøåÆøÅöôêÊ字符串Responses[keyof NonAsciiæøåÆøÅöôêÊ字符串Responses]; export type PutWithFormUrlEncodedData = { body: ArrayWithStrings; 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 2f6b56c07..0478efcec 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 @@ -951,9 +951,27 @@ export type ImportData = { body: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; }; -export type ImportResponse = Model_From_Zendesk | ModelWithReadOnlyAndWriteOnly; +export type ImportResponses = { + /** + * Success + */ + 200: Model_From_Zendesk; + /** + * Default success response + */ + default: ModelWithReadOnlyAndWriteOnly; +}; + +export type ImportResponse = ImportResponses[keyof ImportResponses]; + +export type ApiVversionOdataControllerCountResponses = { + /** + * Success + */ + 200: Model_From_Zendesk; +}; -export type ApiVversionOdataControllerCountResponse = Model_From_Zendesk; +export type ApiVversionOdataControllerCountResponse = ApiVversionOdataControllerCountResponses[keyof ApiVversionOdataControllerCountResponses]; export type GetApiVbyApiVersionSimpleOperationData = { body?: never; @@ -966,9 +984,23 @@ export type GetApiVbyApiVersionSimpleOperationData = { query?: never; }; -export type GetApiVbyApiVersionSimpleOperationError = ModelWithBoolean; +export type GetApiVbyApiVersionSimpleOperationErrors = { + /** + * Default error response + */ + default: ModelWithBoolean; +}; -export type GetApiVbyApiVersionSimpleOperationResponse = number; +export type GetApiVbyApiVersionSimpleOperationError = GetApiVbyApiVersionSimpleOperationErrors[keyof GetApiVbyApiVersionSimpleOperationErrors]; + +export type GetApiVbyApiVersionSimpleOperationResponses = { + /** + * Response is a simple number + */ + 200: number; +}; + +export type GetApiVbyApiVersionSimpleOperationResponse = GetApiVbyApiVersionSimpleOperationResponses[keyof GetApiVbyApiVersionSimpleOperationResponses]; export type DeleteFooData3 = { body?: never; @@ -1140,7 +1172,18 @@ export type PostCallWithOptionalParamData = { }; }; -export type PostCallWithOptionalParamResponse = number | void; +export type PostCallWithOptionalParamResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; + +export type PostCallWithOptionalParamResponse = PostCallWithOptionalParamResponses[keyof PostCallWithOptionalParamResponses]; export type PostApiVbyApiVersionRequestBodyData = { /** @@ -1263,27 +1306,132 @@ export type CallToTestOrderOfParamsData = { }; }; -export type CallWithNoContentResponseResponse = void; +export type CallWithNoContentResponseResponses = { + /** + * Success + */ + 204: void; +}; -export type CallWithResponseAndNoContentResponseResponse = number | void; +export type CallWithNoContentResponseResponse = CallWithNoContentResponseResponses[keyof CallWithNoContentResponseResponses]; -export type DummyAResponse = _400; +export type CallWithResponseAndNoContentResponseResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; -export type DummyBResponse = void; +export type CallWithResponseAndNoContentResponseResponse = CallWithResponseAndNoContentResponseResponses[keyof CallWithResponseAndNoContentResponseResponses]; -export type CallWithResponseResponse = _import; +export type DummyAResponses = { + 200: _400; +}; -export type CallWithDuplicateResponsesError = ModelWithStringError | DictionaryWithArray | ModelWithBoolean; +export type DummyAResponse = DummyAResponses[keyof DummyAResponses]; -export type CallWithDuplicateResponsesResponse = (ModelWithBoolean & ModelWithInteger) | ModelWithString; +export type DummyBResponses = { + /** + * Success + */ + 204: void; +}; -export type CallWithResponsesError = ModelWithStringError; +export type DummyBResponse = DummyBResponses[keyof DummyBResponses]; -export type CallWithResponsesResponse = { - readonly '@namespace.string'?: string; - readonly '@namespace.integer'?: number; - readonly value?: Array; -} | ModelThatExtends | ModelThatExtendsExtends; +export type CallWithResponseResponses = { + default: _import; +}; + +export type CallWithResponseResponse = CallWithResponseResponses[keyof CallWithResponseResponses]; + +export type CallWithDuplicateResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for 4XX errors + */ + '4XX': DictionaryWithArray; + /** + * Default error response + */ + default: ModelWithBoolean; +}; + +export type CallWithDuplicateResponsesError = CallWithDuplicateResponsesErrors[keyof CallWithDuplicateResponsesErrors]; + +export type CallWithDuplicateResponsesResponses = { + /** + * Message for 200 response + */ + 200: ModelWithBoolean & ModelWithInteger; + /** + * Message for 201 response + */ + 201: ModelWithString; + /** + * Message for 202 response + */ + 202: ModelWithString; +}; + +export type CallWithDuplicateResponsesResponse = CallWithDuplicateResponsesResponses[keyof CallWithDuplicateResponsesResponses]; + +export type CallWithResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for default response + */ + default: ModelWithStringError; +}; + +export type CallWithResponsesError = CallWithResponsesErrors[keyof CallWithResponsesErrors]; + +export type CallWithResponsesResponses = { + /** + * Message for 200 response + */ + 200: { + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; + readonly value?: Array; + }; + /** + * Message for 201 response + */ + 201: ModelThatExtends; + /** + * Message for 202 response + */ + 202: ModelThatExtendsExtends; +}; + +export type CallWithResponsesResponse = CallWithResponsesResponses[keyof CallWithResponsesResponses]; export type CollectionFormatData = { body?: never; @@ -1352,7 +1500,26 @@ export type TypesData = { }; }; -export type TypesResponse = number | string | boolean | {}; +export type TypesResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Response is a simple string + */ + 201: string; + /** + * Response is a simple boolean + */ + 202: boolean; + /** + * Response is a simple object + */ + 203: {}; +}; + +export type TypesResponse = TypesResponses[keyof TypesResponses]; export type UploadFileData = { body: Blob | File; @@ -1365,7 +1532,11 @@ export type UploadFileData = { query?: never; }; -export type UploadFileResponse = boolean; +export type UploadFileResponses = { + 200: boolean; +}; + +export type UploadFileResponse = UploadFileResponses[keyof UploadFileResponses]; export type FileResponseData = { body?: never; @@ -1379,7 +1550,14 @@ export type FileResponseData = { query?: never; }; -export type FileResponseResponse = Blob | File; +export type FileResponseResponses = { + /** + * Success + */ + 200: Blob | File; +}; + +export type FileResponseResponse = FileResponseResponses[keyof FileResponseResponses]; export type ComplexTypesData = { body?: never; @@ -1402,16 +1580,41 @@ export type ComplexTypesData = { }; }; -export type ComplexTypesResponse = Array; +export type ComplexTypesErrors = { + /** + * 400 `server` error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type ComplexTypesResponses = { + /** + * Successful response + */ + 200: Array; +}; -export type MultipartResponseResponse = { - file?: Blob | File; - metadata?: { - foo?: string; - bar?: string; +export type ComplexTypesResponse = ComplexTypesResponses[keyof ComplexTypesResponses]; + +export type MultipartResponseResponses = { + /** + * OK + */ + 200: { + file?: Blob | File; + metadata?: { + foo?: string; + bar?: string; + }; }; }; +export type MultipartResponseResponse = MultipartResponseResponses[keyof MultipartResponseResponses]; + export type MultipartRequestData = { body?: { content?: Blob | File; @@ -1443,7 +1646,32 @@ export type ComplexParamsData = { query?: never; }; -export type ComplexParamsResponse = ModelWithString; +export type ComplexParamsResponses = { + /** + * Success + */ + 200: ModelWithString; +}; + +export type ComplexParamsResponse = ComplexParamsResponses[keyof ComplexParamsResponses]; + +export type CallWithResultFromHeaderErrors = { + /** + * 400 server error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type CallWithResultFromHeaderResponses = { + /** + * Successful response + */ + 200: unknown; +}; export type TestErrorCodeData = { body?: never; @@ -1456,6 +1684,32 @@ export type TestErrorCodeData = { }; }; +export type TestErrorCodeErrors = { + /** + * Custom message: Internal Server Error + */ + 500: unknown; + /** + * Custom message: Not Implemented + */ + 501: unknown; + /** + * Custom message: Bad Gateway + */ + 502: unknown; + /** + * Custom message: Service Unavailable + */ + 503: unknown; +}; + +export type TestErrorCodeResponses = { + /** + * Custom message: Successful response + */ + 200: unknown; +}; + export type NonAsciiæøåÆøÅöôêÊ字符串Data = { body?: never; path?: never; @@ -1467,7 +1721,14 @@ export type NonAsciiæøåÆøÅöôêÊ字符串Data = { }; }; -export type NonAsciiæøåÆøÅöôêÊ字符串Response = Array; +export type NonAsciiæøåÆøÅöôêÊ字符串Responses = { + /** + * Successful response + */ + 200: Array; +}; + +export type NonAsciiæøåÆøÅöôêÊ字符串Response = NonAsciiæøåÆøÅöôêÊ字符串Responses[keyof NonAsciiæøåÆøÅöôêÊ字符串Responses]; export type PutWithFormUrlEncodedData = { body: ArrayWithStrings; 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 2f6b56c07..0478efcec 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 @@ -951,9 +951,27 @@ export type ImportData = { body: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; }; -export type ImportResponse = Model_From_Zendesk | ModelWithReadOnlyAndWriteOnly; +export type ImportResponses = { + /** + * Success + */ + 200: Model_From_Zendesk; + /** + * Default success response + */ + default: ModelWithReadOnlyAndWriteOnly; +}; + +export type ImportResponse = ImportResponses[keyof ImportResponses]; + +export type ApiVversionOdataControllerCountResponses = { + /** + * Success + */ + 200: Model_From_Zendesk; +}; -export type ApiVversionOdataControllerCountResponse = Model_From_Zendesk; +export type ApiVversionOdataControllerCountResponse = ApiVversionOdataControllerCountResponses[keyof ApiVversionOdataControllerCountResponses]; export type GetApiVbyApiVersionSimpleOperationData = { body?: never; @@ -966,9 +984,23 @@ export type GetApiVbyApiVersionSimpleOperationData = { query?: never; }; -export type GetApiVbyApiVersionSimpleOperationError = ModelWithBoolean; +export type GetApiVbyApiVersionSimpleOperationErrors = { + /** + * Default error response + */ + default: ModelWithBoolean; +}; -export type GetApiVbyApiVersionSimpleOperationResponse = number; +export type GetApiVbyApiVersionSimpleOperationError = GetApiVbyApiVersionSimpleOperationErrors[keyof GetApiVbyApiVersionSimpleOperationErrors]; + +export type GetApiVbyApiVersionSimpleOperationResponses = { + /** + * Response is a simple number + */ + 200: number; +}; + +export type GetApiVbyApiVersionSimpleOperationResponse = GetApiVbyApiVersionSimpleOperationResponses[keyof GetApiVbyApiVersionSimpleOperationResponses]; export type DeleteFooData3 = { body?: never; @@ -1140,7 +1172,18 @@ export type PostCallWithOptionalParamData = { }; }; -export type PostCallWithOptionalParamResponse = number | void; +export type PostCallWithOptionalParamResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; + +export type PostCallWithOptionalParamResponse = PostCallWithOptionalParamResponses[keyof PostCallWithOptionalParamResponses]; export type PostApiVbyApiVersionRequestBodyData = { /** @@ -1263,27 +1306,132 @@ export type CallToTestOrderOfParamsData = { }; }; -export type CallWithNoContentResponseResponse = void; +export type CallWithNoContentResponseResponses = { + /** + * Success + */ + 204: void; +}; -export type CallWithResponseAndNoContentResponseResponse = number | void; +export type CallWithNoContentResponseResponse = CallWithNoContentResponseResponses[keyof CallWithNoContentResponseResponses]; -export type DummyAResponse = _400; +export type CallWithResponseAndNoContentResponseResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; -export type DummyBResponse = void; +export type CallWithResponseAndNoContentResponseResponse = CallWithResponseAndNoContentResponseResponses[keyof CallWithResponseAndNoContentResponseResponses]; -export type CallWithResponseResponse = _import; +export type DummyAResponses = { + 200: _400; +}; -export type CallWithDuplicateResponsesError = ModelWithStringError | DictionaryWithArray | ModelWithBoolean; +export type DummyAResponse = DummyAResponses[keyof DummyAResponses]; -export type CallWithDuplicateResponsesResponse = (ModelWithBoolean & ModelWithInteger) | ModelWithString; +export type DummyBResponses = { + /** + * Success + */ + 204: void; +}; -export type CallWithResponsesError = ModelWithStringError; +export type DummyBResponse = DummyBResponses[keyof DummyBResponses]; -export type CallWithResponsesResponse = { - readonly '@namespace.string'?: string; - readonly '@namespace.integer'?: number; - readonly value?: Array; -} | ModelThatExtends | ModelThatExtendsExtends; +export type CallWithResponseResponses = { + default: _import; +}; + +export type CallWithResponseResponse = CallWithResponseResponses[keyof CallWithResponseResponses]; + +export type CallWithDuplicateResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for 4XX errors + */ + '4XX': DictionaryWithArray; + /** + * Default error response + */ + default: ModelWithBoolean; +}; + +export type CallWithDuplicateResponsesError = CallWithDuplicateResponsesErrors[keyof CallWithDuplicateResponsesErrors]; + +export type CallWithDuplicateResponsesResponses = { + /** + * Message for 200 response + */ + 200: ModelWithBoolean & ModelWithInteger; + /** + * Message for 201 response + */ + 201: ModelWithString; + /** + * Message for 202 response + */ + 202: ModelWithString; +}; + +export type CallWithDuplicateResponsesResponse = CallWithDuplicateResponsesResponses[keyof CallWithDuplicateResponsesResponses]; + +export type CallWithResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for default response + */ + default: ModelWithStringError; +}; + +export type CallWithResponsesError = CallWithResponsesErrors[keyof CallWithResponsesErrors]; + +export type CallWithResponsesResponses = { + /** + * Message for 200 response + */ + 200: { + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; + readonly value?: Array; + }; + /** + * Message for 201 response + */ + 201: ModelThatExtends; + /** + * Message for 202 response + */ + 202: ModelThatExtendsExtends; +}; + +export type CallWithResponsesResponse = CallWithResponsesResponses[keyof CallWithResponsesResponses]; export type CollectionFormatData = { body?: never; @@ -1352,7 +1500,26 @@ export type TypesData = { }; }; -export type TypesResponse = number | string | boolean | {}; +export type TypesResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Response is a simple string + */ + 201: string; + /** + * Response is a simple boolean + */ + 202: boolean; + /** + * Response is a simple object + */ + 203: {}; +}; + +export type TypesResponse = TypesResponses[keyof TypesResponses]; export type UploadFileData = { body: Blob | File; @@ -1365,7 +1532,11 @@ export type UploadFileData = { query?: never; }; -export type UploadFileResponse = boolean; +export type UploadFileResponses = { + 200: boolean; +}; + +export type UploadFileResponse = UploadFileResponses[keyof UploadFileResponses]; export type FileResponseData = { body?: never; @@ -1379,7 +1550,14 @@ export type FileResponseData = { query?: never; }; -export type FileResponseResponse = Blob | File; +export type FileResponseResponses = { + /** + * Success + */ + 200: Blob | File; +}; + +export type FileResponseResponse = FileResponseResponses[keyof FileResponseResponses]; export type ComplexTypesData = { body?: never; @@ -1402,16 +1580,41 @@ export type ComplexTypesData = { }; }; -export type ComplexTypesResponse = Array; +export type ComplexTypesErrors = { + /** + * 400 `server` error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type ComplexTypesResponses = { + /** + * Successful response + */ + 200: Array; +}; -export type MultipartResponseResponse = { - file?: Blob | File; - metadata?: { - foo?: string; - bar?: string; +export type ComplexTypesResponse = ComplexTypesResponses[keyof ComplexTypesResponses]; + +export type MultipartResponseResponses = { + /** + * OK + */ + 200: { + file?: Blob | File; + metadata?: { + foo?: string; + bar?: string; + }; }; }; +export type MultipartResponseResponse = MultipartResponseResponses[keyof MultipartResponseResponses]; + export type MultipartRequestData = { body?: { content?: Blob | File; @@ -1443,7 +1646,32 @@ export type ComplexParamsData = { query?: never; }; -export type ComplexParamsResponse = ModelWithString; +export type ComplexParamsResponses = { + /** + * Success + */ + 200: ModelWithString; +}; + +export type ComplexParamsResponse = ComplexParamsResponses[keyof ComplexParamsResponses]; + +export type CallWithResultFromHeaderErrors = { + /** + * 400 server error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type CallWithResultFromHeaderResponses = { + /** + * Successful response + */ + 200: unknown; +}; export type TestErrorCodeData = { body?: never; @@ -1456,6 +1684,32 @@ export type TestErrorCodeData = { }; }; +export type TestErrorCodeErrors = { + /** + * Custom message: Internal Server Error + */ + 500: unknown; + /** + * Custom message: Not Implemented + */ + 501: unknown; + /** + * Custom message: Bad Gateway + */ + 502: unknown; + /** + * Custom message: Service Unavailable + */ + 503: unknown; +}; + +export type TestErrorCodeResponses = { + /** + * Custom message: Successful response + */ + 200: unknown; +}; + export type NonAsciiæøåÆøÅöôêÊ字符串Data = { body?: never; path?: never; @@ -1467,7 +1721,14 @@ export type NonAsciiæøåÆøÅöôêÊ字符串Data = { }; }; -export type NonAsciiæøåÆøÅöôêÊ字符串Response = Array; +export type NonAsciiæøåÆøÅöôêÊ字符串Responses = { + /** + * Successful response + */ + 200: Array; +}; + +export type NonAsciiæøåÆøÅöôêÊ字符串Response = NonAsciiæøåÆøÅöôêÊ字符串Responses[keyof NonAsciiæøåÆøÅöôêÊ字符串Responses]; export type PutWithFormUrlEncodedData = { body: ArrayWithStrings; 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 2f6b56c07..0478efcec 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 @@ -951,9 +951,27 @@ export type ImportData = { body: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; }; -export type ImportResponse = Model_From_Zendesk | ModelWithReadOnlyAndWriteOnly; +export type ImportResponses = { + /** + * Success + */ + 200: Model_From_Zendesk; + /** + * Default success response + */ + default: ModelWithReadOnlyAndWriteOnly; +}; + +export type ImportResponse = ImportResponses[keyof ImportResponses]; + +export type ApiVversionOdataControllerCountResponses = { + /** + * Success + */ + 200: Model_From_Zendesk; +}; -export type ApiVversionOdataControllerCountResponse = Model_From_Zendesk; +export type ApiVversionOdataControllerCountResponse = ApiVversionOdataControllerCountResponses[keyof ApiVversionOdataControllerCountResponses]; export type GetApiVbyApiVersionSimpleOperationData = { body?: never; @@ -966,9 +984,23 @@ export type GetApiVbyApiVersionSimpleOperationData = { query?: never; }; -export type GetApiVbyApiVersionSimpleOperationError = ModelWithBoolean; +export type GetApiVbyApiVersionSimpleOperationErrors = { + /** + * Default error response + */ + default: ModelWithBoolean; +}; -export type GetApiVbyApiVersionSimpleOperationResponse = number; +export type GetApiVbyApiVersionSimpleOperationError = GetApiVbyApiVersionSimpleOperationErrors[keyof GetApiVbyApiVersionSimpleOperationErrors]; + +export type GetApiVbyApiVersionSimpleOperationResponses = { + /** + * Response is a simple number + */ + 200: number; +}; + +export type GetApiVbyApiVersionSimpleOperationResponse = GetApiVbyApiVersionSimpleOperationResponses[keyof GetApiVbyApiVersionSimpleOperationResponses]; export type DeleteFooData3 = { body?: never; @@ -1140,7 +1172,18 @@ export type PostCallWithOptionalParamData = { }; }; -export type PostCallWithOptionalParamResponse = number | void; +export type PostCallWithOptionalParamResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; + +export type PostCallWithOptionalParamResponse = PostCallWithOptionalParamResponses[keyof PostCallWithOptionalParamResponses]; export type PostApiVbyApiVersionRequestBodyData = { /** @@ -1263,27 +1306,132 @@ export type CallToTestOrderOfParamsData = { }; }; -export type CallWithNoContentResponseResponse = void; +export type CallWithNoContentResponseResponses = { + /** + * Success + */ + 204: void; +}; -export type CallWithResponseAndNoContentResponseResponse = number | void; +export type CallWithNoContentResponseResponse = CallWithNoContentResponseResponses[keyof CallWithNoContentResponseResponses]; -export type DummyAResponse = _400; +export type CallWithResponseAndNoContentResponseResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; -export type DummyBResponse = void; +export type CallWithResponseAndNoContentResponseResponse = CallWithResponseAndNoContentResponseResponses[keyof CallWithResponseAndNoContentResponseResponses]; -export type CallWithResponseResponse = _import; +export type DummyAResponses = { + 200: _400; +}; -export type CallWithDuplicateResponsesError = ModelWithStringError | DictionaryWithArray | ModelWithBoolean; +export type DummyAResponse = DummyAResponses[keyof DummyAResponses]; -export type CallWithDuplicateResponsesResponse = (ModelWithBoolean & ModelWithInteger) | ModelWithString; +export type DummyBResponses = { + /** + * Success + */ + 204: void; +}; -export type CallWithResponsesError = ModelWithStringError; +export type DummyBResponse = DummyBResponses[keyof DummyBResponses]; -export type CallWithResponsesResponse = { - readonly '@namespace.string'?: string; - readonly '@namespace.integer'?: number; - readonly value?: Array; -} | ModelThatExtends | ModelThatExtendsExtends; +export type CallWithResponseResponses = { + default: _import; +}; + +export type CallWithResponseResponse = CallWithResponseResponses[keyof CallWithResponseResponses]; + +export type CallWithDuplicateResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for 4XX errors + */ + '4XX': DictionaryWithArray; + /** + * Default error response + */ + default: ModelWithBoolean; +}; + +export type CallWithDuplicateResponsesError = CallWithDuplicateResponsesErrors[keyof CallWithDuplicateResponsesErrors]; + +export type CallWithDuplicateResponsesResponses = { + /** + * Message for 200 response + */ + 200: ModelWithBoolean & ModelWithInteger; + /** + * Message for 201 response + */ + 201: ModelWithString; + /** + * Message for 202 response + */ + 202: ModelWithString; +}; + +export type CallWithDuplicateResponsesResponse = CallWithDuplicateResponsesResponses[keyof CallWithDuplicateResponsesResponses]; + +export type CallWithResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for default response + */ + default: ModelWithStringError; +}; + +export type CallWithResponsesError = CallWithResponsesErrors[keyof CallWithResponsesErrors]; + +export type CallWithResponsesResponses = { + /** + * Message for 200 response + */ + 200: { + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; + readonly value?: Array; + }; + /** + * Message for 201 response + */ + 201: ModelThatExtends; + /** + * Message for 202 response + */ + 202: ModelThatExtendsExtends; +}; + +export type CallWithResponsesResponse = CallWithResponsesResponses[keyof CallWithResponsesResponses]; export type CollectionFormatData = { body?: never; @@ -1352,7 +1500,26 @@ export type TypesData = { }; }; -export type TypesResponse = number | string | boolean | {}; +export type TypesResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Response is a simple string + */ + 201: string; + /** + * Response is a simple boolean + */ + 202: boolean; + /** + * Response is a simple object + */ + 203: {}; +}; + +export type TypesResponse = TypesResponses[keyof TypesResponses]; export type UploadFileData = { body: Blob | File; @@ -1365,7 +1532,11 @@ export type UploadFileData = { query?: never; }; -export type UploadFileResponse = boolean; +export type UploadFileResponses = { + 200: boolean; +}; + +export type UploadFileResponse = UploadFileResponses[keyof UploadFileResponses]; export type FileResponseData = { body?: never; @@ -1379,7 +1550,14 @@ export type FileResponseData = { query?: never; }; -export type FileResponseResponse = Blob | File; +export type FileResponseResponses = { + /** + * Success + */ + 200: Blob | File; +}; + +export type FileResponseResponse = FileResponseResponses[keyof FileResponseResponses]; export type ComplexTypesData = { body?: never; @@ -1402,16 +1580,41 @@ export type ComplexTypesData = { }; }; -export type ComplexTypesResponse = Array; +export type ComplexTypesErrors = { + /** + * 400 `server` error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type ComplexTypesResponses = { + /** + * Successful response + */ + 200: Array; +}; -export type MultipartResponseResponse = { - file?: Blob | File; - metadata?: { - foo?: string; - bar?: string; +export type ComplexTypesResponse = ComplexTypesResponses[keyof ComplexTypesResponses]; + +export type MultipartResponseResponses = { + /** + * OK + */ + 200: { + file?: Blob | File; + metadata?: { + foo?: string; + bar?: string; + }; }; }; +export type MultipartResponseResponse = MultipartResponseResponses[keyof MultipartResponseResponses]; + export type MultipartRequestData = { body?: { content?: Blob | File; @@ -1443,7 +1646,32 @@ export type ComplexParamsData = { query?: never; }; -export type ComplexParamsResponse = ModelWithString; +export type ComplexParamsResponses = { + /** + * Success + */ + 200: ModelWithString; +}; + +export type ComplexParamsResponse = ComplexParamsResponses[keyof ComplexParamsResponses]; + +export type CallWithResultFromHeaderErrors = { + /** + * 400 server error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type CallWithResultFromHeaderResponses = { + /** + * Successful response + */ + 200: unknown; +}; export type TestErrorCodeData = { body?: never; @@ -1456,6 +1684,32 @@ export type TestErrorCodeData = { }; }; +export type TestErrorCodeErrors = { + /** + * Custom message: Internal Server Error + */ + 500: unknown; + /** + * Custom message: Not Implemented + */ + 501: unknown; + /** + * Custom message: Bad Gateway + */ + 502: unknown; + /** + * Custom message: Service Unavailable + */ + 503: unknown; +}; + +export type TestErrorCodeResponses = { + /** + * Custom message: Successful response + */ + 200: unknown; +}; + export type NonAsciiæøåÆøÅöôêÊ字符串Data = { body?: never; path?: never; @@ -1467,7 +1721,14 @@ export type NonAsciiæøåÆøÅöôêÊ字符串Data = { }; }; -export type NonAsciiæøåÆøÅöôêÊ字符串Response = Array; +export type NonAsciiæøåÆøÅöôêÊ字符串Responses = { + /** + * Successful response + */ + 200: Array; +}; + +export type NonAsciiæøåÆøÅöôêÊ字符串Response = NonAsciiæøåÆøÅöôêÊ字符串Responses[keyof NonAsciiæøåÆøÅöôêÊ字符串Responses]; export type PutWithFormUrlEncodedData = { body: ArrayWithStrings; 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 2f6b56c07..0478efcec 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 @@ -951,9 +951,27 @@ export type ImportData = { body: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; }; -export type ImportResponse = Model_From_Zendesk | ModelWithReadOnlyAndWriteOnly; +export type ImportResponses = { + /** + * Success + */ + 200: Model_From_Zendesk; + /** + * Default success response + */ + default: ModelWithReadOnlyAndWriteOnly; +}; + +export type ImportResponse = ImportResponses[keyof ImportResponses]; + +export type ApiVversionOdataControllerCountResponses = { + /** + * Success + */ + 200: Model_From_Zendesk; +}; -export type ApiVversionOdataControllerCountResponse = Model_From_Zendesk; +export type ApiVversionOdataControllerCountResponse = ApiVversionOdataControllerCountResponses[keyof ApiVversionOdataControllerCountResponses]; export type GetApiVbyApiVersionSimpleOperationData = { body?: never; @@ -966,9 +984,23 @@ export type GetApiVbyApiVersionSimpleOperationData = { query?: never; }; -export type GetApiVbyApiVersionSimpleOperationError = ModelWithBoolean; +export type GetApiVbyApiVersionSimpleOperationErrors = { + /** + * Default error response + */ + default: ModelWithBoolean; +}; -export type GetApiVbyApiVersionSimpleOperationResponse = number; +export type GetApiVbyApiVersionSimpleOperationError = GetApiVbyApiVersionSimpleOperationErrors[keyof GetApiVbyApiVersionSimpleOperationErrors]; + +export type GetApiVbyApiVersionSimpleOperationResponses = { + /** + * Response is a simple number + */ + 200: number; +}; + +export type GetApiVbyApiVersionSimpleOperationResponse = GetApiVbyApiVersionSimpleOperationResponses[keyof GetApiVbyApiVersionSimpleOperationResponses]; export type DeleteFooData3 = { body?: never; @@ -1140,7 +1172,18 @@ export type PostCallWithOptionalParamData = { }; }; -export type PostCallWithOptionalParamResponse = number | void; +export type PostCallWithOptionalParamResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; + +export type PostCallWithOptionalParamResponse = PostCallWithOptionalParamResponses[keyof PostCallWithOptionalParamResponses]; export type PostApiVbyApiVersionRequestBodyData = { /** @@ -1263,27 +1306,132 @@ export type CallToTestOrderOfParamsData = { }; }; -export type CallWithNoContentResponseResponse = void; +export type CallWithNoContentResponseResponses = { + /** + * Success + */ + 204: void; +}; -export type CallWithResponseAndNoContentResponseResponse = number | void; +export type CallWithNoContentResponseResponse = CallWithNoContentResponseResponses[keyof CallWithNoContentResponseResponses]; -export type DummyAResponse = _400; +export type CallWithResponseAndNoContentResponseResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; -export type DummyBResponse = void; +export type CallWithResponseAndNoContentResponseResponse = CallWithResponseAndNoContentResponseResponses[keyof CallWithResponseAndNoContentResponseResponses]; -export type CallWithResponseResponse = _import; +export type DummyAResponses = { + 200: _400; +}; -export type CallWithDuplicateResponsesError = ModelWithStringError | DictionaryWithArray | ModelWithBoolean; +export type DummyAResponse = DummyAResponses[keyof DummyAResponses]; -export type CallWithDuplicateResponsesResponse = (ModelWithBoolean & ModelWithInteger) | ModelWithString; +export type DummyBResponses = { + /** + * Success + */ + 204: void; +}; -export type CallWithResponsesError = ModelWithStringError; +export type DummyBResponse = DummyBResponses[keyof DummyBResponses]; -export type CallWithResponsesResponse = { - readonly '@namespace.string'?: string; - readonly '@namespace.integer'?: number; - readonly value?: Array; -} | ModelThatExtends | ModelThatExtendsExtends; +export type CallWithResponseResponses = { + default: _import; +}; + +export type CallWithResponseResponse = CallWithResponseResponses[keyof CallWithResponseResponses]; + +export type CallWithDuplicateResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for 4XX errors + */ + '4XX': DictionaryWithArray; + /** + * Default error response + */ + default: ModelWithBoolean; +}; + +export type CallWithDuplicateResponsesError = CallWithDuplicateResponsesErrors[keyof CallWithDuplicateResponsesErrors]; + +export type CallWithDuplicateResponsesResponses = { + /** + * Message for 200 response + */ + 200: ModelWithBoolean & ModelWithInteger; + /** + * Message for 201 response + */ + 201: ModelWithString; + /** + * Message for 202 response + */ + 202: ModelWithString; +}; + +export type CallWithDuplicateResponsesResponse = CallWithDuplicateResponsesResponses[keyof CallWithDuplicateResponsesResponses]; + +export type CallWithResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for default response + */ + default: ModelWithStringError; +}; + +export type CallWithResponsesError = CallWithResponsesErrors[keyof CallWithResponsesErrors]; + +export type CallWithResponsesResponses = { + /** + * Message for 200 response + */ + 200: { + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; + readonly value?: Array; + }; + /** + * Message for 201 response + */ + 201: ModelThatExtends; + /** + * Message for 202 response + */ + 202: ModelThatExtendsExtends; +}; + +export type CallWithResponsesResponse = CallWithResponsesResponses[keyof CallWithResponsesResponses]; export type CollectionFormatData = { body?: never; @@ -1352,7 +1500,26 @@ export type TypesData = { }; }; -export type TypesResponse = number | string | boolean | {}; +export type TypesResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Response is a simple string + */ + 201: string; + /** + * Response is a simple boolean + */ + 202: boolean; + /** + * Response is a simple object + */ + 203: {}; +}; + +export type TypesResponse = TypesResponses[keyof TypesResponses]; export type UploadFileData = { body: Blob | File; @@ -1365,7 +1532,11 @@ export type UploadFileData = { query?: never; }; -export type UploadFileResponse = boolean; +export type UploadFileResponses = { + 200: boolean; +}; + +export type UploadFileResponse = UploadFileResponses[keyof UploadFileResponses]; export type FileResponseData = { body?: never; @@ -1379,7 +1550,14 @@ export type FileResponseData = { query?: never; }; -export type FileResponseResponse = Blob | File; +export type FileResponseResponses = { + /** + * Success + */ + 200: Blob | File; +}; + +export type FileResponseResponse = FileResponseResponses[keyof FileResponseResponses]; export type ComplexTypesData = { body?: never; @@ -1402,16 +1580,41 @@ export type ComplexTypesData = { }; }; -export type ComplexTypesResponse = Array; +export type ComplexTypesErrors = { + /** + * 400 `server` error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type ComplexTypesResponses = { + /** + * Successful response + */ + 200: Array; +}; -export type MultipartResponseResponse = { - file?: Blob | File; - metadata?: { - foo?: string; - bar?: string; +export type ComplexTypesResponse = ComplexTypesResponses[keyof ComplexTypesResponses]; + +export type MultipartResponseResponses = { + /** + * OK + */ + 200: { + file?: Blob | File; + metadata?: { + foo?: string; + bar?: string; + }; }; }; +export type MultipartResponseResponse = MultipartResponseResponses[keyof MultipartResponseResponses]; + export type MultipartRequestData = { body?: { content?: Blob | File; @@ -1443,7 +1646,32 @@ export type ComplexParamsData = { query?: never; }; -export type ComplexParamsResponse = ModelWithString; +export type ComplexParamsResponses = { + /** + * Success + */ + 200: ModelWithString; +}; + +export type ComplexParamsResponse = ComplexParamsResponses[keyof ComplexParamsResponses]; + +export type CallWithResultFromHeaderErrors = { + /** + * 400 server error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type CallWithResultFromHeaderResponses = { + /** + * Successful response + */ + 200: unknown; +}; export type TestErrorCodeData = { body?: never; @@ -1456,6 +1684,32 @@ export type TestErrorCodeData = { }; }; +export type TestErrorCodeErrors = { + /** + * Custom message: Internal Server Error + */ + 500: unknown; + /** + * Custom message: Not Implemented + */ + 501: unknown; + /** + * Custom message: Bad Gateway + */ + 502: unknown; + /** + * Custom message: Service Unavailable + */ + 503: unknown; +}; + +export type TestErrorCodeResponses = { + /** + * Custom message: Successful response + */ + 200: unknown; +}; + export type NonAsciiæøåÆøÅöôêÊ字符串Data = { body?: never; path?: never; @@ -1467,7 +1721,14 @@ export type NonAsciiæøåÆøÅöôêÊ字符串Data = { }; }; -export type NonAsciiæøåÆøÅöôêÊ字符串Response = Array; +export type NonAsciiæøåÆøÅöôêÊ字符串Responses = { + /** + * Successful response + */ + 200: Array; +}; + +export type NonAsciiæøåÆøÅöôêÊ字符串Response = NonAsciiæøåÆøÅöôêÊ字符串Responses[keyof NonAsciiæøåÆøÅöôêÊ字符串Responses]; export type PutWithFormUrlEncodedData = { body: ArrayWithStrings; 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 2f6b56c07..0478efcec 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 @@ -951,9 +951,27 @@ export type ImportData = { body: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; }; -export type ImportResponse = Model_From_Zendesk | ModelWithReadOnlyAndWriteOnly; +export type ImportResponses = { + /** + * Success + */ + 200: Model_From_Zendesk; + /** + * Default success response + */ + default: ModelWithReadOnlyAndWriteOnly; +}; + +export type ImportResponse = ImportResponses[keyof ImportResponses]; + +export type ApiVversionOdataControllerCountResponses = { + /** + * Success + */ + 200: Model_From_Zendesk; +}; -export type ApiVversionOdataControllerCountResponse = Model_From_Zendesk; +export type ApiVversionOdataControllerCountResponse = ApiVversionOdataControllerCountResponses[keyof ApiVversionOdataControllerCountResponses]; export type GetApiVbyApiVersionSimpleOperationData = { body?: never; @@ -966,9 +984,23 @@ export type GetApiVbyApiVersionSimpleOperationData = { query?: never; }; -export type GetApiVbyApiVersionSimpleOperationError = ModelWithBoolean; +export type GetApiVbyApiVersionSimpleOperationErrors = { + /** + * Default error response + */ + default: ModelWithBoolean; +}; -export type GetApiVbyApiVersionSimpleOperationResponse = number; +export type GetApiVbyApiVersionSimpleOperationError = GetApiVbyApiVersionSimpleOperationErrors[keyof GetApiVbyApiVersionSimpleOperationErrors]; + +export type GetApiVbyApiVersionSimpleOperationResponses = { + /** + * Response is a simple number + */ + 200: number; +}; + +export type GetApiVbyApiVersionSimpleOperationResponse = GetApiVbyApiVersionSimpleOperationResponses[keyof GetApiVbyApiVersionSimpleOperationResponses]; export type DeleteFooData3 = { body?: never; @@ -1140,7 +1172,18 @@ export type PostCallWithOptionalParamData = { }; }; -export type PostCallWithOptionalParamResponse = number | void; +export type PostCallWithOptionalParamResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; + +export type PostCallWithOptionalParamResponse = PostCallWithOptionalParamResponses[keyof PostCallWithOptionalParamResponses]; export type PostApiVbyApiVersionRequestBodyData = { /** @@ -1263,27 +1306,132 @@ export type CallToTestOrderOfParamsData = { }; }; -export type CallWithNoContentResponseResponse = void; +export type CallWithNoContentResponseResponses = { + /** + * Success + */ + 204: void; +}; -export type CallWithResponseAndNoContentResponseResponse = number | void; +export type CallWithNoContentResponseResponse = CallWithNoContentResponseResponses[keyof CallWithNoContentResponseResponses]; -export type DummyAResponse = _400; +export type CallWithResponseAndNoContentResponseResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; -export type DummyBResponse = void; +export type CallWithResponseAndNoContentResponseResponse = CallWithResponseAndNoContentResponseResponses[keyof CallWithResponseAndNoContentResponseResponses]; -export type CallWithResponseResponse = _import; +export type DummyAResponses = { + 200: _400; +}; -export type CallWithDuplicateResponsesError = ModelWithStringError | DictionaryWithArray | ModelWithBoolean; +export type DummyAResponse = DummyAResponses[keyof DummyAResponses]; -export type CallWithDuplicateResponsesResponse = (ModelWithBoolean & ModelWithInteger) | ModelWithString; +export type DummyBResponses = { + /** + * Success + */ + 204: void; +}; -export type CallWithResponsesError = ModelWithStringError; +export type DummyBResponse = DummyBResponses[keyof DummyBResponses]; -export type CallWithResponsesResponse = { - readonly '@namespace.string'?: string; - readonly '@namespace.integer'?: number; - readonly value?: Array; -} | ModelThatExtends | ModelThatExtendsExtends; +export type CallWithResponseResponses = { + default: _import; +}; + +export type CallWithResponseResponse = CallWithResponseResponses[keyof CallWithResponseResponses]; + +export type CallWithDuplicateResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for 4XX errors + */ + '4XX': DictionaryWithArray; + /** + * Default error response + */ + default: ModelWithBoolean; +}; + +export type CallWithDuplicateResponsesError = CallWithDuplicateResponsesErrors[keyof CallWithDuplicateResponsesErrors]; + +export type CallWithDuplicateResponsesResponses = { + /** + * Message for 200 response + */ + 200: ModelWithBoolean & ModelWithInteger; + /** + * Message for 201 response + */ + 201: ModelWithString; + /** + * Message for 202 response + */ + 202: ModelWithString; +}; + +export type CallWithDuplicateResponsesResponse = CallWithDuplicateResponsesResponses[keyof CallWithDuplicateResponsesResponses]; + +export type CallWithResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for default response + */ + default: ModelWithStringError; +}; + +export type CallWithResponsesError = CallWithResponsesErrors[keyof CallWithResponsesErrors]; + +export type CallWithResponsesResponses = { + /** + * Message for 200 response + */ + 200: { + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; + readonly value?: Array; + }; + /** + * Message for 201 response + */ + 201: ModelThatExtends; + /** + * Message for 202 response + */ + 202: ModelThatExtendsExtends; +}; + +export type CallWithResponsesResponse = CallWithResponsesResponses[keyof CallWithResponsesResponses]; export type CollectionFormatData = { body?: never; @@ -1352,7 +1500,26 @@ export type TypesData = { }; }; -export type TypesResponse = number | string | boolean | {}; +export type TypesResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Response is a simple string + */ + 201: string; + /** + * Response is a simple boolean + */ + 202: boolean; + /** + * Response is a simple object + */ + 203: {}; +}; + +export type TypesResponse = TypesResponses[keyof TypesResponses]; export type UploadFileData = { body: Blob | File; @@ -1365,7 +1532,11 @@ export type UploadFileData = { query?: never; }; -export type UploadFileResponse = boolean; +export type UploadFileResponses = { + 200: boolean; +}; + +export type UploadFileResponse = UploadFileResponses[keyof UploadFileResponses]; export type FileResponseData = { body?: never; @@ -1379,7 +1550,14 @@ export type FileResponseData = { query?: never; }; -export type FileResponseResponse = Blob | File; +export type FileResponseResponses = { + /** + * Success + */ + 200: Blob | File; +}; + +export type FileResponseResponse = FileResponseResponses[keyof FileResponseResponses]; export type ComplexTypesData = { body?: never; @@ -1402,16 +1580,41 @@ export type ComplexTypesData = { }; }; -export type ComplexTypesResponse = Array; +export type ComplexTypesErrors = { + /** + * 400 `server` error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type ComplexTypesResponses = { + /** + * Successful response + */ + 200: Array; +}; -export type MultipartResponseResponse = { - file?: Blob | File; - metadata?: { - foo?: string; - bar?: string; +export type ComplexTypesResponse = ComplexTypesResponses[keyof ComplexTypesResponses]; + +export type MultipartResponseResponses = { + /** + * OK + */ + 200: { + file?: Blob | File; + metadata?: { + foo?: string; + bar?: string; + }; }; }; +export type MultipartResponseResponse = MultipartResponseResponses[keyof MultipartResponseResponses]; + export type MultipartRequestData = { body?: { content?: Blob | File; @@ -1443,7 +1646,32 @@ export type ComplexParamsData = { query?: never; }; -export type ComplexParamsResponse = ModelWithString; +export type ComplexParamsResponses = { + /** + * Success + */ + 200: ModelWithString; +}; + +export type ComplexParamsResponse = ComplexParamsResponses[keyof ComplexParamsResponses]; + +export type CallWithResultFromHeaderErrors = { + /** + * 400 server error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type CallWithResultFromHeaderResponses = { + /** + * Successful response + */ + 200: unknown; +}; export type TestErrorCodeData = { body?: never; @@ -1456,6 +1684,32 @@ export type TestErrorCodeData = { }; }; +export type TestErrorCodeErrors = { + /** + * Custom message: Internal Server Error + */ + 500: unknown; + /** + * Custom message: Not Implemented + */ + 501: unknown; + /** + * Custom message: Bad Gateway + */ + 502: unknown; + /** + * Custom message: Service Unavailable + */ + 503: unknown; +}; + +export type TestErrorCodeResponses = { + /** + * Custom message: Successful response + */ + 200: unknown; +}; + export type NonAsciiæøåÆøÅöôêÊ字符串Data = { body?: never; path?: never; @@ -1467,7 +1721,14 @@ export type NonAsciiæøåÆøÅöôêÊ字符串Data = { }; }; -export type NonAsciiæøåÆøÅöôêÊ字符串Response = Array; +export type NonAsciiæøåÆøÅöôêÊ字符串Responses = { + /** + * Successful response + */ + 200: Array; +}; + +export type NonAsciiæøåÆøÅöôêÊ字符串Response = NonAsciiæøåÆøÅöôêÊ字符串Responses[keyof NonAsciiæøåÆøÅöôêÊ字符串Responses]; export type PutWithFormUrlEncodedData = { body: ArrayWithStrings; 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 2f6b56c07..0478efcec 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 @@ -951,9 +951,27 @@ export type ImportData = { body: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; }; -export type ImportResponse = Model_From_Zendesk | ModelWithReadOnlyAndWriteOnly; +export type ImportResponses = { + /** + * Success + */ + 200: Model_From_Zendesk; + /** + * Default success response + */ + default: ModelWithReadOnlyAndWriteOnly; +}; + +export type ImportResponse = ImportResponses[keyof ImportResponses]; + +export type ApiVversionOdataControllerCountResponses = { + /** + * Success + */ + 200: Model_From_Zendesk; +}; -export type ApiVversionOdataControllerCountResponse = Model_From_Zendesk; +export type ApiVversionOdataControllerCountResponse = ApiVversionOdataControllerCountResponses[keyof ApiVversionOdataControllerCountResponses]; export type GetApiVbyApiVersionSimpleOperationData = { body?: never; @@ -966,9 +984,23 @@ export type GetApiVbyApiVersionSimpleOperationData = { query?: never; }; -export type GetApiVbyApiVersionSimpleOperationError = ModelWithBoolean; +export type GetApiVbyApiVersionSimpleOperationErrors = { + /** + * Default error response + */ + default: ModelWithBoolean; +}; -export type GetApiVbyApiVersionSimpleOperationResponse = number; +export type GetApiVbyApiVersionSimpleOperationError = GetApiVbyApiVersionSimpleOperationErrors[keyof GetApiVbyApiVersionSimpleOperationErrors]; + +export type GetApiVbyApiVersionSimpleOperationResponses = { + /** + * Response is a simple number + */ + 200: number; +}; + +export type GetApiVbyApiVersionSimpleOperationResponse = GetApiVbyApiVersionSimpleOperationResponses[keyof GetApiVbyApiVersionSimpleOperationResponses]; export type DeleteFooData3 = { body?: never; @@ -1140,7 +1172,18 @@ export type PostCallWithOptionalParamData = { }; }; -export type PostCallWithOptionalParamResponse = number | void; +export type PostCallWithOptionalParamResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; + +export type PostCallWithOptionalParamResponse = PostCallWithOptionalParamResponses[keyof PostCallWithOptionalParamResponses]; export type PostApiVbyApiVersionRequestBodyData = { /** @@ -1263,27 +1306,132 @@ export type CallToTestOrderOfParamsData = { }; }; -export type CallWithNoContentResponseResponse = void; +export type CallWithNoContentResponseResponses = { + /** + * Success + */ + 204: void; +}; -export type CallWithResponseAndNoContentResponseResponse = number | void; +export type CallWithNoContentResponseResponse = CallWithNoContentResponseResponses[keyof CallWithNoContentResponseResponses]; -export type DummyAResponse = _400; +export type CallWithResponseAndNoContentResponseResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; -export type DummyBResponse = void; +export type CallWithResponseAndNoContentResponseResponse = CallWithResponseAndNoContentResponseResponses[keyof CallWithResponseAndNoContentResponseResponses]; -export type CallWithResponseResponse = _import; +export type DummyAResponses = { + 200: _400; +}; -export type CallWithDuplicateResponsesError = ModelWithStringError | DictionaryWithArray | ModelWithBoolean; +export type DummyAResponse = DummyAResponses[keyof DummyAResponses]; -export type CallWithDuplicateResponsesResponse = (ModelWithBoolean & ModelWithInteger) | ModelWithString; +export type DummyBResponses = { + /** + * Success + */ + 204: void; +}; -export type CallWithResponsesError = ModelWithStringError; +export type DummyBResponse = DummyBResponses[keyof DummyBResponses]; -export type CallWithResponsesResponse = { - readonly '@namespace.string'?: string; - readonly '@namespace.integer'?: number; - readonly value?: Array; -} | ModelThatExtends | ModelThatExtendsExtends; +export type CallWithResponseResponses = { + default: _import; +}; + +export type CallWithResponseResponse = CallWithResponseResponses[keyof CallWithResponseResponses]; + +export type CallWithDuplicateResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for 4XX errors + */ + '4XX': DictionaryWithArray; + /** + * Default error response + */ + default: ModelWithBoolean; +}; + +export type CallWithDuplicateResponsesError = CallWithDuplicateResponsesErrors[keyof CallWithDuplicateResponsesErrors]; + +export type CallWithDuplicateResponsesResponses = { + /** + * Message for 200 response + */ + 200: ModelWithBoolean & ModelWithInteger; + /** + * Message for 201 response + */ + 201: ModelWithString; + /** + * Message for 202 response + */ + 202: ModelWithString; +}; + +export type CallWithDuplicateResponsesResponse = CallWithDuplicateResponsesResponses[keyof CallWithDuplicateResponsesResponses]; + +export type CallWithResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for default response + */ + default: ModelWithStringError; +}; + +export type CallWithResponsesError = CallWithResponsesErrors[keyof CallWithResponsesErrors]; + +export type CallWithResponsesResponses = { + /** + * Message for 200 response + */ + 200: { + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; + readonly value?: Array; + }; + /** + * Message for 201 response + */ + 201: ModelThatExtends; + /** + * Message for 202 response + */ + 202: ModelThatExtendsExtends; +}; + +export type CallWithResponsesResponse = CallWithResponsesResponses[keyof CallWithResponsesResponses]; export type CollectionFormatData = { body?: never; @@ -1352,7 +1500,26 @@ export type TypesData = { }; }; -export type TypesResponse = number | string | boolean | {}; +export type TypesResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Response is a simple string + */ + 201: string; + /** + * Response is a simple boolean + */ + 202: boolean; + /** + * Response is a simple object + */ + 203: {}; +}; + +export type TypesResponse = TypesResponses[keyof TypesResponses]; export type UploadFileData = { body: Blob | File; @@ -1365,7 +1532,11 @@ export type UploadFileData = { query?: never; }; -export type UploadFileResponse = boolean; +export type UploadFileResponses = { + 200: boolean; +}; + +export type UploadFileResponse = UploadFileResponses[keyof UploadFileResponses]; export type FileResponseData = { body?: never; @@ -1379,7 +1550,14 @@ export type FileResponseData = { query?: never; }; -export type FileResponseResponse = Blob | File; +export type FileResponseResponses = { + /** + * Success + */ + 200: Blob | File; +}; + +export type FileResponseResponse = FileResponseResponses[keyof FileResponseResponses]; export type ComplexTypesData = { body?: never; @@ -1402,16 +1580,41 @@ export type ComplexTypesData = { }; }; -export type ComplexTypesResponse = Array; +export type ComplexTypesErrors = { + /** + * 400 `server` error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type ComplexTypesResponses = { + /** + * Successful response + */ + 200: Array; +}; -export type MultipartResponseResponse = { - file?: Blob | File; - metadata?: { - foo?: string; - bar?: string; +export type ComplexTypesResponse = ComplexTypesResponses[keyof ComplexTypesResponses]; + +export type MultipartResponseResponses = { + /** + * OK + */ + 200: { + file?: Blob | File; + metadata?: { + foo?: string; + bar?: string; + }; }; }; +export type MultipartResponseResponse = MultipartResponseResponses[keyof MultipartResponseResponses]; + export type MultipartRequestData = { body?: { content?: Blob | File; @@ -1443,7 +1646,32 @@ export type ComplexParamsData = { query?: never; }; -export type ComplexParamsResponse = ModelWithString; +export type ComplexParamsResponses = { + /** + * Success + */ + 200: ModelWithString; +}; + +export type ComplexParamsResponse = ComplexParamsResponses[keyof ComplexParamsResponses]; + +export type CallWithResultFromHeaderErrors = { + /** + * 400 server error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type CallWithResultFromHeaderResponses = { + /** + * Successful response + */ + 200: unknown; +}; export type TestErrorCodeData = { body?: never; @@ -1456,6 +1684,32 @@ export type TestErrorCodeData = { }; }; +export type TestErrorCodeErrors = { + /** + * Custom message: Internal Server Error + */ + 500: unknown; + /** + * Custom message: Not Implemented + */ + 501: unknown; + /** + * Custom message: Bad Gateway + */ + 502: unknown; + /** + * Custom message: Service Unavailable + */ + 503: unknown; +}; + +export type TestErrorCodeResponses = { + /** + * Custom message: Successful response + */ + 200: unknown; +}; + export type NonAsciiæøåÆøÅöôêÊ字符串Data = { body?: never; path?: never; @@ -1467,7 +1721,14 @@ export type NonAsciiæøåÆøÅöôêÊ字符串Data = { }; }; -export type NonAsciiæøåÆøÅöôêÊ字符串Response = Array; +export type NonAsciiæøåÆøÅöôêÊ字符串Responses = { + /** + * Successful response + */ + 200: Array; +}; + +export type NonAsciiæøåÆøÅöôêÊ字符串Response = NonAsciiæøåÆøÅöôêÊ字符串Responses[keyof NonAsciiæøåÆøÅöôêÊ字符串Responses]; export type PutWithFormUrlEncodedData = { body: ArrayWithStrings; 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 2f6b56c07..0478efcec 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 @@ -951,9 +951,27 @@ export type ImportData = { body: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; }; -export type ImportResponse = Model_From_Zendesk | ModelWithReadOnlyAndWriteOnly; +export type ImportResponses = { + /** + * Success + */ + 200: Model_From_Zendesk; + /** + * Default success response + */ + default: ModelWithReadOnlyAndWriteOnly; +}; + +export type ImportResponse = ImportResponses[keyof ImportResponses]; + +export type ApiVversionOdataControllerCountResponses = { + /** + * Success + */ + 200: Model_From_Zendesk; +}; -export type ApiVversionOdataControllerCountResponse = Model_From_Zendesk; +export type ApiVversionOdataControllerCountResponse = ApiVversionOdataControllerCountResponses[keyof ApiVversionOdataControllerCountResponses]; export type GetApiVbyApiVersionSimpleOperationData = { body?: never; @@ -966,9 +984,23 @@ export type GetApiVbyApiVersionSimpleOperationData = { query?: never; }; -export type GetApiVbyApiVersionSimpleOperationError = ModelWithBoolean; +export type GetApiVbyApiVersionSimpleOperationErrors = { + /** + * Default error response + */ + default: ModelWithBoolean; +}; -export type GetApiVbyApiVersionSimpleOperationResponse = number; +export type GetApiVbyApiVersionSimpleOperationError = GetApiVbyApiVersionSimpleOperationErrors[keyof GetApiVbyApiVersionSimpleOperationErrors]; + +export type GetApiVbyApiVersionSimpleOperationResponses = { + /** + * Response is a simple number + */ + 200: number; +}; + +export type GetApiVbyApiVersionSimpleOperationResponse = GetApiVbyApiVersionSimpleOperationResponses[keyof GetApiVbyApiVersionSimpleOperationResponses]; export type DeleteFooData3 = { body?: never; @@ -1140,7 +1172,18 @@ export type PostCallWithOptionalParamData = { }; }; -export type PostCallWithOptionalParamResponse = number | void; +export type PostCallWithOptionalParamResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; + +export type PostCallWithOptionalParamResponse = PostCallWithOptionalParamResponses[keyof PostCallWithOptionalParamResponses]; export type PostApiVbyApiVersionRequestBodyData = { /** @@ -1263,27 +1306,132 @@ export type CallToTestOrderOfParamsData = { }; }; -export type CallWithNoContentResponseResponse = void; +export type CallWithNoContentResponseResponses = { + /** + * Success + */ + 204: void; +}; -export type CallWithResponseAndNoContentResponseResponse = number | void; +export type CallWithNoContentResponseResponse = CallWithNoContentResponseResponses[keyof CallWithNoContentResponseResponses]; -export type DummyAResponse = _400; +export type CallWithResponseAndNoContentResponseResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; -export type DummyBResponse = void; +export type CallWithResponseAndNoContentResponseResponse = CallWithResponseAndNoContentResponseResponses[keyof CallWithResponseAndNoContentResponseResponses]; -export type CallWithResponseResponse = _import; +export type DummyAResponses = { + 200: _400; +}; -export type CallWithDuplicateResponsesError = ModelWithStringError | DictionaryWithArray | ModelWithBoolean; +export type DummyAResponse = DummyAResponses[keyof DummyAResponses]; -export type CallWithDuplicateResponsesResponse = (ModelWithBoolean & ModelWithInteger) | ModelWithString; +export type DummyBResponses = { + /** + * Success + */ + 204: void; +}; -export type CallWithResponsesError = ModelWithStringError; +export type DummyBResponse = DummyBResponses[keyof DummyBResponses]; -export type CallWithResponsesResponse = { - readonly '@namespace.string'?: string; - readonly '@namespace.integer'?: number; - readonly value?: Array; -} | ModelThatExtends | ModelThatExtendsExtends; +export type CallWithResponseResponses = { + default: _import; +}; + +export type CallWithResponseResponse = CallWithResponseResponses[keyof CallWithResponseResponses]; + +export type CallWithDuplicateResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for 4XX errors + */ + '4XX': DictionaryWithArray; + /** + * Default error response + */ + default: ModelWithBoolean; +}; + +export type CallWithDuplicateResponsesError = CallWithDuplicateResponsesErrors[keyof CallWithDuplicateResponsesErrors]; + +export type CallWithDuplicateResponsesResponses = { + /** + * Message for 200 response + */ + 200: ModelWithBoolean & ModelWithInteger; + /** + * Message for 201 response + */ + 201: ModelWithString; + /** + * Message for 202 response + */ + 202: ModelWithString; +}; + +export type CallWithDuplicateResponsesResponse = CallWithDuplicateResponsesResponses[keyof CallWithDuplicateResponsesResponses]; + +export type CallWithResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for default response + */ + default: ModelWithStringError; +}; + +export type CallWithResponsesError = CallWithResponsesErrors[keyof CallWithResponsesErrors]; + +export type CallWithResponsesResponses = { + /** + * Message for 200 response + */ + 200: { + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; + readonly value?: Array; + }; + /** + * Message for 201 response + */ + 201: ModelThatExtends; + /** + * Message for 202 response + */ + 202: ModelThatExtendsExtends; +}; + +export type CallWithResponsesResponse = CallWithResponsesResponses[keyof CallWithResponsesResponses]; export type CollectionFormatData = { body?: never; @@ -1352,7 +1500,26 @@ export type TypesData = { }; }; -export type TypesResponse = number | string | boolean | {}; +export type TypesResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Response is a simple string + */ + 201: string; + /** + * Response is a simple boolean + */ + 202: boolean; + /** + * Response is a simple object + */ + 203: {}; +}; + +export type TypesResponse = TypesResponses[keyof TypesResponses]; export type UploadFileData = { body: Blob | File; @@ -1365,7 +1532,11 @@ export type UploadFileData = { query?: never; }; -export type UploadFileResponse = boolean; +export type UploadFileResponses = { + 200: boolean; +}; + +export type UploadFileResponse = UploadFileResponses[keyof UploadFileResponses]; export type FileResponseData = { body?: never; @@ -1379,7 +1550,14 @@ export type FileResponseData = { query?: never; }; -export type FileResponseResponse = Blob | File; +export type FileResponseResponses = { + /** + * Success + */ + 200: Blob | File; +}; + +export type FileResponseResponse = FileResponseResponses[keyof FileResponseResponses]; export type ComplexTypesData = { body?: never; @@ -1402,16 +1580,41 @@ export type ComplexTypesData = { }; }; -export type ComplexTypesResponse = Array; +export type ComplexTypesErrors = { + /** + * 400 `server` error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type ComplexTypesResponses = { + /** + * Successful response + */ + 200: Array; +}; -export type MultipartResponseResponse = { - file?: Blob | File; - metadata?: { - foo?: string; - bar?: string; +export type ComplexTypesResponse = ComplexTypesResponses[keyof ComplexTypesResponses]; + +export type MultipartResponseResponses = { + /** + * OK + */ + 200: { + file?: Blob | File; + metadata?: { + foo?: string; + bar?: string; + }; }; }; +export type MultipartResponseResponse = MultipartResponseResponses[keyof MultipartResponseResponses]; + export type MultipartRequestData = { body?: { content?: Blob | File; @@ -1443,7 +1646,32 @@ export type ComplexParamsData = { query?: never; }; -export type ComplexParamsResponse = ModelWithString; +export type ComplexParamsResponses = { + /** + * Success + */ + 200: ModelWithString; +}; + +export type ComplexParamsResponse = ComplexParamsResponses[keyof ComplexParamsResponses]; + +export type CallWithResultFromHeaderErrors = { + /** + * 400 server error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type CallWithResultFromHeaderResponses = { + /** + * Successful response + */ + 200: unknown; +}; export type TestErrorCodeData = { body?: never; @@ -1456,6 +1684,32 @@ export type TestErrorCodeData = { }; }; +export type TestErrorCodeErrors = { + /** + * Custom message: Internal Server Error + */ + 500: unknown; + /** + * Custom message: Not Implemented + */ + 501: unknown; + /** + * Custom message: Bad Gateway + */ + 502: unknown; + /** + * Custom message: Service Unavailable + */ + 503: unknown; +}; + +export type TestErrorCodeResponses = { + /** + * Custom message: Successful response + */ + 200: unknown; +}; + export type NonAsciiæøåÆøÅöôêÊ字符串Data = { body?: never; path?: never; @@ -1467,7 +1721,14 @@ export type NonAsciiæøåÆøÅöôêÊ字符串Data = { }; }; -export type NonAsciiæøåÆøÅöôêÊ字符串Response = Array; +export type NonAsciiæøåÆøÅöôêÊ字符串Responses = { + /** + * Successful response + */ + 200: Array; +}; + +export type NonAsciiæøåÆøÅöôêÊ字符串Response = NonAsciiæøåÆøÅöôêÊ字符串Responses[keyof NonAsciiæøåÆøÅöôêÊ字符串Responses]; export type PutWithFormUrlEncodedData = { body: ArrayWithStrings; 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 2f6b56c07..0478efcec 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 @@ -951,9 +951,27 @@ export type ImportData = { body: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; }; -export type ImportResponse = Model_From_Zendesk | ModelWithReadOnlyAndWriteOnly; +export type ImportResponses = { + /** + * Success + */ + 200: Model_From_Zendesk; + /** + * Default success response + */ + default: ModelWithReadOnlyAndWriteOnly; +}; + +export type ImportResponse = ImportResponses[keyof ImportResponses]; + +export type ApiVversionOdataControllerCountResponses = { + /** + * Success + */ + 200: Model_From_Zendesk; +}; -export type ApiVversionOdataControllerCountResponse = Model_From_Zendesk; +export type ApiVversionOdataControllerCountResponse = ApiVversionOdataControllerCountResponses[keyof ApiVversionOdataControllerCountResponses]; export type GetApiVbyApiVersionSimpleOperationData = { body?: never; @@ -966,9 +984,23 @@ export type GetApiVbyApiVersionSimpleOperationData = { query?: never; }; -export type GetApiVbyApiVersionSimpleOperationError = ModelWithBoolean; +export type GetApiVbyApiVersionSimpleOperationErrors = { + /** + * Default error response + */ + default: ModelWithBoolean; +}; -export type GetApiVbyApiVersionSimpleOperationResponse = number; +export type GetApiVbyApiVersionSimpleOperationError = GetApiVbyApiVersionSimpleOperationErrors[keyof GetApiVbyApiVersionSimpleOperationErrors]; + +export type GetApiVbyApiVersionSimpleOperationResponses = { + /** + * Response is a simple number + */ + 200: number; +}; + +export type GetApiVbyApiVersionSimpleOperationResponse = GetApiVbyApiVersionSimpleOperationResponses[keyof GetApiVbyApiVersionSimpleOperationResponses]; export type DeleteFooData3 = { body?: never; @@ -1140,7 +1172,18 @@ export type PostCallWithOptionalParamData = { }; }; -export type PostCallWithOptionalParamResponse = number | void; +export type PostCallWithOptionalParamResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; + +export type PostCallWithOptionalParamResponse = PostCallWithOptionalParamResponses[keyof PostCallWithOptionalParamResponses]; export type PostApiVbyApiVersionRequestBodyData = { /** @@ -1263,27 +1306,132 @@ export type CallToTestOrderOfParamsData = { }; }; -export type CallWithNoContentResponseResponse = void; +export type CallWithNoContentResponseResponses = { + /** + * Success + */ + 204: void; +}; -export type CallWithResponseAndNoContentResponseResponse = number | void; +export type CallWithNoContentResponseResponse = CallWithNoContentResponseResponses[keyof CallWithNoContentResponseResponses]; -export type DummyAResponse = _400; +export type CallWithResponseAndNoContentResponseResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; -export type DummyBResponse = void; +export type CallWithResponseAndNoContentResponseResponse = CallWithResponseAndNoContentResponseResponses[keyof CallWithResponseAndNoContentResponseResponses]; -export type CallWithResponseResponse = _import; +export type DummyAResponses = { + 200: _400; +}; -export type CallWithDuplicateResponsesError = ModelWithStringError | DictionaryWithArray | ModelWithBoolean; +export type DummyAResponse = DummyAResponses[keyof DummyAResponses]; -export type CallWithDuplicateResponsesResponse = (ModelWithBoolean & ModelWithInteger) | ModelWithString; +export type DummyBResponses = { + /** + * Success + */ + 204: void; +}; -export type CallWithResponsesError = ModelWithStringError; +export type DummyBResponse = DummyBResponses[keyof DummyBResponses]; -export type CallWithResponsesResponse = { - readonly '@namespace.string'?: string; - readonly '@namespace.integer'?: number; - readonly value?: Array; -} | ModelThatExtends | ModelThatExtendsExtends; +export type CallWithResponseResponses = { + default: _import; +}; + +export type CallWithResponseResponse = CallWithResponseResponses[keyof CallWithResponseResponses]; + +export type CallWithDuplicateResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for 4XX errors + */ + '4XX': DictionaryWithArray; + /** + * Default error response + */ + default: ModelWithBoolean; +}; + +export type CallWithDuplicateResponsesError = CallWithDuplicateResponsesErrors[keyof CallWithDuplicateResponsesErrors]; + +export type CallWithDuplicateResponsesResponses = { + /** + * Message for 200 response + */ + 200: ModelWithBoolean & ModelWithInteger; + /** + * Message for 201 response + */ + 201: ModelWithString; + /** + * Message for 202 response + */ + 202: ModelWithString; +}; + +export type CallWithDuplicateResponsesResponse = CallWithDuplicateResponsesResponses[keyof CallWithDuplicateResponsesResponses]; + +export type CallWithResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for default response + */ + default: ModelWithStringError; +}; + +export type CallWithResponsesError = CallWithResponsesErrors[keyof CallWithResponsesErrors]; + +export type CallWithResponsesResponses = { + /** + * Message for 200 response + */ + 200: { + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; + readonly value?: Array; + }; + /** + * Message for 201 response + */ + 201: ModelThatExtends; + /** + * Message for 202 response + */ + 202: ModelThatExtendsExtends; +}; + +export type CallWithResponsesResponse = CallWithResponsesResponses[keyof CallWithResponsesResponses]; export type CollectionFormatData = { body?: never; @@ -1352,7 +1500,26 @@ export type TypesData = { }; }; -export type TypesResponse = number | string | boolean | {}; +export type TypesResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Response is a simple string + */ + 201: string; + /** + * Response is a simple boolean + */ + 202: boolean; + /** + * Response is a simple object + */ + 203: {}; +}; + +export type TypesResponse = TypesResponses[keyof TypesResponses]; export type UploadFileData = { body: Blob | File; @@ -1365,7 +1532,11 @@ export type UploadFileData = { query?: never; }; -export type UploadFileResponse = boolean; +export type UploadFileResponses = { + 200: boolean; +}; + +export type UploadFileResponse = UploadFileResponses[keyof UploadFileResponses]; export type FileResponseData = { body?: never; @@ -1379,7 +1550,14 @@ export type FileResponseData = { query?: never; }; -export type FileResponseResponse = Blob | File; +export type FileResponseResponses = { + /** + * Success + */ + 200: Blob | File; +}; + +export type FileResponseResponse = FileResponseResponses[keyof FileResponseResponses]; export type ComplexTypesData = { body?: never; @@ -1402,16 +1580,41 @@ export type ComplexTypesData = { }; }; -export type ComplexTypesResponse = Array; +export type ComplexTypesErrors = { + /** + * 400 `server` error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type ComplexTypesResponses = { + /** + * Successful response + */ + 200: Array; +}; -export type MultipartResponseResponse = { - file?: Blob | File; - metadata?: { - foo?: string; - bar?: string; +export type ComplexTypesResponse = ComplexTypesResponses[keyof ComplexTypesResponses]; + +export type MultipartResponseResponses = { + /** + * OK + */ + 200: { + file?: Blob | File; + metadata?: { + foo?: string; + bar?: string; + }; }; }; +export type MultipartResponseResponse = MultipartResponseResponses[keyof MultipartResponseResponses]; + export type MultipartRequestData = { body?: { content?: Blob | File; @@ -1443,7 +1646,32 @@ export type ComplexParamsData = { query?: never; }; -export type ComplexParamsResponse = ModelWithString; +export type ComplexParamsResponses = { + /** + * Success + */ + 200: ModelWithString; +}; + +export type ComplexParamsResponse = ComplexParamsResponses[keyof ComplexParamsResponses]; + +export type CallWithResultFromHeaderErrors = { + /** + * 400 server error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type CallWithResultFromHeaderResponses = { + /** + * Successful response + */ + 200: unknown; +}; export type TestErrorCodeData = { body?: never; @@ -1456,6 +1684,32 @@ export type TestErrorCodeData = { }; }; +export type TestErrorCodeErrors = { + /** + * Custom message: Internal Server Error + */ + 500: unknown; + /** + * Custom message: Not Implemented + */ + 501: unknown; + /** + * Custom message: Bad Gateway + */ + 502: unknown; + /** + * Custom message: Service Unavailable + */ + 503: unknown; +}; + +export type TestErrorCodeResponses = { + /** + * Custom message: Successful response + */ + 200: unknown; +}; + export type NonAsciiæøåÆøÅöôêÊ字符串Data = { body?: never; path?: never; @@ -1467,7 +1721,14 @@ export type NonAsciiæøåÆøÅöôêÊ字符串Data = { }; }; -export type NonAsciiæøåÆøÅöôêÊ字符串Response = Array; +export type NonAsciiæøåÆøÅöôêÊ字符串Responses = { + /** + * Successful response + */ + 200: Array; +}; + +export type NonAsciiæøåÆøÅöôêÊ字符串Response = NonAsciiæøåÆøÅöôêÊ字符串Responses[keyof NonAsciiæøåÆøÅöôêÊ字符串Responses]; export type PutWithFormUrlEncodedData = { body: ArrayWithStrings; 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 2f6b56c07..0478efcec 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 @@ -951,9 +951,27 @@ export type ImportData = { body: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; }; -export type ImportResponse = Model_From_Zendesk | ModelWithReadOnlyAndWriteOnly; +export type ImportResponses = { + /** + * Success + */ + 200: Model_From_Zendesk; + /** + * Default success response + */ + default: ModelWithReadOnlyAndWriteOnly; +}; + +export type ImportResponse = ImportResponses[keyof ImportResponses]; + +export type ApiVversionOdataControllerCountResponses = { + /** + * Success + */ + 200: Model_From_Zendesk; +}; -export type ApiVversionOdataControllerCountResponse = Model_From_Zendesk; +export type ApiVversionOdataControllerCountResponse = ApiVversionOdataControllerCountResponses[keyof ApiVversionOdataControllerCountResponses]; export type GetApiVbyApiVersionSimpleOperationData = { body?: never; @@ -966,9 +984,23 @@ export type GetApiVbyApiVersionSimpleOperationData = { query?: never; }; -export type GetApiVbyApiVersionSimpleOperationError = ModelWithBoolean; +export type GetApiVbyApiVersionSimpleOperationErrors = { + /** + * Default error response + */ + default: ModelWithBoolean; +}; -export type GetApiVbyApiVersionSimpleOperationResponse = number; +export type GetApiVbyApiVersionSimpleOperationError = GetApiVbyApiVersionSimpleOperationErrors[keyof GetApiVbyApiVersionSimpleOperationErrors]; + +export type GetApiVbyApiVersionSimpleOperationResponses = { + /** + * Response is a simple number + */ + 200: number; +}; + +export type GetApiVbyApiVersionSimpleOperationResponse = GetApiVbyApiVersionSimpleOperationResponses[keyof GetApiVbyApiVersionSimpleOperationResponses]; export type DeleteFooData3 = { body?: never; @@ -1140,7 +1172,18 @@ export type PostCallWithOptionalParamData = { }; }; -export type PostCallWithOptionalParamResponse = number | void; +export type PostCallWithOptionalParamResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; + +export type PostCallWithOptionalParamResponse = PostCallWithOptionalParamResponses[keyof PostCallWithOptionalParamResponses]; export type PostApiVbyApiVersionRequestBodyData = { /** @@ -1263,27 +1306,132 @@ export type CallToTestOrderOfParamsData = { }; }; -export type CallWithNoContentResponseResponse = void; +export type CallWithNoContentResponseResponses = { + /** + * Success + */ + 204: void; +}; -export type CallWithResponseAndNoContentResponseResponse = number | void; +export type CallWithNoContentResponseResponse = CallWithNoContentResponseResponses[keyof CallWithNoContentResponseResponses]; -export type DummyAResponse = _400; +export type CallWithResponseAndNoContentResponseResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; -export type DummyBResponse = void; +export type CallWithResponseAndNoContentResponseResponse = CallWithResponseAndNoContentResponseResponses[keyof CallWithResponseAndNoContentResponseResponses]; -export type CallWithResponseResponse = _import; +export type DummyAResponses = { + 200: _400; +}; -export type CallWithDuplicateResponsesError = ModelWithStringError | DictionaryWithArray | ModelWithBoolean; +export type DummyAResponse = DummyAResponses[keyof DummyAResponses]; -export type CallWithDuplicateResponsesResponse = (ModelWithBoolean & ModelWithInteger) | ModelWithString; +export type DummyBResponses = { + /** + * Success + */ + 204: void; +}; -export type CallWithResponsesError = ModelWithStringError; +export type DummyBResponse = DummyBResponses[keyof DummyBResponses]; -export type CallWithResponsesResponse = { - readonly '@namespace.string'?: string; - readonly '@namespace.integer'?: number; - readonly value?: Array; -} | ModelThatExtends | ModelThatExtendsExtends; +export type CallWithResponseResponses = { + default: _import; +}; + +export type CallWithResponseResponse = CallWithResponseResponses[keyof CallWithResponseResponses]; + +export type CallWithDuplicateResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for 4XX errors + */ + '4XX': DictionaryWithArray; + /** + * Default error response + */ + default: ModelWithBoolean; +}; + +export type CallWithDuplicateResponsesError = CallWithDuplicateResponsesErrors[keyof CallWithDuplicateResponsesErrors]; + +export type CallWithDuplicateResponsesResponses = { + /** + * Message for 200 response + */ + 200: ModelWithBoolean & ModelWithInteger; + /** + * Message for 201 response + */ + 201: ModelWithString; + /** + * Message for 202 response + */ + 202: ModelWithString; +}; + +export type CallWithDuplicateResponsesResponse = CallWithDuplicateResponsesResponses[keyof CallWithDuplicateResponsesResponses]; + +export type CallWithResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for default response + */ + default: ModelWithStringError; +}; + +export type CallWithResponsesError = CallWithResponsesErrors[keyof CallWithResponsesErrors]; + +export type CallWithResponsesResponses = { + /** + * Message for 200 response + */ + 200: { + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; + readonly value?: Array; + }; + /** + * Message for 201 response + */ + 201: ModelThatExtends; + /** + * Message for 202 response + */ + 202: ModelThatExtendsExtends; +}; + +export type CallWithResponsesResponse = CallWithResponsesResponses[keyof CallWithResponsesResponses]; export type CollectionFormatData = { body?: never; @@ -1352,7 +1500,26 @@ export type TypesData = { }; }; -export type TypesResponse = number | string | boolean | {}; +export type TypesResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Response is a simple string + */ + 201: string; + /** + * Response is a simple boolean + */ + 202: boolean; + /** + * Response is a simple object + */ + 203: {}; +}; + +export type TypesResponse = TypesResponses[keyof TypesResponses]; export type UploadFileData = { body: Blob | File; @@ -1365,7 +1532,11 @@ export type UploadFileData = { query?: never; }; -export type UploadFileResponse = boolean; +export type UploadFileResponses = { + 200: boolean; +}; + +export type UploadFileResponse = UploadFileResponses[keyof UploadFileResponses]; export type FileResponseData = { body?: never; @@ -1379,7 +1550,14 @@ export type FileResponseData = { query?: never; }; -export type FileResponseResponse = Blob | File; +export type FileResponseResponses = { + /** + * Success + */ + 200: Blob | File; +}; + +export type FileResponseResponse = FileResponseResponses[keyof FileResponseResponses]; export type ComplexTypesData = { body?: never; @@ -1402,16 +1580,41 @@ export type ComplexTypesData = { }; }; -export type ComplexTypesResponse = Array; +export type ComplexTypesErrors = { + /** + * 400 `server` error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type ComplexTypesResponses = { + /** + * Successful response + */ + 200: Array; +}; -export type MultipartResponseResponse = { - file?: Blob | File; - metadata?: { - foo?: string; - bar?: string; +export type ComplexTypesResponse = ComplexTypesResponses[keyof ComplexTypesResponses]; + +export type MultipartResponseResponses = { + /** + * OK + */ + 200: { + file?: Blob | File; + metadata?: { + foo?: string; + bar?: string; + }; }; }; +export type MultipartResponseResponse = MultipartResponseResponses[keyof MultipartResponseResponses]; + export type MultipartRequestData = { body?: { content?: Blob | File; @@ -1443,7 +1646,32 @@ export type ComplexParamsData = { query?: never; }; -export type ComplexParamsResponse = ModelWithString; +export type ComplexParamsResponses = { + /** + * Success + */ + 200: ModelWithString; +}; + +export type ComplexParamsResponse = ComplexParamsResponses[keyof ComplexParamsResponses]; + +export type CallWithResultFromHeaderErrors = { + /** + * 400 server error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type CallWithResultFromHeaderResponses = { + /** + * Successful response + */ + 200: unknown; +}; export type TestErrorCodeData = { body?: never; @@ -1456,6 +1684,32 @@ export type TestErrorCodeData = { }; }; +export type TestErrorCodeErrors = { + /** + * Custom message: Internal Server Error + */ + 500: unknown; + /** + * Custom message: Not Implemented + */ + 501: unknown; + /** + * Custom message: Bad Gateway + */ + 502: unknown; + /** + * Custom message: Service Unavailable + */ + 503: unknown; +}; + +export type TestErrorCodeResponses = { + /** + * Custom message: Successful response + */ + 200: unknown; +}; + export type NonAsciiæøåÆøÅöôêÊ字符串Data = { body?: never; path?: never; @@ -1467,7 +1721,14 @@ export type NonAsciiæøåÆøÅöôêÊ字符串Data = { }; }; -export type NonAsciiæøåÆøÅöôêÊ字符串Response = Array; +export type NonAsciiæøåÆøÅöôêÊ字符串Responses = { + /** + * Successful response + */ + 200: Array; +}; + +export type NonAsciiæøåÆøÅöôêÊ字符串Response = NonAsciiæøåÆøÅöôêÊ字符串Responses[keyof NonAsciiæøåÆøÅöôêÊ字符串Responses]; export type PutWithFormUrlEncodedData = { body: ArrayWithStrings; 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 2f6b56c07..0478efcec 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 @@ -951,9 +951,27 @@ export type ImportData = { body: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; }; -export type ImportResponse = Model_From_Zendesk | ModelWithReadOnlyAndWriteOnly; +export type ImportResponses = { + /** + * Success + */ + 200: Model_From_Zendesk; + /** + * Default success response + */ + default: ModelWithReadOnlyAndWriteOnly; +}; + +export type ImportResponse = ImportResponses[keyof ImportResponses]; + +export type ApiVversionOdataControllerCountResponses = { + /** + * Success + */ + 200: Model_From_Zendesk; +}; -export type ApiVversionOdataControllerCountResponse = Model_From_Zendesk; +export type ApiVversionOdataControllerCountResponse = ApiVversionOdataControllerCountResponses[keyof ApiVversionOdataControllerCountResponses]; export type GetApiVbyApiVersionSimpleOperationData = { body?: never; @@ -966,9 +984,23 @@ export type GetApiVbyApiVersionSimpleOperationData = { query?: never; }; -export type GetApiVbyApiVersionSimpleOperationError = ModelWithBoolean; +export type GetApiVbyApiVersionSimpleOperationErrors = { + /** + * Default error response + */ + default: ModelWithBoolean; +}; -export type GetApiVbyApiVersionSimpleOperationResponse = number; +export type GetApiVbyApiVersionSimpleOperationError = GetApiVbyApiVersionSimpleOperationErrors[keyof GetApiVbyApiVersionSimpleOperationErrors]; + +export type GetApiVbyApiVersionSimpleOperationResponses = { + /** + * Response is a simple number + */ + 200: number; +}; + +export type GetApiVbyApiVersionSimpleOperationResponse = GetApiVbyApiVersionSimpleOperationResponses[keyof GetApiVbyApiVersionSimpleOperationResponses]; export type DeleteFooData3 = { body?: never; @@ -1140,7 +1172,18 @@ export type PostCallWithOptionalParamData = { }; }; -export type PostCallWithOptionalParamResponse = number | void; +export type PostCallWithOptionalParamResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; + +export type PostCallWithOptionalParamResponse = PostCallWithOptionalParamResponses[keyof PostCallWithOptionalParamResponses]; export type PostApiVbyApiVersionRequestBodyData = { /** @@ -1263,27 +1306,132 @@ export type CallToTestOrderOfParamsData = { }; }; -export type CallWithNoContentResponseResponse = void; +export type CallWithNoContentResponseResponses = { + /** + * Success + */ + 204: void; +}; -export type CallWithResponseAndNoContentResponseResponse = number | void; +export type CallWithNoContentResponseResponse = CallWithNoContentResponseResponses[keyof CallWithNoContentResponseResponses]; -export type DummyAResponse = _400; +export type CallWithResponseAndNoContentResponseResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; -export type DummyBResponse = void; +export type CallWithResponseAndNoContentResponseResponse = CallWithResponseAndNoContentResponseResponses[keyof CallWithResponseAndNoContentResponseResponses]; -export type CallWithResponseResponse = _import; +export type DummyAResponses = { + 200: _400; +}; -export type CallWithDuplicateResponsesError = ModelWithStringError | DictionaryWithArray | ModelWithBoolean; +export type DummyAResponse = DummyAResponses[keyof DummyAResponses]; -export type CallWithDuplicateResponsesResponse = (ModelWithBoolean & ModelWithInteger) | ModelWithString; +export type DummyBResponses = { + /** + * Success + */ + 204: void; +}; -export type CallWithResponsesError = ModelWithStringError; +export type DummyBResponse = DummyBResponses[keyof DummyBResponses]; -export type CallWithResponsesResponse = { - readonly '@namespace.string'?: string; - readonly '@namespace.integer'?: number; - readonly value?: Array; -} | ModelThatExtends | ModelThatExtendsExtends; +export type CallWithResponseResponses = { + default: _import; +}; + +export type CallWithResponseResponse = CallWithResponseResponses[keyof CallWithResponseResponses]; + +export type CallWithDuplicateResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for 4XX errors + */ + '4XX': DictionaryWithArray; + /** + * Default error response + */ + default: ModelWithBoolean; +}; + +export type CallWithDuplicateResponsesError = CallWithDuplicateResponsesErrors[keyof CallWithDuplicateResponsesErrors]; + +export type CallWithDuplicateResponsesResponses = { + /** + * Message for 200 response + */ + 200: ModelWithBoolean & ModelWithInteger; + /** + * Message for 201 response + */ + 201: ModelWithString; + /** + * Message for 202 response + */ + 202: ModelWithString; +}; + +export type CallWithDuplicateResponsesResponse = CallWithDuplicateResponsesResponses[keyof CallWithDuplicateResponsesResponses]; + +export type CallWithResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for default response + */ + default: ModelWithStringError; +}; + +export type CallWithResponsesError = CallWithResponsesErrors[keyof CallWithResponsesErrors]; + +export type CallWithResponsesResponses = { + /** + * Message for 200 response + */ + 200: { + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; + readonly value?: Array; + }; + /** + * Message for 201 response + */ + 201: ModelThatExtends; + /** + * Message for 202 response + */ + 202: ModelThatExtendsExtends; +}; + +export type CallWithResponsesResponse = CallWithResponsesResponses[keyof CallWithResponsesResponses]; export type CollectionFormatData = { body?: never; @@ -1352,7 +1500,26 @@ export type TypesData = { }; }; -export type TypesResponse = number | string | boolean | {}; +export type TypesResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Response is a simple string + */ + 201: string; + /** + * Response is a simple boolean + */ + 202: boolean; + /** + * Response is a simple object + */ + 203: {}; +}; + +export type TypesResponse = TypesResponses[keyof TypesResponses]; export type UploadFileData = { body: Blob | File; @@ -1365,7 +1532,11 @@ export type UploadFileData = { query?: never; }; -export type UploadFileResponse = boolean; +export type UploadFileResponses = { + 200: boolean; +}; + +export type UploadFileResponse = UploadFileResponses[keyof UploadFileResponses]; export type FileResponseData = { body?: never; @@ -1379,7 +1550,14 @@ export type FileResponseData = { query?: never; }; -export type FileResponseResponse = Blob | File; +export type FileResponseResponses = { + /** + * Success + */ + 200: Blob | File; +}; + +export type FileResponseResponse = FileResponseResponses[keyof FileResponseResponses]; export type ComplexTypesData = { body?: never; @@ -1402,16 +1580,41 @@ export type ComplexTypesData = { }; }; -export type ComplexTypesResponse = Array; +export type ComplexTypesErrors = { + /** + * 400 `server` error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type ComplexTypesResponses = { + /** + * Successful response + */ + 200: Array; +}; -export type MultipartResponseResponse = { - file?: Blob | File; - metadata?: { - foo?: string; - bar?: string; +export type ComplexTypesResponse = ComplexTypesResponses[keyof ComplexTypesResponses]; + +export type MultipartResponseResponses = { + /** + * OK + */ + 200: { + file?: Blob | File; + metadata?: { + foo?: string; + bar?: string; + }; }; }; +export type MultipartResponseResponse = MultipartResponseResponses[keyof MultipartResponseResponses]; + export type MultipartRequestData = { body?: { content?: Blob | File; @@ -1443,7 +1646,32 @@ export type ComplexParamsData = { query?: never; }; -export type ComplexParamsResponse = ModelWithString; +export type ComplexParamsResponses = { + /** + * Success + */ + 200: ModelWithString; +}; + +export type ComplexParamsResponse = ComplexParamsResponses[keyof ComplexParamsResponses]; + +export type CallWithResultFromHeaderErrors = { + /** + * 400 server error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type CallWithResultFromHeaderResponses = { + /** + * Successful response + */ + 200: unknown; +}; export type TestErrorCodeData = { body?: never; @@ -1456,6 +1684,32 @@ export type TestErrorCodeData = { }; }; +export type TestErrorCodeErrors = { + /** + * Custom message: Internal Server Error + */ + 500: unknown; + /** + * Custom message: Not Implemented + */ + 501: unknown; + /** + * Custom message: Bad Gateway + */ + 502: unknown; + /** + * Custom message: Service Unavailable + */ + 503: unknown; +}; + +export type TestErrorCodeResponses = { + /** + * Custom message: Successful response + */ + 200: unknown; +}; + export type NonAsciiæøåÆøÅöôêÊ字符串Data = { body?: never; path?: never; @@ -1467,7 +1721,14 @@ export type NonAsciiæøåÆøÅöôêÊ字符串Data = { }; }; -export type NonAsciiæøåÆøÅöôêÊ字符串Response = Array; +export type NonAsciiæøåÆøÅöôêÊ字符串Responses = { + /** + * Successful response + */ + 200: Array; +}; + +export type NonAsciiæøåÆøÅöôêÊ字符串Response = NonAsciiæøåÆøÅöôêÊ字符串Responses[keyof NonAsciiæøåÆøÅöôêÊ字符串Responses]; export type PutWithFormUrlEncodedData = { body: ArrayWithStrings; 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 2f6b56c07..0478efcec 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 @@ -951,9 +951,27 @@ export type ImportData = { body: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; }; -export type ImportResponse = Model_From_Zendesk | ModelWithReadOnlyAndWriteOnly; +export type ImportResponses = { + /** + * Success + */ + 200: Model_From_Zendesk; + /** + * Default success response + */ + default: ModelWithReadOnlyAndWriteOnly; +}; + +export type ImportResponse = ImportResponses[keyof ImportResponses]; + +export type ApiVversionOdataControllerCountResponses = { + /** + * Success + */ + 200: Model_From_Zendesk; +}; -export type ApiVversionOdataControllerCountResponse = Model_From_Zendesk; +export type ApiVversionOdataControllerCountResponse = ApiVversionOdataControllerCountResponses[keyof ApiVversionOdataControllerCountResponses]; export type GetApiVbyApiVersionSimpleOperationData = { body?: never; @@ -966,9 +984,23 @@ export type GetApiVbyApiVersionSimpleOperationData = { query?: never; }; -export type GetApiVbyApiVersionSimpleOperationError = ModelWithBoolean; +export type GetApiVbyApiVersionSimpleOperationErrors = { + /** + * Default error response + */ + default: ModelWithBoolean; +}; -export type GetApiVbyApiVersionSimpleOperationResponse = number; +export type GetApiVbyApiVersionSimpleOperationError = GetApiVbyApiVersionSimpleOperationErrors[keyof GetApiVbyApiVersionSimpleOperationErrors]; + +export type GetApiVbyApiVersionSimpleOperationResponses = { + /** + * Response is a simple number + */ + 200: number; +}; + +export type GetApiVbyApiVersionSimpleOperationResponse = GetApiVbyApiVersionSimpleOperationResponses[keyof GetApiVbyApiVersionSimpleOperationResponses]; export type DeleteFooData3 = { body?: never; @@ -1140,7 +1172,18 @@ export type PostCallWithOptionalParamData = { }; }; -export type PostCallWithOptionalParamResponse = number | void; +export type PostCallWithOptionalParamResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; + +export type PostCallWithOptionalParamResponse = PostCallWithOptionalParamResponses[keyof PostCallWithOptionalParamResponses]; export type PostApiVbyApiVersionRequestBodyData = { /** @@ -1263,27 +1306,132 @@ export type CallToTestOrderOfParamsData = { }; }; -export type CallWithNoContentResponseResponse = void; +export type CallWithNoContentResponseResponses = { + /** + * Success + */ + 204: void; +}; -export type CallWithResponseAndNoContentResponseResponse = number | void; +export type CallWithNoContentResponseResponse = CallWithNoContentResponseResponses[keyof CallWithNoContentResponseResponses]; -export type DummyAResponse = _400; +export type CallWithResponseAndNoContentResponseResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; -export type DummyBResponse = void; +export type CallWithResponseAndNoContentResponseResponse = CallWithResponseAndNoContentResponseResponses[keyof CallWithResponseAndNoContentResponseResponses]; -export type CallWithResponseResponse = _import; +export type DummyAResponses = { + 200: _400; +}; -export type CallWithDuplicateResponsesError = ModelWithStringError | DictionaryWithArray | ModelWithBoolean; +export type DummyAResponse = DummyAResponses[keyof DummyAResponses]; -export type CallWithDuplicateResponsesResponse = (ModelWithBoolean & ModelWithInteger) | ModelWithString; +export type DummyBResponses = { + /** + * Success + */ + 204: void; +}; -export type CallWithResponsesError = ModelWithStringError; +export type DummyBResponse = DummyBResponses[keyof DummyBResponses]; -export type CallWithResponsesResponse = { - readonly '@namespace.string'?: string; - readonly '@namespace.integer'?: number; - readonly value?: Array; -} | ModelThatExtends | ModelThatExtendsExtends; +export type CallWithResponseResponses = { + default: _import; +}; + +export type CallWithResponseResponse = CallWithResponseResponses[keyof CallWithResponseResponses]; + +export type CallWithDuplicateResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for 4XX errors + */ + '4XX': DictionaryWithArray; + /** + * Default error response + */ + default: ModelWithBoolean; +}; + +export type CallWithDuplicateResponsesError = CallWithDuplicateResponsesErrors[keyof CallWithDuplicateResponsesErrors]; + +export type CallWithDuplicateResponsesResponses = { + /** + * Message for 200 response + */ + 200: ModelWithBoolean & ModelWithInteger; + /** + * Message for 201 response + */ + 201: ModelWithString; + /** + * Message for 202 response + */ + 202: ModelWithString; +}; + +export type CallWithDuplicateResponsesResponse = CallWithDuplicateResponsesResponses[keyof CallWithDuplicateResponsesResponses]; + +export type CallWithResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for default response + */ + default: ModelWithStringError; +}; + +export type CallWithResponsesError = CallWithResponsesErrors[keyof CallWithResponsesErrors]; + +export type CallWithResponsesResponses = { + /** + * Message for 200 response + */ + 200: { + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; + readonly value?: Array; + }; + /** + * Message for 201 response + */ + 201: ModelThatExtends; + /** + * Message for 202 response + */ + 202: ModelThatExtendsExtends; +}; + +export type CallWithResponsesResponse = CallWithResponsesResponses[keyof CallWithResponsesResponses]; export type CollectionFormatData = { body?: never; @@ -1352,7 +1500,26 @@ export type TypesData = { }; }; -export type TypesResponse = number | string | boolean | {}; +export type TypesResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Response is a simple string + */ + 201: string; + /** + * Response is a simple boolean + */ + 202: boolean; + /** + * Response is a simple object + */ + 203: {}; +}; + +export type TypesResponse = TypesResponses[keyof TypesResponses]; export type UploadFileData = { body: Blob | File; @@ -1365,7 +1532,11 @@ export type UploadFileData = { query?: never; }; -export type UploadFileResponse = boolean; +export type UploadFileResponses = { + 200: boolean; +}; + +export type UploadFileResponse = UploadFileResponses[keyof UploadFileResponses]; export type FileResponseData = { body?: never; @@ -1379,7 +1550,14 @@ export type FileResponseData = { query?: never; }; -export type FileResponseResponse = Blob | File; +export type FileResponseResponses = { + /** + * Success + */ + 200: Blob | File; +}; + +export type FileResponseResponse = FileResponseResponses[keyof FileResponseResponses]; export type ComplexTypesData = { body?: never; @@ -1402,16 +1580,41 @@ export type ComplexTypesData = { }; }; -export type ComplexTypesResponse = Array; +export type ComplexTypesErrors = { + /** + * 400 `server` error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type ComplexTypesResponses = { + /** + * Successful response + */ + 200: Array; +}; -export type MultipartResponseResponse = { - file?: Blob | File; - metadata?: { - foo?: string; - bar?: string; +export type ComplexTypesResponse = ComplexTypesResponses[keyof ComplexTypesResponses]; + +export type MultipartResponseResponses = { + /** + * OK + */ + 200: { + file?: Blob | File; + metadata?: { + foo?: string; + bar?: string; + }; }; }; +export type MultipartResponseResponse = MultipartResponseResponses[keyof MultipartResponseResponses]; + export type MultipartRequestData = { body?: { content?: Blob | File; @@ -1443,7 +1646,32 @@ export type ComplexParamsData = { query?: never; }; -export type ComplexParamsResponse = ModelWithString; +export type ComplexParamsResponses = { + /** + * Success + */ + 200: ModelWithString; +}; + +export type ComplexParamsResponse = ComplexParamsResponses[keyof ComplexParamsResponses]; + +export type CallWithResultFromHeaderErrors = { + /** + * 400 server error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type CallWithResultFromHeaderResponses = { + /** + * Successful response + */ + 200: unknown; +}; export type TestErrorCodeData = { body?: never; @@ -1456,6 +1684,32 @@ export type TestErrorCodeData = { }; }; +export type TestErrorCodeErrors = { + /** + * Custom message: Internal Server Error + */ + 500: unknown; + /** + * Custom message: Not Implemented + */ + 501: unknown; + /** + * Custom message: Bad Gateway + */ + 502: unknown; + /** + * Custom message: Service Unavailable + */ + 503: unknown; +}; + +export type TestErrorCodeResponses = { + /** + * Custom message: Successful response + */ + 200: unknown; +}; + export type NonAsciiæøåÆøÅöôêÊ字符串Data = { body?: never; path?: never; @@ -1467,7 +1721,14 @@ export type NonAsciiæøåÆøÅöôêÊ字符串Data = { }; }; -export type NonAsciiæøåÆøÅöôêÊ字符串Response = Array; +export type NonAsciiæøåÆøÅöôêÊ字符串Responses = { + /** + * Successful response + */ + 200: Array; +}; + +export type NonAsciiæøåÆøÅöôêÊ字符串Response = NonAsciiæøåÆøÅöôêÊ字符串Responses[keyof NonAsciiæøåÆøÅöôêÊ字符串Responses]; export type PutWithFormUrlEncodedData = { body: ArrayWithStrings; diff --git a/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/fastify/default/fastify.gen.ts b/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/fastify/default/fastify.gen.ts index 1729a59ed..b075b001e 100644 --- a/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/fastify/default/fastify.gen.ts +++ b/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/fastify/default/fastify.gen.ts @@ -1,981 +1,20 @@ // This file is auto-generated by @hey-api/openapi-ts +import type { ImportData, ImportResponses, ApiVversionOdataControllerCountResponses, GetApiVbyApiVersionSimpleOperationData, GetApiVbyApiVersionSimpleOperationErrors, GetApiVbyApiVersionSimpleOperationResponses, DeleteFooData3, CallWithDescriptionsData, DeprecatedCallData, CallWithParametersData, CallWithWeirdParameterNamesData, GetCallWithOptionalParamData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponses, PostApiVbyApiVersionRequestBodyData, PostApiVbyApiVersionFormDataData, CallWithDefaultParametersData, CallWithDefaultOptionalParametersData, CallToTestOrderOfParamsData, CallWithNoContentResponseResponses, CallWithResponseAndNoContentResponseResponses, DummyAResponses, DummyBResponses, CallWithResponseResponses, CallWithDuplicateResponsesErrors, CallWithDuplicateResponsesResponses, CallWithResponsesErrors, CallWithResponsesResponses, CollectionFormatData, TypesData, TypesResponses, UploadFileData, UploadFileResponses, FileResponseData, FileResponseResponses, ComplexTypesData, ComplexTypesErrors, ComplexTypesResponses, MultipartResponseResponses, MultipartRequestData, ComplexParamsData, ComplexParamsResponses, CallWithResultFromHeaderErrors, CallWithResultFromHeaderResponses, TestErrorCodeData, TestErrorCodeErrors, TestErrorCodeResponses, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Responses, PutWithFormUrlEncodedData } from './types.gen'; import type { RouteHandler } from 'fastify'; -import type { ImportData, GetApiVbyApiVersionSimpleOperationData, DeleteFooData3, CallWithDescriptionsData, DeprecatedCallData, CallWithParametersData, CallWithWeirdParameterNamesData, GetCallWithOptionalParamData, PostCallWithOptionalParamData, PostApiVbyApiVersionRequestBodyData, PostApiVbyApiVersionFormDataData, CallWithDefaultParametersData, CallWithDefaultOptionalParametersData, CallToTestOrderOfParamsData, CollectionFormatData, TypesData, UploadFileData, FileResponseData, ComplexTypesData, MultipartRequestData, ComplexParamsData, TestErrorCodeData, NonAsciiæøåÆøÅöôêÊ字符串Data, PutWithFormUrlEncodedData } from './types.gen'; - -/** - * Model with number-only name - */ -export type _400 = string; - -/** - * Testing multiline comments in string: First line - * Second line - * - * Fourth line - */ -export type camelCaseCommentWithBreaks = number; - -/** - * Testing multiline comments in string: First line - * Second line - * - * Fourth line - */ -export type CommentWithBreaks = number; - -/** - * Testing backticks in string: `backticks` and ```multiple backticks``` should work - */ -export type CommentWithBackticks = number; - -/** - * Testing backticks and quotes in string: `backticks`, 'quotes', "double quotes" and ```multiple backticks``` should work - */ -export type CommentWithBackticksAndQuotes = number; - -/** - * Testing slashes in string: \backwards\\\ and /forwards/// should work - */ -export type CommentWithSlashes = number; - -/** - * Testing expression placeholders in string: ${expression} should work - */ -export type CommentWithExpressionPlaceholders = number; - -/** - * Testing quotes in string: 'single quote''' and "double quotes""" should work - */ -export type CommentWithQuotes = number; - -/** - * Testing reserved characters in string: * inline * and ** inline ** should work - */ -export type CommentWithReservedCharacters = number; - -/** - * This is a simple number - */ -export type SimpleInteger = number; - -/** - * This is a simple boolean - */ -export type SimpleBoolean = boolean; - -/** - * This is a simple string - */ -export type SimpleString = string; - -/** - * A string with non-ascii (unicode) characters valid in typescript identifiers (æøåÆØÅöÔèÈ字符串) - */ -export type NonAsciiStringæøåÆØÅöôêÊ字符串 = string; - -/** - * This is a simple file - */ -export type SimpleFile = Blob | File; - -/** - * This is a simple reference - */ -export type SimpleReference = ModelWithString; - -/** - * This is a simple string - */ -export type SimpleStringWithPattern = string | null; - -/** - * This is a simple enum with strings - */ -export type EnumWithStrings = 'Success' | 'Warning' | 'Error' | "'Single Quote'" | '"Double Quotes"' | 'Non-ascii: øæåôöØÆÅÔÖ字符串'; - -export type EnumWithReplacedCharacters = "'Single Quote'" | '"Double Quotes"' | 'øæåôöØÆÅÔÖ字符串' | 3.1 | ''; - -/** - * This is a simple enum with numbers - */ -export type EnumWithNumbers = 1 | 2 | 3 | 1.1 | 1.2 | 1.3 | 100 | 200 | 300 | -100 | -200 | -300 | -1.1 | -1.2 | -1.3; - -/** - * Success=1,Warning=2,Error=3 - */ -export type EnumFromDescription = number; - -/** - * This is a simple enum with numbers - */ -export type EnumWithExtensions = 200 | 400 | 500; - -export type EnumWithXEnumNames = 0 | 1 | 2; - -/** - * This is a simple array with numbers - */ -export type ArrayWithNumbers = Array; - -/** - * This is a simple array with booleans - */ -export type ArrayWithBooleans = Array; - -/** - * This is a simple array with strings - */ -export type ArrayWithStrings = Array; - -/** - * This is a simple array with references - */ -export type ArrayWithReferences = Array; - -/** - * This is a simple array containing an array - */ -export type ArrayWithArray = Array>; - -/** - * This is a simple array with properties - */ -export type ArrayWithProperties = Array<{ - '16x16'?: camelCaseCommentWithBreaks; - bar?: string; -}>; - -/** - * This is a simple array with any of properties - */ -export type ArrayWithAnyOfProperties = Array<{ - foo?: string; -} | { - bar?: string; -}>; - -export type AnyOfAnyAndNull = { - data?: unknown | null; -}; - -/** - * This is a simple array with any of properties - */ -export type AnyOfArrays = { - results?: Array<{ - foo?: string; - } | { - bar?: string; - }>; -}; - -/** - * This is a string dictionary - */ -export type DictionaryWithString = { - [key: string]: string; -}; - -export type DictionaryWithPropertiesAndAdditionalProperties = { - foo?: number; - bar?: boolean; - [key: string]: string | number | boolean | undefined; -}; - -/** - * This is a string reference - */ -export type DictionaryWithReference = { - [key: string]: ModelWithString; -}; - -/** - * This is a complex dictionary - */ -export type DictionaryWithArray = { - [key: string]: Array; -}; - -/** - * This is a string dictionary - */ -export type DictionaryWithDictionary = { - [key: string]: { - [key: string]: string; - }; -}; - -/** - * This is a complex dictionary - */ -export type DictionaryWithProperties = { - [key: string]: { - foo?: string; - bar?: string; - }; -}; - -/** - * This is a model with one number property - */ -export type ModelWithInteger = { - /** - * This is a simple number property - */ - prop?: number; -}; - -/** - * This is a model with one boolean property - */ -export type ModelWithBoolean = { - /** - * This is a simple boolean property - */ - prop?: boolean; -}; - -/** - * This is a model with one string property - */ -export type ModelWithString = { - /** - * This is a simple string property - */ - prop?: string; -}; - -/** - * This is a model with one string property - */ -export type ModelWithStringError = { - /** - * This is a simple string property - */ - prop?: string; -}; - -/** - * `Comment` or `VoiceComment`. The JSON object for adding voice comments to tickets is different. See [Adding voice comments to tickets](/documentation/ticketing/managing-tickets/adding-voice-comments-to-tickets) - */ -export type Model_From_Zendesk = string; - -/** - * This is a model with one string property - */ -export type ModelWithNullableString = { - /** - * This is a simple string property - */ - nullableProp1?: string | null; - /** - * This is a simple string property - */ - nullableRequiredProp1: string | null; - /** - * This is a simple string property - */ - nullableProp2?: string | null; - /** - * This is a simple string property - */ - nullableRequiredProp2: string | null; - /** - * This is a simple enum with strings - */ - 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; -}; - -/** - * This is a model with one enum - */ -export type ModelWithEnum = { - /** - * This is a simple enum with strings - */ - 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; - /** - * These are the HTTP error code enums - */ - statusCode?: '100' | '200 FOO' | '300 FOO_BAR' | '400 foo-bar' | '500 foo.bar' | '600 foo&bar'; - /** - * Simple boolean enum - */ - bool?: true; -}; - -/** - * This is a model with one enum with escaped name - */ -export type ModelWithEnumWithHyphen = { - 'foo-bar-baz-qux'?: '3.0'; -}; - -/** - * This is a model with one enum - */ -export type ModelWithEnumFromDescription = { - /** - * Success=1,Warning=2,Error=3 - */ - test?: number; -}; - -/** - * This is a model with nested enums - */ -export type ModelWithNestedEnums = { - dictionaryWithEnum?: { - [key: string]: 'Success' | 'Warning' | 'Error'; - }; - dictionaryWithEnumFromDescription?: { - [key: string]: number; - }; - arrayWithEnum?: Array<'Success' | 'Warning' | 'Error'>; - arrayWithDescription?: Array; - /** - * This is a simple enum with strings - */ - 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; -}; - -/** - * This is a model with one property containing a reference - */ -export type ModelWithReference = { - prop?: ModelWithProperties; -}; - -/** - * This is a model with one property containing an array - */ -export type ModelWithArrayReadOnlyAndWriteOnly = { - prop?: Array; - propWithFile?: Array; - propWithNumber?: Array; -}; - -/** - * This is a model with one property containing an array - */ -export type ModelWithArray = { - prop?: Array; - propWithFile?: Array; - propWithNumber?: Array; -}; - -/** - * This is a model with one property containing a dictionary - */ -export type ModelWithDictionary = { - prop?: { - [key: string]: string; - }; -}; - -/** - * This is a deprecated model with a deprecated property - * @deprecated - */ -export type DeprecatedModel = { - /** - * This is a deprecated property - * @deprecated - */ - prop?: string; -}; - -/** - * This is a model with one property containing a circular reference - */ -export type ModelWithCircularReference = { - prop?: ModelWithCircularReference; -}; - -/** - * This is a model with one property with a 'one of' relationship - */ -export type CompositionWithOneOf = { - propA?: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; -}; - -/** - * This is a model with one property with a 'one of' relationship where the options are not $ref - */ -export type CompositionWithOneOfAnonymous = { - propA?: { - propA?: string; - } | string | number; -}; - -/** - * Circle - */ -export type ModelCircle = { - kind: string; - radius?: number; -}; - -/** - * Square - */ -export type ModelSquare = { - kind: string; - sideLength?: number; -}; - -/** - * This is a model with one property with a 'one of' relationship where the options are not $ref - */ -export type CompositionWithOneOfDiscriminator = ({ - kind?: 'circle'; -} & ModelCircle) | ({ - kind?: 'square'; -} & ModelSquare); - -/** - * This is a model with one property with a 'any of' relationship - */ -export type CompositionWithAnyOf = { - propA?: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; -}; - -/** - * This is a model with one property with a 'any of' relationship where the options are not $ref - */ -export type CompositionWithAnyOfAnonymous = { - propA?: { - propA?: string; - } | string | number; -}; - -/** - * This is a model with nested 'any of' property with a type null - */ -export type CompositionWithNestedAnyAndTypeNull = { - propA?: Array | Array; -}; - -export type _3e_num_1Период = 'Bird' | 'Dog'; - -export type ConstValue = 'ConstValue'; - -/** - * This is a model with one property with a 'any of' relationship where the options are not $ref - */ -export type CompositionWithNestedAnyOfAndNull = { - propA?: Array<_3e_num_1Период | ConstValue> | null; -}; - -/** - * This is a model with one property with a 'one of' relationship - */ -export type CompositionWithOneOfAndNullable = { - propA?: { - boolean?: boolean; - } | ModelWithEnum | ModelWithArray | ModelWithDictionary | null; -}; - -/** - * This is a model that contains a simple dictionary within composition - */ -export type CompositionWithOneOfAndSimpleDictionary = { - propA?: boolean | { - [key: string]: number; - }; -}; - -/** - * This is a model that contains a dictionary of simple arrays within composition - */ -export type CompositionWithOneOfAndSimpleArrayDictionary = { - propA?: boolean | { - [key: string]: Array; - }; -}; - -/** - * This is a model that contains a dictionary of complex arrays (composited) within composition - */ -export type CompositionWithOneOfAndComplexArrayDictionary = { - propA?: boolean | { - [key: string]: Array; - }; -}; - -/** - * This is a model with one property with a 'all of' relationship - */ -export type CompositionWithAllOfAndNullable = { - propA?: ({ - boolean?: boolean; - } & ModelWithEnum & ModelWithArray & ModelWithDictionary) | null; -}; - -/** - * This is a model with one property with a 'any of' relationship - */ -export type CompositionWithAnyOfAndNullable = { - propA?: { - boolean?: boolean; - } | ModelWithEnum | ModelWithArray | ModelWithDictionary | null; -}; - -/** - * This is a base model with two simple optional properties - */ -export type CompositionBaseModel = { - firstName?: string; - lastname?: string; -}; - -/** - * This is a model that extends the base model - */ -export type CompositionExtendedModel = CompositionBaseModel & { - age: number; - firstName: string; - lastname: string; -}; - -/** - * This is a model with one nested property - */ -export type ModelWithProperties = { - required: string; - readonly requiredAndReadOnly: string; - requiredAndNullable: string | null; - string?: string; - number?: number; - boolean?: boolean; - reference?: ModelWithString; - 'property with space'?: string; - default?: string; - try?: string; - readonly '@namespace.string'?: string; - readonly '@namespace.integer'?: number; -}; - -/** - * This is a model with one nested property - */ -export type ModelWithNestedProperties = { - readonly first: { - readonly second: { - readonly third: string | null; - } | null; - } | null; -}; - -/** - * This is a model with duplicated properties - */ -export type ModelWithDuplicateProperties = { - prop?: ModelWithString; -}; - -/** - * This is a model with ordered properties - */ -export type ModelWithOrderedProperties = { - zebra?: string; - apple?: string; - hawaii?: string; -}; - -/** - * This is a model with duplicated imports - */ -export type ModelWithDuplicateImports = { - propA?: ModelWithString; - propB?: ModelWithString; - propC?: ModelWithString; -}; - -/** - * This is a model that extends another model - */ -export type ModelThatExtends = ModelWithString & { - propExtendsA?: string; - propExtendsB?: ModelWithString; -}; - -/** - * This is a model that extends another model - */ -export type ModelThatExtendsExtends = ModelWithString & ModelThatExtends & { - propExtendsC?: string; - propExtendsD?: ModelWithString; -}; - -/** - * This is a model that contains a some patterns - */ -export type ModelWithPattern = { - key: string; - name: string; - readonly enabled?: boolean; - readonly modified?: string; - id?: string; - text?: string; - patternWithSingleQuotes?: string; - patternWithNewline?: string; - patternWithBacktick?: string; -}; - -export type File = { - readonly id?: string; - readonly updated_at?: string; - readonly created_at?: string; - mime: string; - readonly file?: string; -}; - -export type _default = { - name?: string; -}; - -export type Pageable = { - page?: number; - size?: number; - sort?: Array; -}; - -/** - * This is a free-form object without additionalProperties. - */ -export type FreeFormObjectWithoutAdditionalProperties = {}; - -/** - * This is a free-form object with additionalProperties: true. - */ -export type FreeFormObjectWithAdditionalPropertiesEqTrue = { - [key: string]: unknown; -}; - -/** - * This is a free-form object with additionalProperties: {}. - */ -export type FreeFormObjectWithAdditionalPropertiesEqEmptyObject = {}; - -export type ModelWithConst = { - String?: 'String'; - number?: 0; - null?: null; - withType?: 'Some string'; -}; - -/** - * This is a model with one property and additionalProperties: true - */ -export type ModelWithAdditionalPropertiesEqTrue = { - /** - * This is a simple string property - */ - prop?: string; - [key: string]: unknown | string | undefined; -}; - -export type NestedAnyOfArraysNullable = { - nullableArray?: Array | null; -}; - -export type CompositionWithOneOfAndProperties = ({ - foo: SimpleParameter; -} | { - bar: NonAsciiStringæøåÆØÅöôêÊ字符串; -}) & { - baz: number | null; - qux: number; -}; - -/** - * An object that can be null - */ -export type NullableObject = { - foo?: string; -} | null; - -/** - * Some % character - */ -export type CharactersInDescription = string; - -export type ModelWithNullableObject = { - data?: NullableObject; -}; - -export type ModelWithOneOfEnum = { - foo: 'Bar'; -} | { - foo: 'Baz'; -} | { - foo: 'Qux'; -} | { - content: string; - foo: 'Quux'; -} | { - content: [ - string, - string - ]; - foo: 'Corge'; -}; - -export type ModelWithNestedArrayEnumsDataFoo = 'foo' | 'bar'; - -export type ModelWithNestedArrayEnumsDataBar = 'baz' | 'qux'; - -export type ModelWithNestedArrayEnumsData = { - foo?: Array; - bar?: Array; -}; - -export type ModelWithNestedArrayEnums = { - array_strings?: Array; - data?: ModelWithNestedArrayEnumsData; -}; - -export type ModelWithNestedCompositionEnums = { - foo?: ModelWithNestedArrayEnumsDataFoo; -}; - -export type ModelWithReadOnlyAndWriteOnly = { - foo: string; - readonly bar: string; - baz: string; -}; - -export type ModelWithConstantSizeArray = [ - number, - number -]; - -export type ModelWithAnyOfConstantSizeArray = [ - number | string, - number | string, - number | string -]; - -export type ModelWithPrefixItemsConstantSizeArray = [ - ModelWithInteger, - number | string, - string -]; - -export type ModelWithAnyOfConstantSizeArrayNullable = [ - number | null | string, - number | null | string, - number | null | string -]; - -export type ModelWithAnyOfConstantSizeArrayWithNSizeAndOptions = [ - number | _import, - number | _import -]; - -export type ModelWithAnyOfConstantSizeArrayAndIntersect = [ - number & string, - number & string -]; - -export type ModelWithNumericEnumUnion = { - /** - * Период - */ - value?: -10 | -1 | 0 | 1 | 3 | 6 | 12; -}; - -/** - * Some description with `back ticks` - */ -export type ModelWithBackticksInDescription = { - /** - * The template `that` should be used for parsing and importing the contents of the CSV file. - * - *

There is one placeholder currently supported:

  • ${x} - refers to the n-th column in the CSV file, e.g. ${1}, ${2}, ...)

Example of a correct JSON template:

- *
-     * [
-     * {
-     * "resourceType": "Asset",
-     * "identifier": {
-     * "name": "${1}",
-     * "domain": {
-     * "name": "${2}",
-     * "community": {
-     * "name": "Some Community"
-     * }
-     * }
-     * },
-     * "attributes" : {
-     * "00000000-0000-0000-0000-000000003115" : [ {
-     * "value" : "${3}"
-     * } ],
-     * "00000000-0000-0000-0000-000000000222" : [ {
-     * "value" : "${4}"
-     * } ]
-     * }
-     * }
-     * ]
-     * 
- */ - template?: string; -}; - -export type ModelWithOneOfAndProperties = (SimpleParameter | NonAsciiStringæøåÆØÅöôêÊ字符串) & { - baz: number | null; - qux: number; -}; - -/** - * Model used to test deduplication strategy (unused) - */ -export type ParameterSimpleParameterUnused = string; - -/** - * Model used to test deduplication strategy - */ -export type PostServiceWithEmptyTagResponse = string; - -/** - * Model used to test deduplication strategy - */ -export type PostServiceWithEmptyTagResponse2 = string; - -/** - * Model used to test deduplication strategy - */ -export type DeleteFooData = string; - -/** - * Model used to test deduplication strategy - */ -export type DeleteFooData2 = string; - -/** - * Model with restricted keyword name - */ -export type _import = string; - -export type SchemaWithFormRestrictedKeys = { - description?: string; - 'x-enum-descriptions'?: string; - 'x-enum-varnames'?: string; - 'x-enumNames'?: string; - title?: string; - object?: { - description?: string; - 'x-enum-descriptions'?: string; - 'x-enum-varnames'?: string; - 'x-enumNames'?: string; - title?: string; - }; - array?: Array<{ - description?: string; - 'x-enum-descriptions'?: string; - 'x-enum-varnames'?: string; - 'x-enumNames'?: string; - title?: string; - }>; -}; - -/** - * This schema was giving PascalCase transformations a hard time - */ -export type io_k8s_apimachinery_pkg_apis_meta_v1_DeleteOptions = { - /** - * Must be fulfilled before a deletion is carried out. If not possible, a 409 Conflict status will be returned. - */ - preconditions?: io_k8s_apimachinery_pkg_apis_meta_v1_Preconditions; -}; - -/** - * This schema was giving PascalCase transformations a hard time - */ -export type io_k8s_apimachinery_pkg_apis_meta_v1_Preconditions = { - /** - * Specifies the target ResourceVersion - */ - resourceVersion?: string; - /** - * Specifies the target UID. - */ - uid?: string; -}; - -export type AdditionalPropertiesUnknownIssue = { - [key: string]: string | number; -}; - -export type AdditionalPropertiesUnknownIssue2 = { - [key: string]: string | number; -}; - -export type AdditionalPropertiesUnknownIssue3 = string & { - entries: { - [key: string]: AdditionalPropertiesUnknownIssue; - }; -}; - -export type AdditionalPropertiesIntegerIssue = { - value: number; - [key: string]: number; -}; - -export type OneOfAllOfIssue = ((ConstValue | Generic_Schema_Duplicate_Issue_1_System_Boolean_) & _3e_num_1Период) | Generic_Schema_Duplicate_Issue_1_System_String_; - -export type Generic_Schema_Duplicate_Issue_1_System_Boolean_ = { - item?: boolean; - error?: string | null; - readonly hasError?: boolean; - data?: { - [key: string]: never; - }; -}; - -export type Generic_Schema_Duplicate_Issue_1_System_String_ = { - item?: string | null; - error?: string | null; - readonly hasError?: boolean; -}; - -/** - * This is a reusable parameter - */ -export type SimpleParameter = string; - -/** - * Parameter with illegal characters - */ -export type x_Foo_Bar = ModelWithString; export type RouteHandlers = { - export: RouteHandler<{}>; import: RouteHandler<{ Body: ImportData['body']; - Reply: { - '200': Model_From_Zendesk; - }; + Reply: ImportResponses; }>; apiVVersionOdataControllerCount: RouteHandler<{ - Reply: { - '200': Model_From_Zendesk; - }; + Reply: ApiVversionOdataControllerCountResponses; }>; getApiVbyApiVersionSimpleOperation: RouteHandler<{ Params: GetApiVbyApiVersionSimpleOperationData['path']; - Reply: { - '200': number; - }; + Reply: GetApiVbyApiVersionSimpleOperationErrors & GetApiVbyApiVersionSimpleOperationResponses; }>; - deleteCallWithoutParametersAndResponse: RouteHandler<{}>; - getCallWithoutParametersAndResponse: RouteHandler<{}>; - headCallWithoutParametersAndResponse: RouteHandler<{}>; - optionsCallWithoutParametersAndResponse: RouteHandler<{}>; - patchCallWithoutParametersAndResponse: RouteHandler<{}>; - postCallWithoutParametersAndResponse: RouteHandler<{}>; - putCallWithoutParametersAndResponse: RouteHandler<{}>; deleteFoo: RouteHandler<{ Headers: DeleteFooData3['headers']; Params: DeleteFooData3['path']; @@ -1005,10 +44,7 @@ export type RouteHandlers = { postCallWithOptionalParam: RouteHandler<{ Body: PostCallWithOptionalParamData['body']; Querystring: PostCallWithOptionalParamData['query']; - Reply: { - '200': number; - '204': void; - }; + Reply: PostCallWithOptionalParamResponses; }>; postApiVbyApiVersionRequestBody: RouteHandler<{ Body: PostApiVbyApiVersionRequestBodyData['body']; @@ -1027,58 +63,26 @@ export type RouteHandlers = { callToTestOrderOfParams: RouteHandler<{ Querystring: CallToTestOrderOfParamsData['query']; }>; - duplicateName: RouteHandler<{}>; - duplicateName2: RouteHandler<{}>; - duplicateName3: RouteHandler<{}>; - duplicateName4: RouteHandler<{}>; callWithNoContentResponse: RouteHandler<{ - Reply: { - '204': void; - }; + Reply: CallWithNoContentResponseResponses; }>; callWithResponseAndNoContentResponse: RouteHandler<{ - Reply: { - '200': number; - '204': void; - }; + Reply: CallWithResponseAndNoContentResponseResponses; }>; dummyA: RouteHandler<{ - Reply: { - '200': _400; - }; + Reply: DummyAResponses; }>; dummyB: RouteHandler<{ - Reply: { - '204': void; - }; + Reply: DummyBResponses; }>; callWithResponse: RouteHandler<{ - Reply: {}; + Reply: CallWithResponseResponses; }>; callWithDuplicateResponses: RouteHandler<{ - Reply: { - '200': ModelWithBoolean & ModelWithInteger; - '201': ModelWithString; - '202': ModelWithString; - '500': ModelWithStringError; - '501': ModelWithStringError; - '502': ModelWithStringError; - '4XX': DictionaryWithArray; - }; + Reply: CallWithDuplicateResponsesErrors & CallWithDuplicateResponsesResponses; }>; callWithResponses: RouteHandler<{ - Reply: { - '200': { - readonly '@namespace.string'?: string; - readonly '@namespace.integer'?: number; - readonly value?: Array; - }; - '201': ModelThatExtends; - '202': ModelThatExtendsExtends; - '500': ModelWithStringError; - '501': ModelWithStringError; - '502': ModelWithStringError; - }; + Reply: CallWithResponsesErrors & CallWithResponsesResponses; }>; collectionFormat: RouteHandler<{ Querystring: CollectionFormatData['query']; @@ -1086,44 +90,23 @@ export type RouteHandlers = { types: RouteHandler<{ Params?: TypesData['path']; Querystring: TypesData['query']; - Reply: { - '200': number; - '201': string; - '202': boolean; - '203': {}; - }; + Reply: TypesResponses; }>; uploadFile: RouteHandler<{ Body: UploadFileData['body']; Params: UploadFileData['path']; - Reply: { - '200': boolean; - }; + Reply: UploadFileResponses; }>; fileResponse: RouteHandler<{ Params: FileResponseData['path']; - Reply: { - '200': Blob | File; - }; + Reply: FileResponseResponses; }>; complexTypes: RouteHandler<{ Querystring: ComplexTypesData['query']; - Reply: { - '200': Array; - '400': unknown; - '500': unknown; - }; + Reply: ComplexTypesErrors & ComplexTypesResponses; }>; multipartResponse: RouteHandler<{ - Reply: { - '200': { - file?: Blob | File; - metadata?: { - foo?: string; - bar?: string; - }; - }; - }; + Reply: MultipartResponseResponses; }>; multipartRequest: RouteHandler<{ Body: MultipartRequestData['body']; @@ -1131,32 +114,18 @@ export type RouteHandlers = { complexParams: RouteHandler<{ Body: ComplexParamsData['body']; Params: ComplexParamsData['path']; - Reply: { - '200': ModelWithString; - }; + Reply: ComplexParamsResponses; }>; callWithResultFromHeader: RouteHandler<{ - Reply: { - '200': unknown; - '400': unknown; - '500': unknown; - }; + Reply: CallWithResultFromHeaderErrors & CallWithResultFromHeaderResponses; }>; testErrorCode: RouteHandler<{ Querystring: TestErrorCodeData['query']; - Reply: { - '200': unknown; - '500': unknown; - '501': unknown; - '502': unknown; - '503': unknown; - }; + Reply: TestErrorCodeErrors & TestErrorCodeResponses; }>; nonAsciiæøåÆøÅöôêÊ字符串: RouteHandler<{ Querystring: NonAsciiæøåÆøÅöôêÊ字符串Data['query']; - Reply: { - '200': Array; - }; + Reply: NonAsciiæøåÆøÅöôêÊ字符串Responses; }>; putWithFormUrlEncoded: RouteHandler<{ Body: PutWithFormUrlEncodedData['body']; 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 2f6b56c07..0478efcec 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 @@ -951,9 +951,27 @@ export type ImportData = { body: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; }; -export type ImportResponse = Model_From_Zendesk | ModelWithReadOnlyAndWriteOnly; +export type ImportResponses = { + /** + * Success + */ + 200: Model_From_Zendesk; + /** + * Default success response + */ + default: ModelWithReadOnlyAndWriteOnly; +}; + +export type ImportResponse = ImportResponses[keyof ImportResponses]; + +export type ApiVversionOdataControllerCountResponses = { + /** + * Success + */ + 200: Model_From_Zendesk; +}; -export type ApiVversionOdataControllerCountResponse = Model_From_Zendesk; +export type ApiVversionOdataControllerCountResponse = ApiVversionOdataControllerCountResponses[keyof ApiVversionOdataControllerCountResponses]; export type GetApiVbyApiVersionSimpleOperationData = { body?: never; @@ -966,9 +984,23 @@ export type GetApiVbyApiVersionSimpleOperationData = { query?: never; }; -export type GetApiVbyApiVersionSimpleOperationError = ModelWithBoolean; +export type GetApiVbyApiVersionSimpleOperationErrors = { + /** + * Default error response + */ + default: ModelWithBoolean; +}; -export type GetApiVbyApiVersionSimpleOperationResponse = number; +export type GetApiVbyApiVersionSimpleOperationError = GetApiVbyApiVersionSimpleOperationErrors[keyof GetApiVbyApiVersionSimpleOperationErrors]; + +export type GetApiVbyApiVersionSimpleOperationResponses = { + /** + * Response is a simple number + */ + 200: number; +}; + +export type GetApiVbyApiVersionSimpleOperationResponse = GetApiVbyApiVersionSimpleOperationResponses[keyof GetApiVbyApiVersionSimpleOperationResponses]; export type DeleteFooData3 = { body?: never; @@ -1140,7 +1172,18 @@ export type PostCallWithOptionalParamData = { }; }; -export type PostCallWithOptionalParamResponse = number | void; +export type PostCallWithOptionalParamResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; + +export type PostCallWithOptionalParamResponse = PostCallWithOptionalParamResponses[keyof PostCallWithOptionalParamResponses]; export type PostApiVbyApiVersionRequestBodyData = { /** @@ -1263,27 +1306,132 @@ export type CallToTestOrderOfParamsData = { }; }; -export type CallWithNoContentResponseResponse = void; +export type CallWithNoContentResponseResponses = { + /** + * Success + */ + 204: void; +}; -export type CallWithResponseAndNoContentResponseResponse = number | void; +export type CallWithNoContentResponseResponse = CallWithNoContentResponseResponses[keyof CallWithNoContentResponseResponses]; -export type DummyAResponse = _400; +export type CallWithResponseAndNoContentResponseResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; -export type DummyBResponse = void; +export type CallWithResponseAndNoContentResponseResponse = CallWithResponseAndNoContentResponseResponses[keyof CallWithResponseAndNoContentResponseResponses]; -export type CallWithResponseResponse = _import; +export type DummyAResponses = { + 200: _400; +}; -export type CallWithDuplicateResponsesError = ModelWithStringError | DictionaryWithArray | ModelWithBoolean; +export type DummyAResponse = DummyAResponses[keyof DummyAResponses]; -export type CallWithDuplicateResponsesResponse = (ModelWithBoolean & ModelWithInteger) | ModelWithString; +export type DummyBResponses = { + /** + * Success + */ + 204: void; +}; -export type CallWithResponsesError = ModelWithStringError; +export type DummyBResponse = DummyBResponses[keyof DummyBResponses]; -export type CallWithResponsesResponse = { - readonly '@namespace.string'?: string; - readonly '@namespace.integer'?: number; - readonly value?: Array; -} | ModelThatExtends | ModelThatExtendsExtends; +export type CallWithResponseResponses = { + default: _import; +}; + +export type CallWithResponseResponse = CallWithResponseResponses[keyof CallWithResponseResponses]; + +export type CallWithDuplicateResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for 4XX errors + */ + '4XX': DictionaryWithArray; + /** + * Default error response + */ + default: ModelWithBoolean; +}; + +export type CallWithDuplicateResponsesError = CallWithDuplicateResponsesErrors[keyof CallWithDuplicateResponsesErrors]; + +export type CallWithDuplicateResponsesResponses = { + /** + * Message for 200 response + */ + 200: ModelWithBoolean & ModelWithInteger; + /** + * Message for 201 response + */ + 201: ModelWithString; + /** + * Message for 202 response + */ + 202: ModelWithString; +}; + +export type CallWithDuplicateResponsesResponse = CallWithDuplicateResponsesResponses[keyof CallWithDuplicateResponsesResponses]; + +export type CallWithResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for default response + */ + default: ModelWithStringError; +}; + +export type CallWithResponsesError = CallWithResponsesErrors[keyof CallWithResponsesErrors]; + +export type CallWithResponsesResponses = { + /** + * Message for 200 response + */ + 200: { + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; + readonly value?: Array; + }; + /** + * Message for 201 response + */ + 201: ModelThatExtends; + /** + * Message for 202 response + */ + 202: ModelThatExtendsExtends; +}; + +export type CallWithResponsesResponse = CallWithResponsesResponses[keyof CallWithResponsesResponses]; export type CollectionFormatData = { body?: never; @@ -1352,7 +1500,26 @@ export type TypesData = { }; }; -export type TypesResponse = number | string | boolean | {}; +export type TypesResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Response is a simple string + */ + 201: string; + /** + * Response is a simple boolean + */ + 202: boolean; + /** + * Response is a simple object + */ + 203: {}; +}; + +export type TypesResponse = TypesResponses[keyof TypesResponses]; export type UploadFileData = { body: Blob | File; @@ -1365,7 +1532,11 @@ export type UploadFileData = { query?: never; }; -export type UploadFileResponse = boolean; +export type UploadFileResponses = { + 200: boolean; +}; + +export type UploadFileResponse = UploadFileResponses[keyof UploadFileResponses]; export type FileResponseData = { body?: never; @@ -1379,7 +1550,14 @@ export type FileResponseData = { query?: never; }; -export type FileResponseResponse = Blob | File; +export type FileResponseResponses = { + /** + * Success + */ + 200: Blob | File; +}; + +export type FileResponseResponse = FileResponseResponses[keyof FileResponseResponses]; export type ComplexTypesData = { body?: never; @@ -1402,16 +1580,41 @@ export type ComplexTypesData = { }; }; -export type ComplexTypesResponse = Array; +export type ComplexTypesErrors = { + /** + * 400 `server` error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type ComplexTypesResponses = { + /** + * Successful response + */ + 200: Array; +}; -export type MultipartResponseResponse = { - file?: Blob | File; - metadata?: { - foo?: string; - bar?: string; +export type ComplexTypesResponse = ComplexTypesResponses[keyof ComplexTypesResponses]; + +export type MultipartResponseResponses = { + /** + * OK + */ + 200: { + file?: Blob | File; + metadata?: { + foo?: string; + bar?: string; + }; }; }; +export type MultipartResponseResponse = MultipartResponseResponses[keyof MultipartResponseResponses]; + export type MultipartRequestData = { body?: { content?: Blob | File; @@ -1443,7 +1646,32 @@ export type ComplexParamsData = { query?: never; }; -export type ComplexParamsResponse = ModelWithString; +export type ComplexParamsResponses = { + /** + * Success + */ + 200: ModelWithString; +}; + +export type ComplexParamsResponse = ComplexParamsResponses[keyof ComplexParamsResponses]; + +export type CallWithResultFromHeaderErrors = { + /** + * 400 server error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type CallWithResultFromHeaderResponses = { + /** + * Successful response + */ + 200: unknown; +}; export type TestErrorCodeData = { body?: never; @@ -1456,6 +1684,32 @@ export type TestErrorCodeData = { }; }; +export type TestErrorCodeErrors = { + /** + * Custom message: Internal Server Error + */ + 500: unknown; + /** + * Custom message: Not Implemented + */ + 501: unknown; + /** + * Custom message: Bad Gateway + */ + 502: unknown; + /** + * Custom message: Service Unavailable + */ + 503: unknown; +}; + +export type TestErrorCodeResponses = { + /** + * Custom message: Successful response + */ + 200: unknown; +}; + export type NonAsciiæøåÆøÅöôêÊ字符串Data = { body?: never; path?: never; @@ -1467,7 +1721,14 @@ export type NonAsciiæøåÆøÅöôêÊ字符串Data = { }; }; -export type NonAsciiæøåÆøÅöôêÊ字符串Response = Array; +export type NonAsciiæøåÆøÅöôêÊ字符串Responses = { + /** + * Successful response + */ + 200: Array; +}; + +export type NonAsciiæøåÆøÅöôêÊ字符串Response = NonAsciiæøåÆøÅöôêÊ字符串Responses[keyof NonAsciiæøåÆøÅöôêÊ字符串Responses]; export type PutWithFormUrlEncodedData = { body: ArrayWithStrings; -- 2.51.2 From cebf327046c801b375846bae6b07561b8ad1bdd6 Mon Sep 17 00:00:00 2001 From: Lubos Date: Sun, 17 Nov 2024 17:20:09 +0800 Subject: [PATCH 09/13] chore: document types update --- .changeset/fast-dolls-pull.md | 5 +++++ .../src/plugins/@hey-api/services/plugin.ts | 4 ++-- .../plugins/@hey-api/transformers/plugin.ts | 22 +++++-------------- 3 files changed, 13 insertions(+), 18 deletions(-) create mode 100644 .changeset/fast-dolls-pull.md diff --git a/.changeset/fast-dolls-pull.md b/.changeset/fast-dolls-pull.md new file mode 100644 index 000000000..4cf58171b --- /dev/null +++ b/.changeset/fast-dolls-pull.md @@ -0,0 +1,5 @@ +--- +'@hey-api/openapi-ts': patch +--- + +fix: export a map of error and response types by status code diff --git a/packages/openapi-ts/src/plugins/@hey-api/services/plugin.ts b/packages/openapi-ts/src/plugins/@hey-api/services/plugin.ts index 3bb234391..b84b202a8 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/services/plugin.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/services/plugin.ts @@ -19,7 +19,7 @@ import { getServiceName } from '../../../utils/postprocess'; import { irRef } from '../../../utils/ref'; import { transformServiceName } from '../../../utils/transform'; import type { PluginHandler } from '../../types'; -import { operationResponseTransformerRef } from '../transformers/plugin'; +import { operationTransformerIrRef } from '../transformers/plugin'; import { operationOptionsType, serviceFunctionIdentifier, @@ -139,7 +139,7 @@ const requestOptions = ({ const fileTransformers = context.file({ id: 'transformers' }); if (fileTransformers) { const identifier = fileTransformers.identifier({ - $ref: operationResponseTransformerRef({ id: operation.id }), + $ref: operationTransformerIrRef({ id: operation.id, type: 'response' }), namespace: 'value', }); if (identifier.name) { diff --git a/packages/openapi-ts/src/plugins/@hey-api/transformers/plugin.ts b/packages/openapi-ts/src/plugins/@hey-api/transformers/plugin.ts index b57793e82..d04d4f794 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/transformers/plugin.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/transformers/plugin.ts @@ -21,7 +21,7 @@ interface OperationIRRef { id: string; } -const operationTransformerIrRef = ({ +export const operationTransformerIrRef = ({ id, type, }: OperationIRRef & { @@ -46,19 +46,6 @@ const operationTransformerIrRef = ({ })}${affix}`; }; -// TODO: parser - currently unused -export const operationDataTransformerRef = ({ id }: OperationIRRef): string => - operationTransformerIrRef({ id, type: 'data' }); - -// TODO: parser - currently unused -export const operationErrorTransformerRef = ({ id }: OperationIRRef): string => - operationTransformerIrRef({ id, type: 'error' }); - -export const operationResponseTransformerRef = ({ - id, -}: OperationIRRef): string => - operationTransformerIrRef({ id, type: 'response' }); - const schemaIrRef = ({ $ref, type, @@ -394,7 +381,7 @@ export const handler: PluginHandler = ({ context, plugin }) => { } let identifierResponseTransformer = file.identifier({ - $ref: operationResponseTransformerRef({ id: operation.id }), + $ref: operationTransformerIrRef({ id: operation.id, type: 'response' }), create: true, namespace: 'value', }); @@ -442,7 +429,10 @@ export const handler: PluginHandler = ({ context, plugin }) => { // the created schema response transformer was empty, do not generate // it and prevent any future attempts identifierResponseTransformer = file.blockIdentifier({ - $ref: operationResponseTransformerRef({ id: operation.id }), + $ref: operationTransformerIrRef({ + id: operation.id, + type: 'response', + }), namespace: 'value', }); } -- 2.51.2 From 4a939d165ffbcff15aec244c40cd7039a4cba718 Mon Sep 17 00:00:00 2001 From: Lubos Date: Sun, 17 Nov 2024 17:27:52 +0800 Subject: [PATCH 10/13] chore: revert context argument --- .../src/plugins/@hey-api/types/plugin.ts | 746 +++++++++++++++++- .../plugins/@tanstack/query-core/plugin.ts | 10 +- .../openapi-ts/src/plugins/utils/types.ts | 683 ---------------- 3 files changed, 721 insertions(+), 718 deletions(-) delete mode 100644 packages/openapi-ts/src/plugins/utils/types.ts diff --git a/packages/openapi-ts/src/plugins/@hey-api/types/plugin.ts b/packages/openapi-ts/src/plugins/@hey-api/types/plugin.ts index e15bf1c0e..5278e701f 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/types/plugin.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/types/plugin.ts @@ -1,5 +1,6 @@ import ts from 'typescript'; +import type { Property } from '../../../compiler'; import { compiler } from '../../../compiler'; import type { IRContext } from '../../../ir/context'; import type { @@ -11,12 +12,603 @@ import type { } from '../../../ir/ir'; import { operationResponsesMap } from '../../../ir/operation'; import { deduplicateSchema } from '../../../ir/schema'; +import { ensureValidTypeScriptJavaScriptIdentifier } from '../../../openApi'; +import { escapeComment } from '../../../utils/escape'; +import { irRef, isRefOpenApiComponent } from '../../../utils/ref'; import type { PluginHandler } from '../../types'; -import { schemaToType, type SchemaToTypeOptions } from '../../utils/types'; import { operationIrRef } from '../services/plugin'; import type { Config } from './types'; -export const typesId = 'types'; +interface SchemaWithType['type']> + extends Omit { + type: Extract['type'], T>; +} + +const typesId = 'types'; + +const digitsRegExp = /^\d+$/; + +const parseSchemaJsDoc = ({ schema }: { schema: IRSchemaObject }) => { + const comments = [ + schema.description && escapeComment(schema.description), + schema.deprecated && '@deprecated', + ]; + return comments; +}; + +const addJavaScriptEnum = ({ + $ref, + context, + schema, +}: { + $ref: string; + context: IRContext; + schema: SchemaWithType<'enum'>; +}) => { + const identifier = context.file({ id: typesId })!.identifier({ + $ref, + create: true, + namespace: 'value', + }); + + // TODO: parser - this is the old parser behavior where we would NOT + // print nested enum identifiers if they already exist. This is a + // blocker for referencing these identifiers within the file as + // we cannot guarantee just because they have a duplicate identifier, + // they have a duplicate value. + if (!identifier.created) { + return; + } + + const enumObject = schemaToEnumObject({ schema }); + + const expression = compiler.objectExpression({ + multiLine: true, + obj: enumObject.obj, + }); + const node = compiler.constVariable({ + assertion: 'const', + comment: parseSchemaJsDoc({ schema }), + exportConst: true, + expression, + name: identifier.name || '', + }); + return node; +}; + +const schemaToEnumObject = ({ schema }: { schema: IRSchemaObject }) => { + const typeofItems: Array< + | 'string' + | 'number' + | 'bigint' + | 'boolean' + | 'symbol' + | 'undefined' + | 'object' + | 'function' + > = []; + + const obj = (schema.items ?? []).map((item) => { + const typeOfItemConst = typeof item.const; + + if (!typeofItems.includes(typeOfItemConst)) { + typeofItems.push(typeOfItemConst); + } + + let key; + if (item.title) { + key = item.title; + } else if (typeOfItemConst === 'number') { + key = `_${item.const}`; + } else if (typeOfItemConst === 'boolean') { + const valid = typeOfItemConst ? 'true' : 'false'; + key = valid.toLocaleUpperCase(); + } else { + let valid = ensureValidTypeScriptJavaScriptIdentifier( + item.const as string, + ); + if (!valid) { + // TODO: parser - abstract empty string handling + valid = 'empty_string'; + } + key = valid.toLocaleUpperCase(); + } + return { + comments: parseSchemaJsDoc({ schema: item }), + key, + value: item.const, + }; + }); + + return { + obj, + typeofItems, + }; +}; + +const addTypeEnum = ({ + $ref, + context, + schema, +}: { + $ref: string; + context: IRContext; + schema: SchemaWithType<'enum'>; +}) => { + const identifier = context.file({ id: typesId })!.identifier({ + $ref, + create: true, + namespace: 'type', + }); + + // TODO: parser - this is the old parser behavior where we would NOT + // print nested enum identifiers if they already exist. This is a + // blocker for referencing these identifiers within the file as + // we cannot guarantee just because they have a duplicate identifier, + // they have a duplicate value. + if ( + !identifier.created && + !isRefOpenApiComponent($ref) && + context.config.plugins['@hey-api/types']?.enums !== 'typescript+namespace' + ) { + return; + } + + const node = compiler.typeAliasDeclaration({ + comment: parseSchemaJsDoc({ schema }), + exportType: true, + name: identifier.name || '', + type: schemaToType({ + context, + schema: { + ...schema, + type: undefined, + }, + }), + }); + return node; +}; + +const addTypeScriptEnum = ({ + $ref, + context, + schema, +}: { + $ref: string; + context: IRContext; + schema: SchemaWithType<'enum'>; +}) => { + const identifier = context.file({ id: typesId })!.identifier({ + $ref, + create: true, + namespace: 'value', + }); + + // TODO: parser - this is the old parser behavior where we would NOT + // print nested enum identifiers if they already exist. This is a + // blocker for referencing these identifiers within the file as + // we cannot guarantee just because they have a duplicate identifier, + // they have a duplicate value. + if ( + !identifier.created && + context.config.plugins['@hey-api/types']?.enums !== 'typescript+namespace' + ) { + return; + } + + const enumObject = schemaToEnumObject({ schema }); + + // TypeScript enums support only string and number values so we need to fallback to types + if ( + enumObject.typeofItems.filter( + (type) => type !== 'number' && type !== 'string', + ).length + ) { + const node = addTypeEnum({ + $ref, + context, + schema, + }); + return node; + } + + const node = compiler.enumDeclaration({ + leadingComment: parseSchemaJsDoc({ schema }), + name: identifier.name || '', + obj: enumObject.obj, + }); + return node; +}; + +const arrayTypeToIdentifier = ({ + context, + namespace, + schema, +}: { + context: IRContext; + namespace: Array; + schema: SchemaWithType<'array'>; +}) => { + if (!schema.items) { + return compiler.typeArrayNode( + compiler.keywordTypeNode({ + keyword: 'unknown', + }), + ); + } + + schema = deduplicateSchema({ schema }); + + // at least one item is guaranteed + const itemTypes = schema.items!.map((item) => + schemaToType({ + context, + namespace, + schema: item, + }), + ); + + if (itemTypes.length === 1) { + return compiler.typeArrayNode(itemTypes[0]); + } + + if (schema.logicalOperator === 'and') { + return compiler.typeArrayNode( + compiler.typeIntersectionNode({ types: itemTypes }), + ); + } + + return compiler.typeArrayNode(compiler.typeUnionNode({ types: itemTypes })); +}; + +const booleanTypeToIdentifier = ({ + schema, +}: { + context: IRContext; + namespace: Array; + schema: SchemaWithType<'boolean'>; +}) => { + if (schema.const !== undefined) { + return compiler.literalTypeNode({ + literal: compiler.ots.boolean(schema.const as boolean), + }); + } + + return compiler.keywordTypeNode({ + keyword: 'boolean', + }); +}; + +const enumTypeToIdentifier = ({ + $ref, + context, + namespace, + schema, +}: { + $ref?: string; + context: IRContext; + namespace: Array; + schema: SchemaWithType<'enum'>; +}): ts.TypeNode => { + // TODO: parser - add option to inline enums + if ($ref) { + const isRefComponent = isRefOpenApiComponent($ref); + + // when enums are disabled (default), emit only reusable components + // as types, otherwise the output would be broken if we skipped all enums + if (!context.config.plugins['@hey-api/types']?.enums && isRefComponent) { + const typeNode = addTypeEnum({ + $ref, + context, + schema, + }); + if (typeNode) { + context.file({ id: typesId })!.add(typeNode); + } + } + + if (context.config.plugins['@hey-api/types']?.enums === 'javascript') { + const typeNode = addTypeEnum({ + $ref, + context, + schema, + }); + if (typeNode) { + context.file({ id: typesId })!.add(typeNode); + } + + const objectNode = addJavaScriptEnum({ + $ref, + context, + schema, + }); + if (objectNode) { + context.file({ id: typesId })!.add(objectNode); + } + } + + if (context.config.plugins['@hey-api/types']?.enums === 'typescript') { + const enumNode = addTypeScriptEnum({ + $ref, + context, + schema, + }); + if (enumNode) { + context.file({ id: typesId })!.add(enumNode); + } + } + + if ( + context.config.plugins['@hey-api/types']?.enums === 'typescript+namespace' + ) { + const enumNode = addTypeScriptEnum({ + $ref, + context, + schema, + }); + if (enumNode) { + if (isRefComponent) { + context.file({ id: typesId })!.add(enumNode); + } else { + // emit enum inside TypeScript namespace + namespace.push(enumNode); + } + } + } + } + + const type = schemaToType({ + context, + schema: { + ...schema, + type: undefined, + }, + }); + return type; +}; + +const numberTypeToIdentifier = ({ + schema, +}: { + context: IRContext; + namespace: Array; + schema: SchemaWithType<'number'>; +}) => { + if (schema.const !== undefined) { + return compiler.literalTypeNode({ + literal: compiler.ots.number(schema.const as number), + }); + } + + return compiler.keywordTypeNode({ + keyword: 'number', + }); +}; + +const objectTypeToIdentifier = ({ + context, + namespace, + schema, +}: { + context: IRContext; + namespace: Array; + schema: SchemaWithType<'object'>; +}) => { + let indexProperty: Property | undefined; + const schemaProperties: Array = []; + let indexPropertyItems: Array = []; + const required = schema.required ?? []; + let hasOptionalProperties = false; + + for (const name in schema.properties) { + const property = schema.properties[name]; + const isRequired = required.includes(name); + digitsRegExp.lastIndex = 0; + schemaProperties.push({ + comment: parseSchemaJsDoc({ schema: property }), + isReadOnly: property.accessScope === 'read', + isRequired, + name: digitsRegExp.test(name) + ? ts.factory.createNumericLiteral(name) + : name, + type: schemaToType({ + $ref: `${irRef}${name}`, + context, + namespace, + schema: property, + }), + }); + indexPropertyItems.push(property); + + if (!isRequired) { + hasOptionalProperties = true; + } + } + + if ( + schema.additionalProperties && + (schema.additionalProperties.type !== 'never' || !indexPropertyItems.length) + ) { + if (schema.additionalProperties.type === 'never') { + indexPropertyItems = [schema.additionalProperties]; + } else { + indexPropertyItems.unshift(schema.additionalProperties); + } + + if (hasOptionalProperties) { + indexPropertyItems.push({ + type: 'undefined', + }); + } + + indexProperty = { + isRequired: true, + name: 'key', + type: schemaToType({ + context, + namespace, + schema: + indexPropertyItems.length === 1 + ? indexPropertyItems[0] + : { + items: indexPropertyItems, + logicalOperator: 'or', + }, + }), + }; + } + + return compiler.typeInterfaceNode({ + indexProperty, + properties: schemaProperties, + useLegacyResolution: false, + }); +}; + +const stringTypeToIdentifier = ({ + context, + schema, +}: { + context: IRContext; + namespace: Array; + schema: SchemaWithType<'string'>; +}) => { + if (schema.const !== undefined) { + return compiler.literalTypeNode({ + literal: compiler.stringLiteral({ text: schema.const as string }), + }); + } + + if (schema.format) { + if (schema.format === 'binary') { + return compiler.typeUnionNode({ + types: [ + compiler.typeReferenceNode({ + typeName: 'Blob', + }), + compiler.typeReferenceNode({ + typeName: 'File', + }), + ], + }); + } + + if (schema.format === 'date-time' || schema.format === 'date') { + // TODO: parser - add ability to skip type transformers + if (context.config.plugins['@hey-api/transformers']?.dates) { + return compiler.typeReferenceNode({ typeName: 'Date' }); + } + } + } + + return compiler.keywordTypeNode({ + keyword: 'string', + }); +}; + +const tupleTypeToIdentifier = ({ + context, + namespace, + schema, +}: { + context: IRContext; + namespace: Array; + schema: SchemaWithType<'tuple'>; +}) => { + const itemTypes: Array = []; + + for (const item of schema.items ?? []) { + itemTypes.push( + schemaToType({ + context, + namespace, + schema: item, + }), + ); + } + + return compiler.typeTupleNode({ + types: itemTypes, + }); +}; + +const schemaTypeToIdentifier = ({ + $ref, + context, + namespace, + schema, +}: { + $ref?: string; + context: IRContext; + namespace: Array; + schema: IRSchemaObject; +}): ts.TypeNode => { + switch (schema.type as Required['type']) { + case 'array': + return arrayTypeToIdentifier({ + context, + namespace, + schema: schema as SchemaWithType<'array'>, + }); + case 'boolean': + return booleanTypeToIdentifier({ + context, + namespace, + schema: schema as SchemaWithType<'boolean'>, + }); + case 'enum': + return enumTypeToIdentifier({ + $ref, + context, + namespace, + schema: schema as SchemaWithType<'enum'>, + }); + case 'never': + return compiler.keywordTypeNode({ + keyword: 'never', + }); + case 'null': + return compiler.literalTypeNode({ + literal: compiler.null(), + }); + case 'number': + return numberTypeToIdentifier({ + context, + namespace, + schema: schema as SchemaWithType<'number'>, + }); + case 'object': + return objectTypeToIdentifier({ + context, + namespace, + schema: schema as SchemaWithType<'object'>, + }); + case 'string': + return stringTypeToIdentifier({ + context, + namespace, + schema: schema as SchemaWithType<'string'>, + }); + case 'tuple': + return tupleTypeToIdentifier({ + context, + namespace, + schema: schema as SchemaWithType<'tuple'>, + }); + case 'undefined': + return compiler.keywordTypeNode({ + keyword: 'undefined', + }); + case 'unknown': + return compiler.keywordTypeNode({ + keyword: 'unknown', + }); + case 'void': + return compiler.keywordTypeNode({ + keyword: 'void', + }); + } +}; const irParametersToIrSchema = ({ parameters, @@ -56,11 +648,9 @@ const irParametersToIrSchema = ({ const operationToDataType = ({ context, operation, - options, }: { context: IRContext; operation: IROperationObject; - options: SchemaToTypeOptions; }) => { const data: IRSchemaObject = { type: 'object', @@ -143,7 +733,7 @@ const operationToDataType = ({ exportType: true, name: identifier.name || '', type: schemaToType({ - options, + context, schema: data, }), }); @@ -154,16 +744,13 @@ const operationToDataType = ({ const operationToType = ({ context, operation, - options, }: { context: IRContext; operation: IROperationObject; - options: SchemaToTypeOptions; }) => { operationToDataType({ context, operation, - options, }); const file = context.file({ id: typesId })!; @@ -182,7 +769,7 @@ const operationToType = ({ exportType: true, name: identifierErrors.name, type: schemaToType({ - options, + context, schema: errors, }), }); @@ -227,7 +814,7 @@ const operationToType = ({ exportType: true, name: identifierResponses.name, type: schemaToType({ - options, + context, schema: responses, }), }); @@ -262,38 +849,144 @@ const operationToType = ({ } }; +export const schemaToType = ({ + $ref, + context, + namespace = [], + schema, +}: { + $ref?: string; + context: IRContext; + namespace?: Array; + schema: IRSchemaObject; +}): ts.TypeNode => { + let type: ts.TypeNode | undefined; + + if (schema.$ref) { + const identifier = context.file({ id: typesId })!.identifier({ + $ref: schema.$ref, + create: true, + namespace: 'type', + }); + type = compiler.typeReferenceNode({ + typeName: identifier.name || '', + }); + } else if (schema.type) { + type = schemaTypeToIdentifier({ + $ref, + context, + namespace, + schema, + }); + } else if (schema.items) { + schema = deduplicateSchema({ schema }); + if (schema.items) { + const itemTypes = schema.items.map((item) => + schemaToType({ + context, + namespace, + schema: item, + }), + ); + type = + schema.logicalOperator === 'and' + ? compiler.typeIntersectionNode({ types: itemTypes }) + : compiler.typeUnionNode({ types: itemTypes }); + } else { + type = schemaToType({ + context, + namespace, + schema, + }); + } + } else { + // catch-all fallback for failed schemas + type = schemaTypeToIdentifier({ + context, + namespace, + schema: { + type: 'unknown', + }, + }); + } + + // emit nodes only if $ref points to a reusable component + if ($ref && isRefOpenApiComponent($ref)) { + // emit namespace if it has any members + if (namespace.length) { + const identifier = context.file({ id: typesId })!.identifier({ + $ref, + create: true, + namespace: 'value', + }); + const node = compiler.namespaceDeclaration({ + name: identifier.name || '', + statements: namespace, + }); + context.file({ id: typesId })!.add(node); + } + + // enum handler emits its own artifacts + if (schema.type !== 'enum') { + const identifier = context.file({ id: typesId })!.identifier({ + $ref, + create: true, + namespace: 'type', + }); + const node = compiler.typeAliasDeclaration({ + comment: parseSchemaJsDoc({ schema }), + exportType: true, + name: identifier.name || '', + type, + }); + context.file({ id: typesId })!.add(node); + } + } + + return type; +}; + export const handler: PluginHandler = ({ context, plugin }) => { - const file = context.createFile({ + context.createFile({ id: typesId, path: plugin.output, }); - const options: SchemaToTypeOptions = { - enums: context.config.plugins['@hey-api/types']?.enums, - file, - useTransformersDate: context.config.plugins['@hey-api/transformers']?.dates, - }; if (context.ir.components) { for (const name in context.ir.components.schemas) { const schema = context.ir.components.schemas[name]; const $ref = `#/components/schemas/${name}`; - schemaToType({ - $ref, - options, - schema, - }); + try { + schemaToType({ + $ref, + context, + schema, + }); + } catch (error) { + console.error( + `🔥 Failed to process schema ${name}\n$ref: ${$ref}\nschema: ${JSON.stringify(schema, null, 2)}`, + ); + throw error; + } } for (const name in context.ir.components.parameters) { const parameter = context.ir.components.parameters[name]; const $ref = `#/components/parameters/${name}`; - schemaToType({ - $ref, - options, - schema: parameter.schema, - }); + try { + schemaToType({ + $ref, + context, + schema: parameter.schema, + }); + } catch (error) { + console.error( + `🔥 Failed to process schema ${name}\n$ref: ${$ref}\nschema: ${JSON.stringify(parameter.schema, null, 2)}`, + ); + throw error; + } } } @@ -314,7 +1007,6 @@ export const handler: PluginHandler = ({ context, plugin }) => { operationToType({ context, operation, - options, }); } } diff --git a/packages/openapi-ts/src/plugins/@tanstack/query-core/plugin.ts b/packages/openapi-ts/src/plugins/@tanstack/query-core/plugin.ts index de8fcab55..5f9d45a7b 100644 --- a/packages/openapi-ts/src/plugins/@tanstack/query-core/plugin.ts +++ b/packages/openapi-ts/src/plugins/@tanstack/query-core/plugin.ts @@ -29,9 +29,8 @@ import { operationOptionsType, serviceFunctionIdentifier, } from '../../@hey-api/services/plugin-legacy'; -import { typesId } from '../../@hey-api/types/plugin'; +import { schemaToType } from '../../@hey-api/types/plugin'; import type { PluginHandler } from '../../types'; -import { schemaToType } from '../../utils/types'; import type { Config as AngularQueryConfig } from '../angular-query-experimental'; import type { Config as ReactQueryConfig } from '../react-query'; import type { Config as SolidQueryConfig } from '../solid-query'; @@ -891,12 +890,7 @@ export const handler: PluginHandler< // `compiler.returnFunctionCall()` accepts only strings, should be cleaned up const typePageParam = `${tsNodeToString({ node: schemaToType({ - options: { - enums: context.config.plugins['@hey-api/types']?.enums, - file: context.file({ id: typesId })!, - useTransformersDate: - context.config.plugins['@hey-api/transformers']?.dates, - }, + context, schema: pagination.schema, }), unescape: true, diff --git a/packages/openapi-ts/src/plugins/utils/types.ts b/packages/openapi-ts/src/plugins/utils/types.ts deleted file mode 100644 index b4067fb18..000000000 --- a/packages/openapi-ts/src/plugins/utils/types.ts +++ /dev/null @@ -1,683 +0,0 @@ -import ts from 'typescript'; - -import type { Property } from '../../compiler'; -import { compiler } from '../../compiler'; -import type { TypeScriptFile } from '../../generate/files'; -import type { IRSchemaObject } from '../../ir/ir'; -import { deduplicateSchema } from '../../ir/schema'; -import { ensureValidTypeScriptJavaScriptIdentifier } from '../../openApi'; -import { escapeComment } from '../../utils/escape'; -import { irRef, isRefOpenApiComponent } from '../../utils/ref'; - -export type SchemaToTypeOptions = { - enums?: 'javascript' | 'typescript' | 'typescript+namespace' | false; - file: TypeScriptFile; - useTransformersDate?: boolean; -}; - -interface SchemaWithType['type']> - extends Omit { - type: Extract['type'], T>; -} - -const parseSchemaJsDoc = ({ schema }: { schema: IRSchemaObject }) => { - const comments = [ - schema.description && escapeComment(schema.description), - schema.deprecated && '@deprecated', - ]; - return comments; -}; - -const addJavaScriptEnum = ({ - $ref, - schema, - options, -}: { - $ref: string; - options: SchemaToTypeOptions; - schema: SchemaWithType<'enum'>; -}) => { - const identifier = options.file.identifier({ - $ref, - create: true, - namespace: 'value', - }); - - // TODO: parser - this is the old parser behavior where we would NOT - // print nested enum identifiers if they already exist. This is a - // blocker for referencing these identifiers within the file as - // we cannot guarantee just because they have a duplicate identifier, - // they have a duplicate value. - if (!identifier.created) { - return; - } - - const enumObject = schemaToEnumObject({ schema }); - - const expression = compiler.objectExpression({ - multiLine: true, - obj: enumObject.obj, - }); - const node = compiler.constVariable({ - assertion: 'const', - comment: parseSchemaJsDoc({ schema }), - exportConst: true, - expression, - name: identifier.name || '', - }); - return node; -}; - -const schemaToEnumObject = ({ schema }: { schema: IRSchemaObject }) => { - const typeofItems: Array< - | 'string' - | 'number' - | 'bigint' - | 'boolean' - | 'symbol' - | 'undefined' - | 'object' - | 'function' - > = []; - - const obj = (schema.items ?? []).map((item) => { - const typeOfItemConst = typeof item.const; - - if (!typeofItems.includes(typeOfItemConst)) { - typeofItems.push(typeOfItemConst); - } - - let key; - if (item.title) { - key = item.title; - } else if (typeOfItemConst === 'number') { - key = `_${item.const}`; - } else if (typeOfItemConst === 'boolean') { - const valid = typeOfItemConst ? 'true' : 'false'; - key = valid.toLocaleUpperCase(); - } else { - let valid = ensureValidTypeScriptJavaScriptIdentifier( - item.const as string, - ); - if (!valid) { - // TODO: parser - abstract empty string handling - valid = 'empty_string'; - } - key = valid.toLocaleUpperCase(); - } - return { - comments: parseSchemaJsDoc({ schema: item }), - key, - value: item.const, - }; - }); - - return { - obj, - typeofItems, - }; -}; - -const addTypeEnum = ({ - $ref, - schema, - options, -}: { - $ref: string; - options: SchemaToTypeOptions; - schema: SchemaWithType<'enum'>; -}) => { - const identifier = options.file.identifier({ - $ref, - create: true, - namespace: 'type', - }); - - // TODO: parser - this is the old parser behavior where we would NOT - // print nested enum identifiers if they already exist. This is a - // blocker for referencing these identifiers within the file as - // we cannot guarantee just because they have a duplicate identifier, - // they have a duplicate value. - if ( - !identifier.created && - !isRefOpenApiComponent($ref) && - options.enums !== 'typescript+namespace' - ) { - return; - } - - const node = compiler.typeAliasDeclaration({ - comment: parseSchemaJsDoc({ schema }), - exportType: true, - name: identifier.name || '', - type: schemaToType({ - options, - schema: { - ...schema, - type: undefined, - }, - }), - }); - return node; -}; - -const addTypeScriptEnum = ({ - $ref, - schema, - options, -}: { - $ref: string; - options: SchemaToTypeOptions; - schema: SchemaWithType<'enum'>; -}) => { - const identifier = options.file.identifier({ - $ref, - create: true, - namespace: 'value', - }); - - // TODO: parser - this is the old parser behavior where we would NOT - // print nested enum identifiers if they already exist. This is a - // blocker for referencing these identifiers within the file as - // we cannot guarantee just because they have a duplicate identifier, - // they have a duplicate value. - if (!identifier.created && options.enums !== 'typescript+namespace') { - return; - } - - const enumObject = schemaToEnumObject({ schema }); - - // TypeScript enums support only string and number values so we need to fallback to types - if ( - enumObject.typeofItems.filter( - (type) => type !== 'number' && type !== 'string', - ).length - ) { - const node = addTypeEnum({ - $ref, - options, - schema, - }); - return node; - } - - const node = compiler.enumDeclaration({ - leadingComment: parseSchemaJsDoc({ schema }), - name: identifier.name || '', - obj: enumObject.obj, - }); - return node; -}; - -const arrayTypeToIdentifier = ({ - namespace, - schema, - options, -}: { - namespace: Array; - options: SchemaToTypeOptions; - schema: SchemaWithType<'array'>; -}) => { - if (!schema.items) { - return compiler.typeArrayNode( - compiler.keywordTypeNode({ - keyword: 'unknown', - }), - ); - } - - schema = deduplicateSchema({ schema }); - - // at least one item is guaranteed - const itemTypes = schema.items!.map((item) => - schemaToType({ - namespace, - options, - schema: item, - }), - ); - - if (itemTypes.length === 1) { - return compiler.typeArrayNode(itemTypes[0]); - } - - if (schema.logicalOperator === 'and') { - return compiler.typeArrayNode( - compiler.typeIntersectionNode({ types: itemTypes }), - ); - } - - return compiler.typeArrayNode(compiler.typeUnionNode({ types: itemTypes })); -}; - -const booleanTypeToIdentifier = ({ - schema, -}: { - schema: SchemaWithType<'boolean'>; -}) => { - if (schema.const !== undefined) { - return compiler.literalTypeNode({ - literal: compiler.ots.boolean(schema.const as boolean), - }); - } - - return compiler.keywordTypeNode({ - keyword: 'boolean', - }); -}; - -const enumTypeToIdentifier = ({ - $ref, - namespace, - schema, - options, -}: { - $ref?: string; - namespace: Array; - options: SchemaToTypeOptions; - schema: SchemaWithType<'enum'>; -}): ts.TypeNode => { - // TODO: parser - add option to inline enums - if ($ref) { - const isRefComponent = isRefOpenApiComponent($ref); - - // when enums are disabled (default), emit only reusable components - // as types, otherwise the output would be broken if we skipped all enums - if (!options.enums && isRefComponent) { - const typeNode = addTypeEnum({ - $ref, - options, - schema, - }); - if (typeNode) { - options.file.add(typeNode); - } - } - - if (options.enums === 'javascript') { - const typeNode = addTypeEnum({ - $ref, - options, - schema, - }); - if (typeNode) { - options.file.add(typeNode); - } - - const objectNode = addJavaScriptEnum({ - $ref, - options, - schema, - }); - if (objectNode) { - options.file.add(objectNode); - } - } - - if (options.enums === 'typescript') { - const enumNode = addTypeScriptEnum({ - $ref, - options, - schema, - }); - if (enumNode) { - options.file.add(enumNode); - } - } - - if (options.enums === 'typescript+namespace') { - const enumNode = addTypeScriptEnum({ - $ref, - options, - schema, - }); - if (enumNode) { - if (isRefComponent) { - options.file.add(enumNode); - } else { - // emit enum inside TypeScript namespace - namespace.push(enumNode); - } - } - } - } - - const type = schemaToType({ - options, - schema: { - ...schema, - type: undefined, - }, - }); - return type; -}; - -const numberTypeToIdentifier = ({ - schema, -}: { - schema: SchemaWithType<'number'>; -}) => { - if (schema.const !== undefined) { - return compiler.literalTypeNode({ - literal: compiler.ots.number(schema.const as number), - }); - } - - return compiler.keywordTypeNode({ - keyword: 'number', - }); -}; - -const digitsRegExp = /^\d+$/; - -const objectTypeToIdentifier = ({ - namespace, - schema, - options, -}: { - namespace: Array; - options: SchemaToTypeOptions; - schema: SchemaWithType<'object'>; -}) => { - let indexProperty: Property | undefined; - const schemaProperties: Array = []; - let indexPropertyItems: Array = []; - const required = schema.required ?? []; - let hasOptionalProperties = false; - - for (const name in schema.properties) { - const property = schema.properties[name]; - const isRequired = required.includes(name); - digitsRegExp.lastIndex = 0; - schemaProperties.push({ - comment: parseSchemaJsDoc({ schema: property }), - isReadOnly: property.accessScope === 'read', - isRequired, - name: digitsRegExp.test(name) - ? ts.factory.createNumericLiteral(name) - : name, - type: schemaToType({ - $ref: `${irRef}${name}`, - namespace, - options, - schema: property, - }), - }); - indexPropertyItems.push(property); - - if (!isRequired) { - hasOptionalProperties = true; - } - } - - if ( - schema.additionalProperties && - (schema.additionalProperties.type !== 'never' || !indexPropertyItems.length) - ) { - if (schema.additionalProperties.type === 'never') { - indexPropertyItems = [schema.additionalProperties]; - } else { - indexPropertyItems.unshift(schema.additionalProperties); - } - - if (hasOptionalProperties) { - indexPropertyItems.push({ - type: 'undefined', - }); - } - - indexProperty = { - isRequired: true, - name: 'key', - type: schemaToType({ - namespace, - options, - schema: - indexPropertyItems.length === 1 - ? indexPropertyItems[0] - : { - items: indexPropertyItems, - logicalOperator: 'or', - }, - }), - }; - } - - return compiler.typeInterfaceNode({ - indexProperty, - properties: schemaProperties, - useLegacyResolution: false, - }); -}; - -const stringTypeToIdentifier = ({ - schema, - options, -}: { - options: SchemaToTypeOptions; - schema: SchemaWithType<'string'>; -}) => { - if (schema.const !== undefined) { - return compiler.literalTypeNode({ - literal: compiler.stringLiteral({ text: schema.const as string }), - }); - } - - if (schema.format) { - if (schema.format === 'binary') { - return compiler.typeUnionNode({ - types: [ - compiler.typeReferenceNode({ - typeName: 'Blob', - }), - compiler.typeReferenceNode({ - typeName: 'File', - }), - ], - }); - } - - if (schema.format === 'date-time' || schema.format === 'date') { - // TODO: parser - add ability to skip type transformers - if (options.useTransformersDate) { - return compiler.typeReferenceNode({ typeName: 'Date' }); - } - } - } - - return compiler.keywordTypeNode({ - keyword: 'string', - }); -}; - -const tupleTypeToIdentifier = ({ - namespace, - schema, - options, -}: { - namespace: Array; - options: SchemaToTypeOptions; - schema: SchemaWithType<'tuple'>; -}) => { - const itemTypes: Array = []; - - for (const item of schema.items ?? []) { - itemTypes.push( - schemaToType({ - namespace, - options, - schema: item, - }), - ); - } - - return compiler.typeTupleNode({ - types: itemTypes, - }); -}; - -const schemaTypeToIdentifier = ({ - $ref, - namespace, - schema, - options, -}: { - $ref?: string; - namespace: Array; - options: SchemaToTypeOptions; - schema: IRSchemaObject; -}): ts.TypeNode => { - switch (schema.type as Required['type']) { - case 'array': - return arrayTypeToIdentifier({ - namespace, - options, - schema: schema as SchemaWithType<'array'>, - }); - case 'boolean': - return booleanTypeToIdentifier({ - schema: schema as SchemaWithType<'boolean'>, - }); - case 'enum': - return enumTypeToIdentifier({ - $ref, - namespace, - options, - schema: schema as SchemaWithType<'enum'>, - }); - case 'never': - return compiler.keywordTypeNode({ keyword: 'never' }); - case 'null': - return compiler.literalTypeNode({ - literal: compiler.null(), - }); - case 'number': - return numberTypeToIdentifier({ - schema: schema as SchemaWithType<'number'>, - }); - case 'object': - return objectTypeToIdentifier({ - namespace, - options, - schema: schema as SchemaWithType<'object'>, - }); - case 'string': - return stringTypeToIdentifier({ - options, - schema: schema as SchemaWithType<'string'>, - }); - case 'tuple': - return tupleTypeToIdentifier({ - namespace, - options, - schema: schema as SchemaWithType<'tuple'>, - }); - case 'undefined': - return compiler.keywordTypeNode({ keyword: 'undefined' }); - case 'unknown': - return compiler.keywordTypeNode({ - keyword: 'unknown', - }); - case 'void': - return compiler.keywordTypeNode({ - keyword: 'void', - }); - } -}; - -export const schemaToType = ({ - $ref, - namespace = [], - schema, - options, -}: { - $ref?: string; - namespace?: Array; - options: SchemaToTypeOptions; - schema: IRSchemaObject; -}): ts.TypeNode => { - let type: ts.TypeNode | undefined; - - if (schema.$ref) { - const identifier = options.file.identifier({ - $ref: schema.$ref, - create: true, - namespace: 'type', - }); - type = compiler.typeReferenceNode({ - typeName: identifier.name || '', - }); - } else if (schema.type) { - type = schemaTypeToIdentifier({ - $ref, - namespace, - options, - schema, - }); - } else if (schema.items) { - schema = deduplicateSchema({ schema }); - if (schema.items) { - const itemTypes = schema.items.map((item) => - schemaToType({ - namespace, - options, - schema: item, - }), - ); - type = - schema.logicalOperator === 'and' - ? compiler.typeIntersectionNode({ types: itemTypes }) - : compiler.typeUnionNode({ types: itemTypes }); - } else { - type = schemaToType({ - namespace, - options, - schema, - }); - } - } else { - // catch-all fallback for failed schemas - type = schemaTypeToIdentifier({ - namespace, - options, - schema: { - type: 'unknown', - }, - }); - } - - // emit nodes only if $ref points to a reusable component - if ($ref && isRefOpenApiComponent($ref)) { - // emit namespace if it has any members - if (namespace.length) { - const identifier = options.file.identifier({ - $ref, - create: true, - namespace: 'value', - }); - const node = compiler.namespaceDeclaration({ - name: identifier.name || '', - statements: namespace, - }); - options.file.add(node); - } - - // enum handler emits its own artifacts - if (schema.type !== 'enum') { - const identifier = options.file.identifier({ - $ref, - create: true, - namespace: 'type', - }); - const node = compiler.typeAliasDeclaration({ - comment: parseSchemaJsDoc({ schema }), - exportType: true, - name: identifier.name || '', - type, - }); - options.file.add(node); - } - } - - return type; -}; -- 2.51.2 From 8a15a35e86ff22eca85dc218bc1793315b934556 Mon Sep 17 00:00:00 2001 From: Lubos Date: Sun, 17 Nov 2024 19:34:44 +0800 Subject: [PATCH 11/13] chore: remove fastify dependency on services --- .changeset/honest-rings-obey.md | 5 + packages/openapi-ts/src/index.ts | 28 +- packages/openapi-ts/src/ir/context.ts | 13 +- .../src/openApi/3.0.x/parser/operation.ts | 7 +- .../src/openApi/3.1.x/parser/operation.ts | 7 +- .../src/openApi/__tests__/index.spec.ts | 33 +- .../src/openApi/common/parser/operation.ts | 81 ++++ packages/openapi-ts/src/openApi/config.ts | 103 ----- packages/openapi-ts/src/openApi/index.ts | 15 +- .../src/openApi/shared/utils/operation.ts | 39 ++ .../v2/parser/getOperationParameter.ts | 6 +- .../v2/parser/getOperationParameters.ts | 6 +- .../src/openApi/v2/parser/getOperations.ts | 10 +- .../src/openApi/v2/parser/operation.ts | 10 +- .../src/openApi/v3/parser/getModels.ts | 6 - .../v3/parser/getOperationParameter.ts | 6 +- .../v3/parser/getOperationParameters.ts | 6 +- .../src/openApi/v3/parser/getOperations.ts | 10 +- .../src/openApi/v3/parser/operation.ts | 10 +- .../src/plugins/@hey-api/types/plugin.ts | 28 +- .../src/plugins/@hey-api/types/types.d.ts | 2 + .../openapi-ts/src/plugins/fastify/config.ts | 2 +- .../src/utils/__tests__/parse.spec.ts | 2 +- .../src/utils/__tests__/postprocess.spec.ts | 25 +- .../3.0.x/plugins/fastify/default/index.ts | 3 +- .../plugins/fastify/default/services.gen.ts | 382 ------------------ .../3.1.x/plugins/fastify/default/index.ts | 3 +- .../plugins/fastify/default/services.gen.ts | 382 ------------------ packages/openapi-ts/test/sample.cjs | 1 + 29 files changed, 198 insertions(+), 1033 deletions(-) create mode 100644 .changeset/honest-rings-obey.md delete mode 100644 packages/openapi-ts/src/openApi/config.ts create mode 100644 packages/openapi-ts/src/openApi/shared/utils/operation.ts delete mode 100644 packages/openapi-ts/test/__snapshots__/3.0.x/plugins/fastify/default/services.gen.ts delete mode 100644 packages/openapi-ts/test/__snapshots__/3.1.x/plugins/fastify/default/services.gen.ts diff --git a/.changeset/honest-rings-obey.md b/.changeset/honest-rings-obey.md new file mode 100644 index 000000000..c2c39265c --- /dev/null +++ b/.changeset/honest-rings-obey.md @@ -0,0 +1,5 @@ +--- +'@hey-api/openapi-ts': patch +--- + +fix: deprecate types.tree option diff --git a/packages/openapi-ts/src/index.ts b/packages/openapi-ts/src/index.ts index 0aaae14b6..c11f5a597 100644 --- a/packages/openapi-ts/src/index.ts +++ b/packages/openapi-ts/src/index.ts @@ -8,13 +8,6 @@ import { sync } from 'cross-spawn'; import { generateLegacyOutput, generateOutput } from './generate/output'; import type { IRContext } from './ir/context'; import { parseExperimental, parseLegacy } from './openApi'; -import type { ParserConfig } from './openApi/config'; -import { - operationFilterFn, - operationNameFn, - operationParameterFilterFn, - operationParameterNameFn, -} from './openApi/config'; import type { ClientPlugins } from './plugins'; import { defaultPluginConfigs } from './plugins'; import type { DefaultPluginConfigsMap, PluginNames } from './plugins/types'; @@ -413,34 +406,17 @@ export async function createClient( let context: IRContext | undefined; Performance.start('parser'); - const parserConfig: ParserConfig = { - filterFn: { - operation: operationFilterFn, - operationParameter: operationParameterFilterFn, - }, - nameFn: { - operation: operationNameFn, - operationParameter: operationParameterNameFn, - }, - }; if ( config.experimentalParser && !isLegacyClient(config) && !legacyNameFromConfig(config) ) { - context = parseExperimental({ - config, - parserConfig, - spec, - }); + context = parseExperimental({ config, spec }); } // fallback to legacy parser if (!context) { - const parsed = parseLegacy({ - openApi: spec, - parserConfig, - }); + const parsed = parseLegacy({ openApi: spec }); client = postProcessClient(parsed); } Performance.end('parser'); diff --git a/packages/openapi-ts/src/ir/context.ts b/packages/openapi-ts/src/ir/context.ts index 3fb2fafe3..4267fdbef 100644 --- a/packages/openapi-ts/src/ir/context.ts +++ b/packages/openapi-ts/src/ir/context.ts @@ -1,7 +1,6 @@ import path from 'node:path'; import { TypeScriptFile } from '../generate/files'; -import type { ParserConfig } from '../openApi/config'; import type { Config } from '../types/config'; import type { Files } from '../types/utils'; import { resolveRef } from '../utils/ref'; @@ -34,25 +33,15 @@ export class IRContext = any> { * Intermediate representation model obtained from `spec`. */ public ir: IR; - public parserConfig: ParserConfig; /** * Resolved specification from `input`. */ public spec: Spec; - constructor({ - config, - parserConfig, - spec, - }: { - config: Config; - parserConfig: ParserConfig; - spec: Spec; - }) { + constructor({ config, spec }: { config: Config; spec: Spec }) { this.config = config; this.files = {}; this.ir = {}; - this.parserConfig = parserConfig; this.spec = spec; } 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 94df2da3c..5e76d44e9 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 @@ -1,5 +1,6 @@ import type { IRContext } from '../../../ir/context'; import type { IROperationObject, IRPathsObject } from '../../../ir/ir'; +import { operationToId } from '../../shared/utils/operation'; import type { OperationObject, PathItemObject, @@ -205,10 +206,10 @@ export const parseOperation = ({ context.ir.paths[path] = {}; } - operation.id = context.parserConfig.nameFn.operation({ - config: context.config, + operation.id = operationToId({ + context, + id: operation.operationId, method, - operationId: operation.operationId, path, }); 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 18951b2ab..856dde7af 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 @@ -1,5 +1,6 @@ import type { IRContext } from '../../../ir/context'; import type { IROperationObject, IRPathsObject } from '../../../ir/ir'; +import { operationToId } from '../../shared/utils/operation'; import type { OperationObject, PathItemObject, @@ -193,10 +194,10 @@ export const parseOperation = ({ context.ir.paths[path] = {}; } - operation.id = context.parserConfig.nameFn.operation({ - config: context.config, + operation.id = operationToId({ + context, + id: operation.operationId, method, - operationId: operation.operationId, path, }); diff --git a/packages/openapi-ts/src/openApi/__tests__/index.spec.ts b/packages/openapi-ts/src/openApi/__tests__/index.spec.ts index a7575e815..4f749310e 100644 --- a/packages/openapi-ts/src/openApi/__tests__/index.spec.ts +++ b/packages/openapi-ts/src/openApi/__tests__/index.spec.ts @@ -5,7 +5,6 @@ import type { OpenApiV3_0_X } from '../3.0.x'; import { parseV3_0_X } from '../3.0.x'; import type { OpenApiV3_1_X } from '../3.1.x'; import { parseV3_1_X } from '../3.1.x'; -import type { ParserConfig } from '../config'; import * as parseV2 from '../v2'; import * as parseV3 from '../v3'; @@ -16,17 +15,6 @@ vi.mock('../3.1.x', () => ({ parseV3_1_X: vi.fn(), })); -const parserConfig: ParserConfig = { - filterFn: { - operation: () => true, - operationParameter: () => true, - }, - nameFn: { - operation: () => 'operation', - operationParameter: () => 'operationParameter', - }, -}; - describe('parse', () => { afterEach(() => { vi.restoreAllMocks(); @@ -43,7 +31,7 @@ describe('parse', () => { paths: {}, swagger: '2', }; - parseLegacy({ openApi: spec, parserConfig }); + parseLegacy({ openApi: spec }); expect(spy).toHaveBeenCalledWith(spec); const spec2: OpenApi = { @@ -54,7 +42,7 @@ describe('parse', () => { paths: {}, swagger: '2.0', }; - parseLegacy({ openApi: spec2, parserConfig }); + parseLegacy({ openApi: spec2 }); expect(spy).toHaveBeenCalledWith(spec2); }); @@ -69,7 +57,7 @@ describe('parse', () => { openapi: '3', paths: {}, }; - parseLegacy({ openApi: spec, parserConfig }); + parseLegacy({ openApi: spec }); expect(spy).toHaveBeenCalledWith(spec); const spec2: OpenApi = { @@ -80,7 +68,7 @@ describe('parse', () => { openapi: '3.0', paths: {}, }; - parseLegacy({ openApi: spec2, parserConfig }); + parseLegacy({ openApi: spec2 }); expect(spy).toHaveBeenCalledWith(spec2); const spec3: OpenApi = { @@ -91,14 +79,12 @@ describe('parse', () => { openapi: '3.1.0', paths: {}, }; - parseLegacy({ openApi: spec3, parserConfig }); + parseLegacy({ openApi: spec3 }); expect(spy).toHaveBeenCalledWith(spec3); }); it('throws on unknown version', () => { - expect(() => - parseLegacy({ openApi: { foo: 'bar' }, parserConfig }), - ).toThrow( + expect(() => parseLegacy({ openApi: { foo: 'bar' } })).toThrow( `Unsupported OpenAPI specification: ${JSON.stringify({ foo: 'bar' }, null, 2)}`, ); }); @@ -121,7 +107,6 @@ describe('experimentalParser', () => { parseExperimental({ // @ts-ignore config: {}, - parserConfig, spec, }); expect(parseV3_0_X).toHaveBeenCalled(); @@ -139,7 +124,6 @@ describe('experimentalParser', () => { parseExperimental({ // @ts-ignore config: {}, - parserConfig, spec, }); expect(parseV3_0_X).toHaveBeenCalled(); @@ -157,7 +141,6 @@ describe('experimentalParser', () => { parseExperimental({ // @ts-ignore config: {}, - parserConfig, spec, }); expect(parseV3_0_X).toHaveBeenCalled(); @@ -175,7 +158,6 @@ describe('experimentalParser', () => { parseExperimental({ // @ts-ignore config: {}, - parserConfig, spec, }); expect(parseV3_0_X).toHaveBeenCalled(); @@ -193,7 +175,6 @@ describe('experimentalParser', () => { parseExperimental({ // @ts-ignore config: {}, - parserConfig, spec, }); expect(parseV3_0_X).toHaveBeenCalled(); @@ -210,7 +191,6 @@ describe('experimentalParser', () => { parseExperimental({ // @ts-ignore config: {}, - parserConfig, spec, }); expect(parseV3_1_X).toHaveBeenCalled(); @@ -227,7 +207,6 @@ describe('experimentalParser', () => { parseExperimental({ // @ts-ignore config: {}, - parserConfig, spec, }); expect(parseV3_1_X).toHaveBeenCalled(); diff --git a/packages/openapi-ts/src/openApi/common/parser/operation.ts b/packages/openapi-ts/src/openApi/common/parser/operation.ts index 37d910ca8..b54d11d3f 100644 --- a/packages/openapi-ts/src/openApi/common/parser/operation.ts +++ b/packages/openapi-ts/src/openApi/common/parser/operation.ts @@ -1,7 +1,12 @@ +import type { Config } from '../../../types/config'; +import { camelCase } from '../../../utils/camelCase'; +import { getConfig, isLegacyClient } from '../../../utils/config'; +import { transformTypeKeyName } from '../../../utils/type'; import type { OperationParameter, OperationResponse, } from '../interfaces/client'; +import { sanitizeNamespaceIdentifier } from './sanitize'; export const getOperationKey = (operation: { method: string; @@ -153,6 +158,82 @@ const inferDefaultResponseTypes = ( return types; }; +export const operationFilterFn = ({ + config, + operationKey, +}: { + config: Config; + operationKey: string; +}): boolean => { + const regexp = config.plugins['@hey-api/services']?.filter + ? new RegExp(config.plugins['@hey-api/services']?.filter) + : undefined; + return !regexp || regexp.test(operationKey); +}; + +/** + * Convert the input value to a correct operation (method) class name. + * This will use the operation ID - if available - and otherwise fallback + * on a generated name from the URL + */ +export const operationNameFn = ({ + config, + method, + operationId, + path, +}: { + config: Config; + method: string; + operationId: string | undefined; + path: string; +}): string => { + if (config.plugins['@hey-api/services']?.operationId && operationId) { + return camelCase({ + input: sanitizeNamespaceIdentifier(operationId), + }); + } + + let urlWithoutPlaceholders = path; + + // legacy clients ignore the "api-version" param since we do not want to + // add it as the first/default parameter for each of the service calls + if (isLegacyClient(config)) { + urlWithoutPlaceholders = urlWithoutPlaceholders.replace( + /[^/]*?{api-version}.*?\//g, + '', + ); + } + + urlWithoutPlaceholders = urlWithoutPlaceholders + .replace(/{(.*?)}/g, 'by-$1') + // replace slashes with hyphens for camelcase method at the end + .replace(/[/:]/g, '-'); + + return camelCase({ + input: `${method}-${urlWithoutPlaceholders}`, + }); +}; + +export const operationParameterFilterFn = ( + parameter: OperationParameter, +): boolean => { + const config = getConfig(); + + // legacy clients ignore the "api-version" param since we do not want to + // add it as the first/default parameter for each of the service calls + return !isLegacyClient(config) || parameter.prop !== 'api-version'; +}; + +export const operationParameterNameFn = ( + parameter: Omit, +): string => { + const config = getConfig(); + + return !isLegacyClient(config) + ? parameter.prop + : transformTypeKeyName(parameter.prop); +}; + export const tagResponseTypes = (responses: OperationResponse[]) => responses.map((response) => { const { code } = response; diff --git a/packages/openapi-ts/src/openApi/config.ts b/packages/openapi-ts/src/openApi/config.ts deleted file mode 100644 index d5951c05e..000000000 --- a/packages/openapi-ts/src/openApi/config.ts +++ /dev/null @@ -1,103 +0,0 @@ -import type { Config } from '../types/config'; -import { camelCase } from '../utils/camelCase'; -import { getConfig, isLegacyClient } from '../utils/config'; -import { transformTypeKeyName } from '../utils/type'; -import type { OperationParameter } from './common/interfaces/client'; -import { sanitizeNamespaceIdentifier } from './common/parser/sanitize'; - -export interface ParserConfig { - debug?: boolean; - filterFn: { - operation: typeof operationFilterFn; - operationParameter: typeof operationParameterFilterFn; - }; - nameFn: { - operation: typeof operationNameFn; - operationParameter: typeof operationParameterNameFn; - }; -} - -let _config: ParserConfig; - -export const getParserConfig = () => _config; - -export const setParserConfig = (config: ParserConfig) => { - _config = config; - return getParserConfig(); -}; - -export const operationFilterFn = ({ - config, - operationKey, -}: { - config: Config; - operationKey: string; -}): boolean => { - const regexp = config.plugins['@hey-api/services']?.filter - ? new RegExp(config.plugins['@hey-api/services']?.filter) - : undefined; - return !regexp || regexp.test(operationKey); -}; - -export const operationParameterFilterFn = ( - parameter: OperationParameter, -): boolean => { - const config = getConfig(); - - // legacy clients ignore the "api-version" param since we do not want to - // add it as the first/default parameter for each of the service calls - return !isLegacyClient(config) || parameter.prop !== 'api-version'; -}; - -/** - * Convert the input value to a correct operation (method) class name. - * This will use the operation ID - if available - and otherwise fallback - * on a generated name from the URL - */ -export const operationNameFn = ({ - config, - method, - operationId, - path, -}: { - config: Config; - method: string; - operationId: string | undefined; - path: string; -}): string => { - if (config.plugins['@hey-api/services']?.operationId && operationId) { - return camelCase({ - input: sanitizeNamespaceIdentifier(operationId), - }); - } - - let urlWithoutPlaceholders = path; - - // legacy clients ignore the "api-version" param since we do not want to - // add it as the first/default parameter for each of the service calls - if (isLegacyClient(config)) { - urlWithoutPlaceholders = urlWithoutPlaceholders.replace( - /[^/]*?{api-version}.*?\//g, - '', - ); - } - - urlWithoutPlaceholders = urlWithoutPlaceholders - .replace(/{(.*?)}/g, 'by-$1') - // replace slashes with hyphens for camelcase method at the end - .replace(/[/:]/g, '-'); - - return camelCase({ - input: `${method}-${urlWithoutPlaceholders}`, - }); -}; - -export const operationParameterNameFn = ( - parameter: Omit, -): string => { - const config = getConfig(); - - return !isLegacyClient(config) - ? parameter.prop - : transformTypeKeyName(parameter.prop); -}; diff --git a/packages/openapi-ts/src/openApi/index.ts b/packages/openapi-ts/src/openApi/index.ts index fe8b41ea7..3784f9ece 100644 --- a/packages/openapi-ts/src/openApi/index.ts +++ b/packages/openapi-ts/src/openApi/index.ts @@ -4,8 +4,6 @@ import { type OpenApiV3_0_X, parseV3_0_X } from './3.0.x'; import { type OpenApiV3_1_X, parseV3_1_X } from './3.1.x'; import type { Client } from './common/interfaces/client'; import type { OpenApi } from './common/interfaces/OpenApi'; -import type { ParserConfig } from './config'; -import { setParserConfig } from './config'; import { parse as parseV2 } from './v2'; import { parse as parseV3 } from './v3'; @@ -35,17 +33,9 @@ export type { OpenApiSchema as OpenApiV3Schema } from './v3/interfaces/OpenApiSc * all the models, services and schema's we should output. * @param openApi The OpenAPI spec that we have loaded from disk. */ -export function parseLegacy({ - openApi, - parserConfig, -}: { - openApi: unknown; - parserConfig: ParserConfig; -}): Client { +export function parseLegacy({ openApi }: { openApi: unknown }): Client { const spec = openApi as OpenApi; - setParserConfig(parserConfig); - if ('openapi' in spec) { return parseV3(spec); } @@ -62,16 +52,13 @@ export function parseLegacy({ // TODO: parser - add JSDoc comment export const parseExperimental = ({ config, - parserConfig, spec, }: { config: Config; - parserConfig: ParserConfig; spec: unknown; }): IRContext | undefined => { const context = new IRContext({ config, - parserConfig, spec: spec as Record, }); diff --git a/packages/openapi-ts/src/openApi/shared/utils/operation.ts b/packages/openapi-ts/src/openApi/shared/utils/operation.ts new file mode 100644 index 000000000..b7eac71dd --- /dev/null +++ b/packages/openapi-ts/src/openApi/shared/utils/operation.ts @@ -0,0 +1,39 @@ +import type { IRContext } from '../../../ir/context'; +import { camelCase } from '../../../utils/camelCase'; +import { sanitizeNamespaceIdentifier } from '../../common/parser/sanitize'; + +/** + * Returns an operation ID to use across the application. By default, we try + * to use the provided ID. If it's not provided or the services are configured + * to exclude it, we generate operation ID from its location. + */ +export const operationToId = ({ + context, + method, + id, + path, +}: { + context: IRContext; + id: string | undefined; + method: string; + path: string; +}): string => { + if ( + id && + (!context.config.plugins['@hey-api/services'] || + context.config.plugins['@hey-api/services'].operationId) + ) { + return camelCase({ + input: sanitizeNamespaceIdentifier(id), + }); + } + + const urlWithoutPlaceholders = path + .replace(/{(.*?)}/g, 'by-$1') + // replace slashes with hyphens for camelcase method at the end + .replace(/[/:]/g, '-'); + + return camelCase({ + input: `${method}-${urlWithoutPlaceholders}`, + }); +}; diff --git a/packages/openapi-ts/src/openApi/v2/parser/getOperationParameter.ts b/packages/openapi-ts/src/openApi/v2/parser/getOperationParameter.ts index f90bbfee7..4a8427e5b 100644 --- a/packages/openapi-ts/src/openApi/v2/parser/getOperationParameter.ts +++ b/packages/openapi-ts/src/openApi/v2/parser/getOperationParameter.ts @@ -4,8 +4,8 @@ import { getDefault } from '../../common/parser/getDefault'; import { getEnums } from '../../common/parser/getEnums'; import { getPattern } from '../../common/parser/getPattern'; import { getRef } from '../../common/parser/getRef'; +import { operationParameterNameFn } from '../../common/parser/operation'; import { getType } from '../../common/parser/type'; -import { getParserConfig } from '../../config'; import type { OpenApi } from '../interfaces/OpenApi'; import type { OpenApiParameter } from '../interfaces/OpenApiParameter'; import type { OpenApiSchema } from '../interfaces/OpenApiSchema'; @@ -20,8 +20,6 @@ export const getOperationParameter = ({ parameter: OpenApiParameter; types: Client['types']; }): OperationParameter => { - const config = getParserConfig(); - const operationParameterWithoutName: Omit = { $refs: [], base: 'unknown', @@ -56,7 +54,7 @@ export const getOperationParameter = ({ }; let operationParameter = { ...operationParameterWithoutName, - name: config.nameFn.operationParameter(operationParameterWithoutName), + name: operationParameterNameFn(operationParameterWithoutName), }; if (parameter.$ref) { diff --git a/packages/openapi-ts/src/openApi/v2/parser/getOperationParameters.ts b/packages/openapi-ts/src/openApi/v2/parser/getOperationParameters.ts index 5860877b8..8611008d2 100644 --- a/packages/openapi-ts/src/openApi/v2/parser/getOperationParameters.ts +++ b/packages/openapi-ts/src/openApi/v2/parser/getOperationParameters.ts @@ -1,7 +1,7 @@ import type { Client } from '../../../types/client'; import type { OperationParameters } from '../../common/interfaces/client'; import { getRef } from '../../common/parser/getRef'; -import { getParserConfig } from '../../config'; +import { operationParameterFilterFn } from '../../common/parser/operation'; import type { OpenApi } from '../interfaces/OpenApi'; import type { OpenApiParameter } from '../interfaces/OpenApiParameter'; import { getOperationParameter } from './getOperationParameter'; @@ -17,8 +17,6 @@ export const getOperationParameters = ({ parameters: OpenApiParameter[]; types: Client['types']; }): OperationParameters => { - const config = getParserConfig(); - const operationParameters: OperationParameters = { $refs: [], imports: [], @@ -42,7 +40,7 @@ export const getOperationParameters = ({ types, }); - const skip = !config.filterFn.operationParameter(parameter); + const skip = !operationParameterFilterFn(parameter); if (!allowedIn.includes(parameterDef.in) || skip) { return; } diff --git a/packages/openapi-ts/src/openApi/v2/parser/getOperations.ts b/packages/openapi-ts/src/openApi/v2/parser/getOperations.ts index 5bbf3f2ea..b056c3ecb 100644 --- a/packages/openapi-ts/src/openApi/v2/parser/getOperations.ts +++ b/packages/openapi-ts/src/openApi/v2/parser/getOperations.ts @@ -1,8 +1,10 @@ import { getConfig } from '../../../utils/config'; import type { Client, Operation } from '../../common/interfaces/client'; -import { getOperationKey } from '../../common/parser/operation'; +import { + getOperationKey, + operationFilterFn, +} from '../../common/parser/operation'; import { allowedServiceMethods } from '../../common/parser/service'; -import { getParserConfig } from '../../config'; import type { OpenApi } from '../interfaces/OpenApi'; import { getOperationParameters } from './getOperationParameters'; import { getOperation } from './operation'; @@ -14,8 +16,6 @@ export const getOperations = ({ openApi: OpenApi; types: Client['types']; }): Operation[] => { - const config = getParserConfig(); - const operationIds = new Map(); const operations: Operation[] = []; @@ -49,7 +49,7 @@ export const getOperations = ({ } if ( - config.filterFn.operation({ + operationFilterFn({ config: getConfig(), operationKey, }) diff --git a/packages/openapi-ts/src/openApi/v2/parser/operation.ts b/packages/openapi-ts/src/openApi/v2/parser/operation.ts index f175dadee..6cdeca181 100644 --- a/packages/openapi-ts/src/openApi/v2/parser/operation.ts +++ b/packages/openapi-ts/src/openApi/v2/parser/operation.ts @@ -4,9 +4,11 @@ import type { Operation, OperationParameters, } from '../../common/interfaces/client'; -import { getOperationResponseHeader } from '../../common/parser/operation'; +import { + getOperationResponseHeader, + operationNameFn, +} from '../../common/parser/operation'; import { toSortedByRequired } from '../../common/parser/sort'; -import { getParserConfig } from '../../config'; import type { OpenApi } from '../interfaces/OpenApi'; import type { OpenApiOperation } from '../interfaces/OpenApiOperation'; import { getOperationParameters } from './getOperationParameters'; @@ -27,8 +29,6 @@ export const getOperation = ({ types: Client['types']; url: string; }): Operation => { - const config = getParserConfig(); - const operationWithoutName: Omit = { $refs: [], deprecated: op.deprecated === true, @@ -51,7 +51,7 @@ export const getOperation = ({ }; const operation = { ...operationWithoutName, - name: config.nameFn.operation({ + name: operationNameFn({ config: getConfig(), method: operationWithoutName.method, operationId: op.operationId, diff --git a/packages/openapi-ts/src/openApi/v3/parser/getModels.ts b/packages/openapi-ts/src/openApi/v3/parser/getModels.ts index c96a47637..ee410fa03 100644 --- a/packages/openapi-ts/src/openApi/v3/parser/getModels.ts +++ b/packages/openapi-ts/src/openApi/v3/parser/getModels.ts @@ -1,6 +1,5 @@ import type { Client } from '../../../types/client'; import { getParametersMeta, getSchemasMeta } from '../../../utils/meta'; -import { getParserConfig } from '../../config'; import type { OpenApi } from '../interfaces/OpenApi'; import { getModel } from './getModel'; import { getParameterSchema } from './parameter'; @@ -8,8 +7,6 @@ import { getParameterSchema } from './parameter'; export const getModels = ( openApi: OpenApi, ): Pick => { - const config = getParserConfig(); - const types: Client['types'] = {}; let models: Client['models'] = []; @@ -39,9 +36,6 @@ export const getModels = ( ([definitionName, definition]) => { const schema = getParameterSchema(definition); if (!schema) { - if (config.debug) { - console.warn('Skipping generating parameter:', definitionName); - } return; } diff --git a/packages/openapi-ts/src/openApi/v3/parser/getOperationParameter.ts b/packages/openapi-ts/src/openApi/v3/parser/getOperationParameter.ts index 01788a443..ac45a9ffb 100644 --- a/packages/openapi-ts/src/openApi/v3/parser/getOperationParameter.ts +++ b/packages/openapi-ts/src/openApi/v3/parser/getOperationParameter.ts @@ -5,8 +5,8 @@ import type { OperationParameter } from '../../common/interfaces/client'; import { getDefault } from '../../common/parser/getDefault'; import { getPattern } from '../../common/parser/getPattern'; import { getRef } from '../../common/parser/getRef'; +import { operationParameterNameFn } from '../../common/parser/operation'; import { getType } from '../../common/parser/type'; -import { getParserConfig } from '../../config'; import type { OpenApi } from '../interfaces/OpenApi'; import type { OpenApiParameter } from '../interfaces/OpenApiParameter'; import type { OpenApiSchema } from '../interfaces/OpenApiSchema'; @@ -23,8 +23,6 @@ export const getOperationParameter = ({ parameter: OpenApiParameter; types: Client['types']; }): OperationParameter => { - const config = getParserConfig(); - const operationParameterWithoutName: Omit = { $refs: [], base: 'unknown', @@ -48,7 +46,7 @@ export const getOperationParameter = ({ }; let operationParameter = { ...operationParameterWithoutName, - name: config.nameFn.operationParameter(operationParameterWithoutName), + name: operationParameterNameFn(operationParameterWithoutName), }; if (parameter.$ref) { diff --git a/packages/openapi-ts/src/openApi/v3/parser/getOperationParameters.ts b/packages/openapi-ts/src/openApi/v3/parser/getOperationParameters.ts index edc2196b4..3748308fd 100644 --- a/packages/openapi-ts/src/openApi/v3/parser/getOperationParameters.ts +++ b/packages/openapi-ts/src/openApi/v3/parser/getOperationParameters.ts @@ -1,7 +1,7 @@ import type { Client } from '../../../types/client'; import type { OperationParameters } from '../../common/interfaces/client'; import { getRef } from '../../common/parser/getRef'; -import { getParserConfig } from '../../config'; +import { operationParameterFilterFn } from '../../common/parser/operation'; import type { OpenApi } from '../interfaces/OpenApi'; import type { OpenApiParameter } from '../interfaces/OpenApiParameter'; import { getOperationParameter } from './getOperationParameter'; @@ -17,8 +17,6 @@ export const getOperationParameters = ({ parameters: OpenApiParameter[]; types: Client['types']; }): OperationParameters => { - const config = getParserConfig(); - const operationParameters: OperationParameters = { $refs: [], imports: [], @@ -42,7 +40,7 @@ export const getOperationParameters = ({ types, }); - const skip = !config.filterFn.operationParameter(parameter); + const skip = !operationParameterFilterFn(parameter); if (!allowedIn.includes(parameterDef.in) || skip) { return; } diff --git a/packages/openapi-ts/src/openApi/v3/parser/getOperations.ts b/packages/openapi-ts/src/openApi/v3/parser/getOperations.ts index 5bbf3f2ea..b056c3ecb 100644 --- a/packages/openapi-ts/src/openApi/v3/parser/getOperations.ts +++ b/packages/openapi-ts/src/openApi/v3/parser/getOperations.ts @@ -1,8 +1,10 @@ import { getConfig } from '../../../utils/config'; import type { Client, Operation } from '../../common/interfaces/client'; -import { getOperationKey } from '../../common/parser/operation'; +import { + getOperationKey, + operationFilterFn, +} from '../../common/parser/operation'; import { allowedServiceMethods } from '../../common/parser/service'; -import { getParserConfig } from '../../config'; import type { OpenApi } from '../interfaces/OpenApi'; import { getOperationParameters } from './getOperationParameters'; import { getOperation } from './operation'; @@ -14,8 +16,6 @@ export const getOperations = ({ openApi: OpenApi; types: Client['types']; }): Operation[] => { - const config = getParserConfig(); - const operationIds = new Map(); const operations: Operation[] = []; @@ -49,7 +49,7 @@ export const getOperations = ({ } if ( - config.filterFn.operation({ + operationFilterFn({ config: getConfig(), operationKey, }) diff --git a/packages/openapi-ts/src/openApi/v3/parser/operation.ts b/packages/openapi-ts/src/openApi/v3/parser/operation.ts index 18df25ae1..5cb3ebe39 100644 --- a/packages/openapi-ts/src/openApi/v3/parser/operation.ts +++ b/packages/openapi-ts/src/openApi/v3/parser/operation.ts @@ -6,9 +6,11 @@ import type { OperationParameters, } from '../../common/interfaces/client'; import { getRef } from '../../common/parser/getRef'; -import { getOperationResponseHeader } from '../../common/parser/operation'; +import { + getOperationResponseHeader, + operationNameFn, +} from '../../common/parser/operation'; import { toSortedByRequired } from '../../common/parser/sort'; -import { getParserConfig } from '../../config'; import type { OpenApi } from '../interfaces/OpenApi'; import type { OpenApiOperation } from '../interfaces/OpenApiOperation'; import type { OpenApiRequestBody } from '../interfaces/OpenApiRequestBody'; @@ -54,8 +56,6 @@ export const getOperation = ({ types: Client['types']; url: string; }): Operation => { - const config = getParserConfig(); - const operationWithoutName: Omit = { $refs: [], deprecated: Boolean(op.deprecated), @@ -78,7 +78,7 @@ export const getOperation = ({ }; const operation = { ...operationWithoutName, - name: config.nameFn.operation({ + name: operationNameFn({ config: getConfig(), method: operationWithoutName.method, operationId: op.operationId, diff --git a/packages/openapi-ts/src/plugins/@hey-api/types/plugin.ts b/packages/openapi-ts/src/plugins/@hey-api/types/plugin.ts index 5278e701f..66be4a4b9 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/types/plugin.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/types/plugin.ts @@ -990,27 +990,17 @@ export const handler: PluginHandler = ({ context, plugin }) => { } } - // TODO: parser - once types are a plugin, this logic can be simplified - // provide config option on types to generate path types and services - // will set it to true if needed - if ( - context.config.plugins['@hey-api/services'] || - context.config.plugins['@hey-api/types']?.tree - ) { - for (const path in context.ir.paths) { - const pathItem = context.ir.paths[path as keyof IRPathsObject]; + for (const path in context.ir.paths) { + const pathItem = context.ir.paths[path as keyof IRPathsObject]; - for (const _method in pathItem) { - const method = _method as keyof IRPathItemObject; - const operation = pathItem[method]!; + for (const _method in pathItem) { + const method = _method as keyof IRPathItemObject; + const operation = pathItem[method]!; - operationToType({ - context, - operation, - }); - } + operationToType({ + context, + operation, + }); } - - // TODO: parser - document removal of tree? migrate it? } }; diff --git a/packages/openapi-ts/src/plugins/@hey-api/types/types.d.ts b/packages/openapi-ts/src/plugins/@hey-api/types/types.d.ts index a3edd4c0a..6ee60dda4 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/types/types.d.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/types/types.d.ts @@ -28,6 +28,8 @@ export interface Config extends PluginName<'@hey-api/types'> { * Generate a tree of types containing all operations? It will be named * $OpenApiTs. * @default false + * + * @deprecated */ tree?: boolean; } diff --git a/packages/openapi-ts/src/plugins/fastify/config.ts b/packages/openapi-ts/src/plugins/fastify/config.ts index d123a8f83..5f99a6c30 100644 --- a/packages/openapi-ts/src/plugins/fastify/config.ts +++ b/packages/openapi-ts/src/plugins/fastify/config.ts @@ -3,7 +3,7 @@ import { handler } from './plugin'; import type { Config } from './types'; export const defaultConfig: PluginConfig = { - _dependencies: ['@hey-api/types', '@hey-api/services'], + _dependencies: ['@hey-api/types'], _handler: handler, _handlerLegacy: () => {}, name: 'fastify', diff --git a/packages/openapi-ts/src/utils/__tests__/parse.spec.ts b/packages/openapi-ts/src/utils/__tests__/parse.spec.ts index af0ea529d..53ef89f1c 100644 --- a/packages/openapi-ts/src/utils/__tests__/parse.spec.ts +++ b/packages/openapi-ts/src/utils/__tests__/parse.spec.ts @@ -1,6 +1,6 @@ import { describe, expect, it } from 'vitest'; -import { operationNameFn } from '../../openApi/config'; +import { operationNameFn } from '../../openApi/common/parser/operation'; import { setConfig } from '../config'; describe('operationNameFn', () => { diff --git a/packages/openapi-ts/src/utils/__tests__/postprocess.spec.ts b/packages/openapi-ts/src/utils/__tests__/postprocess.spec.ts index dca7cd465..013df8bd9 100644 --- a/packages/openapi-ts/src/utils/__tests__/postprocess.spec.ts +++ b/packages/openapi-ts/src/utils/__tests__/postprocess.spec.ts @@ -1,19 +1,18 @@ -import { describe, expect, it } from 'vitest'; +import { describe, expect, it, vi } from 'vitest'; import { parseLegacy } from '../../openApi'; -import type { ParserConfig } from '../../openApi/config'; +import type { Config } from '../../types/config'; import { getServiceName, postProcessClient } from '../postprocess'; -const parserConfig: ParserConfig = { - filterFn: { - operation: () => true, - operationParameter: () => true, - }, - nameFn: { - operation: () => 'operation', - operationParameter: () => 'operationParameter', - }, -}; +vi.mock('../config', () => { + const config: Partial = { + plugins: {}, + }; + return { + getConfig: () => config, + isLegacyClient: vi.fn().mockReturnValue(true), + }; +}); describe('getServiceName', () => { it.each([ @@ -58,7 +57,6 @@ describe('getServices', () => { }, }, }, - parserConfig, }); const { services } = postProcessClient(parserClient); @@ -92,7 +90,6 @@ describe('getServices', () => { }, }, }, - parserConfig, }); const { services } = postProcessClient(parserClient); diff --git a/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/fastify/default/index.ts b/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/fastify/default/index.ts index e3705920c..56bade120 100644 --- a/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/fastify/default/index.ts +++ b/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/fastify/default/index.ts @@ -1,3 +1,2 @@ // This file is auto-generated by @hey-api/openapi-ts -export * from './types.gen'; -export * from './services.gen'; \ No newline at end of file +export * from './types.gen'; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/fastify/default/services.gen.ts b/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/fastify/default/services.gen.ts deleted file mode 100644 index c79ed1e8c..000000000 --- a/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/fastify/default/services.gen.ts +++ /dev/null @@ -1,382 +0,0 @@ -// This file is auto-generated by @hey-api/openapi-ts - -import { createClient, createConfig, type Options, formDataBodySerializer, urlSearchParamsBodySerializer } from '@hey-api/client-fetch'; -import type { ImportData, ImportResponse, ApiVversionOdataControllerCountResponse, GetApiVbyApiVersionSimpleOperationData, GetApiVbyApiVersionSimpleOperationError, GetApiVbyApiVersionSimpleOperationResponse, DeleteFooData3, CallWithDescriptionsData, DeprecatedCallData, CallWithParametersData, CallWithWeirdParameterNamesData, GetCallWithOptionalParamData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponse, PostApiVbyApiVersionRequestBodyData, PostApiVbyApiVersionFormDataData, CallWithDefaultParametersData, CallWithDefaultOptionalParametersData, CallToTestOrderOfParamsData, CallWithNoContentResponseResponse, CallWithResponseAndNoContentResponseResponse, DummyAResponse, DummyBResponse, CallWithResponseResponse, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithResponsesError, CallWithResponsesResponse, CollectionFormatData, TypesData, TypesResponse, UploadFileData, UploadFileResponse, FileResponseData, FileResponseResponse, ComplexTypesData, ComplexTypesResponse, MultipartResponseResponse, MultipartRequestData, ComplexParamsData, ComplexParamsResponse, TestErrorCodeData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PutWithFormUrlEncodedData } from './types.gen'; - -export const client = createClient(createConfig()); - -export const export_ = (options?: Options) => { - return (options?.client ?? client).get({ - ...options, - url: '/api/v{api-version}/no-tag' - }); -}; - -export const import_ = (options: Options) => { - return (options?.client ?? client).post({ - ...options, - headers: { - 'Content-Type': 'application/json', - ...options?.headers - }, - url: '/api/v{api-version}/no-tag' - }); -}; - -export const apiVVersionOdataControllerCount = (options?: Options) => { - return (options?.client ?? client).get({ - ...options, - url: '/api/v{api-version}/simple/$count' - }); -}; - -export const getApiVbyApiVersionSimpleOperation = (options: Options) => { - return (options?.client ?? client).get({ - ...options, - url: '/api/v{api-version}/simple:operation' - }); -}; - -export const deleteCallWithoutParametersAndResponse = (options?: Options) => { - return (options?.client ?? client).delete({ - ...options, - url: '/api/v{api-version}/simple' - }); -}; - -export const getCallWithoutParametersAndResponse = (options?: Options) => { - return (options?.client ?? client).get({ - ...options, - url: '/api/v{api-version}/simple' - }); -}; - -export const headCallWithoutParametersAndResponse = (options?: Options) => { - return (options?.client ?? client).head({ - ...options, - url: '/api/v{api-version}/simple' - }); -}; - -export const optionsCallWithoutParametersAndResponse = (options?: Options) => { - return (options?.client ?? client).options({ - ...options, - url: '/api/v{api-version}/simple' - }); -}; - -export const patchCallWithoutParametersAndResponse = (options?: Options) => { - return (options?.client ?? client).patch({ - ...options, - url: '/api/v{api-version}/simple' - }); -}; - -export const postCallWithoutParametersAndResponse = (options?: Options) => { - return (options?.client ?? client).post({ - ...options, - url: '/api/v{api-version}/simple' - }); -}; - -export const putCallWithoutParametersAndResponse = (options?: Options) => { - return (options?.client ?? client).put({ - ...options, - url: '/api/v{api-version}/simple' - }); -}; - -export const deleteFoo = (options: Options) => { - return (options?.client ?? client).delete({ - ...options, - url: '/api/v{api-version}/foo/{foo_param}/bar/{BarParam}' - }); -}; - -export const callWithDescriptions = (options?: Options) => { - return (options?.client ?? client).post({ - ...options, - url: '/api/v{api-version}/descriptions' - }); -}; - -/** - * @deprecated - */ -export const deprecatedCall = (options: Options) => { - return (options?.client ?? client).post({ - ...options, - url: '/api/v{api-version}/parameters/deprecated' - }); -}; - -export const callWithParameters = (options: Options) => { - return (options?.client ?? client).post({ - ...options, - headers: { - 'Content-Type': 'application/json', - ...options?.headers - }, - url: '/api/v{api-version}/parameters/{parameterPath}' - }); -}; - -export const callWithWeirdParameterNames = (options: Options) => { - return (options?.client ?? client).post({ - ...options, - headers: { - 'Content-Type': 'application/json', - ...options?.headers - }, - url: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}' - }); -}; - -export const getCallWithOptionalParam = (options: Options) => { - return (options?.client ?? client).get({ - ...options, - headers: { - 'Content-Type': 'application/json', - ...options?.headers - }, - url: '/api/v{api-version}/parameters' - }); -}; - -export const postCallWithOptionalParam = (options: Options) => { - return (options?.client ?? client).post({ - ...options, - headers: { - 'Content-Type': 'application/json', - ...options?.headers - }, - url: '/api/v{api-version}/parameters' - }); -}; - -export const postApiVbyApiVersionRequestBody = (options?: Options) => { - return (options?.client ?? client).post({ - ...options, - headers: { - 'Content-Type': 'application/json', - ...options?.headers - }, - url: '/api/v{api-version}/requestBody' - }); -}; - -export const postApiVbyApiVersionFormData = (options?: Options) => { - return (options?.client ?? client).post({ - ...options, - ...formDataBodySerializer, - headers: { - 'Content-Type': null, - ...options?.headers - }, - url: '/api/v{api-version}/formData' - }); -}; - -export const callWithDefaultParameters = (options?: Options) => { - return (options?.client ?? client).get({ - ...options, - url: '/api/v{api-version}/defaults' - }); -}; - -export const callWithDefaultOptionalParameters = (options?: Options) => { - return (options?.client ?? client).post({ - ...options, - url: '/api/v{api-version}/defaults' - }); -}; - -export const callToTestOrderOfParams = (options: Options) => { - return (options?.client ?? client).put({ - ...options, - url: '/api/v{api-version}/defaults' - }); -}; - -export const duplicateName = (options?: Options) => { - return (options?.client ?? client).delete({ - ...options, - url: '/api/v{api-version}/duplicate' - }); -}; - -export const duplicateName2 = (options?: Options) => { - return (options?.client ?? client).get({ - ...options, - url: '/api/v{api-version}/duplicate' - }); -}; - -export const duplicateName3 = (options?: Options) => { - return (options?.client ?? client).post({ - ...options, - url: '/api/v{api-version}/duplicate' - }); -}; - -export const duplicateName4 = (options?: Options) => { - return (options?.client ?? client).put({ - ...options, - url: '/api/v{api-version}/duplicate' - }); -}; - -export const callWithNoContentResponse = (options?: Options) => { - return (options?.client ?? client).get({ - ...options, - url: '/api/v{api-version}/no-content' - }); -}; - -export const callWithResponseAndNoContentResponse = (options?: Options) => { - return (options?.client ?? client).get({ - ...options, - url: '/api/v{api-version}/multiple-tags/response-and-no-content' - }); -}; - -export const dummyA = (options?: Options) => { - return (options?.client ?? client).get({ - ...options, - url: '/api/v{api-version}/multiple-tags/a' - }); -}; - -export const dummyB = (options?: Options) => { - return (options?.client ?? client).get({ - ...options, - url: '/api/v{api-version}/multiple-tags/b' - }); -}; - -export const callWithResponse = (options?: Options) => { - return (options?.client ?? client).get({ - ...options, - url: '/api/v{api-version}/response' - }); -}; - -export const callWithDuplicateResponses = (options?: Options) => { - return (options?.client ?? client).post({ - ...options, - url: '/api/v{api-version}/response' - }); -}; - -export const callWithResponses = (options?: Options) => { - return (options?.client ?? client).put({ - ...options, - url: '/api/v{api-version}/response' - }); -}; - -export const collectionFormat = (options: Options) => { - return (options?.client ?? client).get({ - ...options, - url: '/api/v{api-version}/collectionFormat' - }); -}; - -export const types = (options: Options) => { - return (options?.client ?? client).get({ - ...options, - url: '/api/v{api-version}/types' - }); -}; - -export const uploadFile = (options: Options) => { - return (options?.client ?? client).post({ - ...options, - ...urlSearchParamsBodySerializer, - headers: { - 'Content-Type': 'application/x-www-form-urlencoded', - ...options?.headers - }, - url: '/api/v{api-version}/upload' - }); -}; - -export const fileResponse = (options: Options) => { - return (options?.client ?? client).get({ - ...options, - url: '/api/v{api-version}/file/{id}' - }); -}; - -export const complexTypes = (options: Options) => { - return (options?.client ?? client).get({ - ...options, - url: '/api/v{api-version}/complex' - }); -}; - -export const multipartResponse = (options?: Options) => { - return (options?.client ?? client).get({ - ...options, - url: '/api/v{api-version}/multipart' - }); -}; - -export const multipartRequest = (options?: Options) => { - return (options?.client ?? client).post({ - ...options, - ...formDataBodySerializer, - headers: { - 'Content-Type': null, - ...options?.headers - }, - url: '/api/v{api-version}/multipart' - }); -}; - -export const complexParams = (options: Options) => { - return (options?.client ?? client).put({ - ...options, - headers: { - 'Content-Type': 'application/json-patch+json', - ...options?.headers - }, - url: '/api/v{api-version}/complex/{id}' - }); -}; - -export const callWithResultFromHeader = (options?: Options) => { - return (options?.client ?? client).post({ - ...options, - url: '/api/v{api-version}/header' - }); -}; - -export const testErrorCode = (options: Options) => { - return (options?.client ?? client).post({ - ...options, - url: '/api/v{api-version}/error' - }); -}; - -export const nonAsciiæøåÆøÅöôêÊ字符串 = (options: Options) => { - return (options?.client ?? client).post({ - ...options, - url: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串' - }); -}; - -/** - * Login User - */ -export const putWithFormUrlEncoded = (options: Options) => { - return (options?.client ?? client).put({ - ...options, - ...urlSearchParamsBodySerializer, - headers: { - 'Content-Type': 'application/x-www-form-urlencoded', - ...options?.headers - }, - url: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串' - }); -}; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/fastify/default/index.ts b/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/fastify/default/index.ts index e3705920c..56bade120 100644 --- a/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/fastify/default/index.ts +++ b/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/fastify/default/index.ts @@ -1,3 +1,2 @@ // This file is auto-generated by @hey-api/openapi-ts -export * from './types.gen'; -export * from './services.gen'; \ No newline at end of file +export * from './types.gen'; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/fastify/default/services.gen.ts b/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/fastify/default/services.gen.ts deleted file mode 100644 index c79ed1e8c..000000000 --- a/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/fastify/default/services.gen.ts +++ /dev/null @@ -1,382 +0,0 @@ -// This file is auto-generated by @hey-api/openapi-ts - -import { createClient, createConfig, type Options, formDataBodySerializer, urlSearchParamsBodySerializer } from '@hey-api/client-fetch'; -import type { ImportData, ImportResponse, ApiVversionOdataControllerCountResponse, GetApiVbyApiVersionSimpleOperationData, GetApiVbyApiVersionSimpleOperationError, GetApiVbyApiVersionSimpleOperationResponse, DeleteFooData3, CallWithDescriptionsData, DeprecatedCallData, CallWithParametersData, CallWithWeirdParameterNamesData, GetCallWithOptionalParamData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponse, PostApiVbyApiVersionRequestBodyData, PostApiVbyApiVersionFormDataData, CallWithDefaultParametersData, CallWithDefaultOptionalParametersData, CallToTestOrderOfParamsData, CallWithNoContentResponseResponse, CallWithResponseAndNoContentResponseResponse, DummyAResponse, DummyBResponse, CallWithResponseResponse, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithResponsesError, CallWithResponsesResponse, CollectionFormatData, TypesData, TypesResponse, UploadFileData, UploadFileResponse, FileResponseData, FileResponseResponse, ComplexTypesData, ComplexTypesResponse, MultipartResponseResponse, MultipartRequestData, ComplexParamsData, ComplexParamsResponse, TestErrorCodeData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PutWithFormUrlEncodedData } from './types.gen'; - -export const client = createClient(createConfig()); - -export const export_ = (options?: Options) => { - return (options?.client ?? client).get({ - ...options, - url: '/api/v{api-version}/no-tag' - }); -}; - -export const import_ = (options: Options) => { - return (options?.client ?? client).post({ - ...options, - headers: { - 'Content-Type': 'application/json', - ...options?.headers - }, - url: '/api/v{api-version}/no-tag' - }); -}; - -export const apiVVersionOdataControllerCount = (options?: Options) => { - return (options?.client ?? client).get({ - ...options, - url: '/api/v{api-version}/simple/$count' - }); -}; - -export const getApiVbyApiVersionSimpleOperation = (options: Options) => { - return (options?.client ?? client).get({ - ...options, - url: '/api/v{api-version}/simple:operation' - }); -}; - -export const deleteCallWithoutParametersAndResponse = (options?: Options) => { - return (options?.client ?? client).delete({ - ...options, - url: '/api/v{api-version}/simple' - }); -}; - -export const getCallWithoutParametersAndResponse = (options?: Options) => { - return (options?.client ?? client).get({ - ...options, - url: '/api/v{api-version}/simple' - }); -}; - -export const headCallWithoutParametersAndResponse = (options?: Options) => { - return (options?.client ?? client).head({ - ...options, - url: '/api/v{api-version}/simple' - }); -}; - -export const optionsCallWithoutParametersAndResponse = (options?: Options) => { - return (options?.client ?? client).options({ - ...options, - url: '/api/v{api-version}/simple' - }); -}; - -export const patchCallWithoutParametersAndResponse = (options?: Options) => { - return (options?.client ?? client).patch({ - ...options, - url: '/api/v{api-version}/simple' - }); -}; - -export const postCallWithoutParametersAndResponse = (options?: Options) => { - return (options?.client ?? client).post({ - ...options, - url: '/api/v{api-version}/simple' - }); -}; - -export const putCallWithoutParametersAndResponse = (options?: Options) => { - return (options?.client ?? client).put({ - ...options, - url: '/api/v{api-version}/simple' - }); -}; - -export const deleteFoo = (options: Options) => { - return (options?.client ?? client).delete({ - ...options, - url: '/api/v{api-version}/foo/{foo_param}/bar/{BarParam}' - }); -}; - -export const callWithDescriptions = (options?: Options) => { - return (options?.client ?? client).post({ - ...options, - url: '/api/v{api-version}/descriptions' - }); -}; - -/** - * @deprecated - */ -export const deprecatedCall = (options: Options) => { - return (options?.client ?? client).post({ - ...options, - url: '/api/v{api-version}/parameters/deprecated' - }); -}; - -export const callWithParameters = (options: Options) => { - return (options?.client ?? client).post({ - ...options, - headers: { - 'Content-Type': 'application/json', - ...options?.headers - }, - url: '/api/v{api-version}/parameters/{parameterPath}' - }); -}; - -export const callWithWeirdParameterNames = (options: Options) => { - return (options?.client ?? client).post({ - ...options, - headers: { - 'Content-Type': 'application/json', - ...options?.headers - }, - url: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}' - }); -}; - -export const getCallWithOptionalParam = (options: Options) => { - return (options?.client ?? client).get({ - ...options, - headers: { - 'Content-Type': 'application/json', - ...options?.headers - }, - url: '/api/v{api-version}/parameters' - }); -}; - -export const postCallWithOptionalParam = (options: Options) => { - return (options?.client ?? client).post({ - ...options, - headers: { - 'Content-Type': 'application/json', - ...options?.headers - }, - url: '/api/v{api-version}/parameters' - }); -}; - -export const postApiVbyApiVersionRequestBody = (options?: Options) => { - return (options?.client ?? client).post({ - ...options, - headers: { - 'Content-Type': 'application/json', - ...options?.headers - }, - url: '/api/v{api-version}/requestBody' - }); -}; - -export const postApiVbyApiVersionFormData = (options?: Options) => { - return (options?.client ?? client).post({ - ...options, - ...formDataBodySerializer, - headers: { - 'Content-Type': null, - ...options?.headers - }, - url: '/api/v{api-version}/formData' - }); -}; - -export const callWithDefaultParameters = (options?: Options) => { - return (options?.client ?? client).get({ - ...options, - url: '/api/v{api-version}/defaults' - }); -}; - -export const callWithDefaultOptionalParameters = (options?: Options) => { - return (options?.client ?? client).post({ - ...options, - url: '/api/v{api-version}/defaults' - }); -}; - -export const callToTestOrderOfParams = (options: Options) => { - return (options?.client ?? client).put({ - ...options, - url: '/api/v{api-version}/defaults' - }); -}; - -export const duplicateName = (options?: Options) => { - return (options?.client ?? client).delete({ - ...options, - url: '/api/v{api-version}/duplicate' - }); -}; - -export const duplicateName2 = (options?: Options) => { - return (options?.client ?? client).get({ - ...options, - url: '/api/v{api-version}/duplicate' - }); -}; - -export const duplicateName3 = (options?: Options) => { - return (options?.client ?? client).post({ - ...options, - url: '/api/v{api-version}/duplicate' - }); -}; - -export const duplicateName4 = (options?: Options) => { - return (options?.client ?? client).put({ - ...options, - url: '/api/v{api-version}/duplicate' - }); -}; - -export const callWithNoContentResponse = (options?: Options) => { - return (options?.client ?? client).get({ - ...options, - url: '/api/v{api-version}/no-content' - }); -}; - -export const callWithResponseAndNoContentResponse = (options?: Options) => { - return (options?.client ?? client).get({ - ...options, - url: '/api/v{api-version}/multiple-tags/response-and-no-content' - }); -}; - -export const dummyA = (options?: Options) => { - return (options?.client ?? client).get({ - ...options, - url: '/api/v{api-version}/multiple-tags/a' - }); -}; - -export const dummyB = (options?: Options) => { - return (options?.client ?? client).get({ - ...options, - url: '/api/v{api-version}/multiple-tags/b' - }); -}; - -export const callWithResponse = (options?: Options) => { - return (options?.client ?? client).get({ - ...options, - url: '/api/v{api-version}/response' - }); -}; - -export const callWithDuplicateResponses = (options?: Options) => { - return (options?.client ?? client).post({ - ...options, - url: '/api/v{api-version}/response' - }); -}; - -export const callWithResponses = (options?: Options) => { - return (options?.client ?? client).put({ - ...options, - url: '/api/v{api-version}/response' - }); -}; - -export const collectionFormat = (options: Options) => { - return (options?.client ?? client).get({ - ...options, - url: '/api/v{api-version}/collectionFormat' - }); -}; - -export const types = (options: Options) => { - return (options?.client ?? client).get({ - ...options, - url: '/api/v{api-version}/types' - }); -}; - -export const uploadFile = (options: Options) => { - return (options?.client ?? client).post({ - ...options, - ...urlSearchParamsBodySerializer, - headers: { - 'Content-Type': 'application/x-www-form-urlencoded', - ...options?.headers - }, - url: '/api/v{api-version}/upload' - }); -}; - -export const fileResponse = (options: Options) => { - return (options?.client ?? client).get({ - ...options, - url: '/api/v{api-version}/file/{id}' - }); -}; - -export const complexTypes = (options: Options) => { - return (options?.client ?? client).get({ - ...options, - url: '/api/v{api-version}/complex' - }); -}; - -export const multipartResponse = (options?: Options) => { - return (options?.client ?? client).get({ - ...options, - url: '/api/v{api-version}/multipart' - }); -}; - -export const multipartRequest = (options?: Options) => { - return (options?.client ?? client).post({ - ...options, - ...formDataBodySerializer, - headers: { - 'Content-Type': null, - ...options?.headers - }, - url: '/api/v{api-version}/multipart' - }); -}; - -export const complexParams = (options: Options) => { - return (options?.client ?? client).put({ - ...options, - headers: { - 'Content-Type': 'application/json-patch+json', - ...options?.headers - }, - url: '/api/v{api-version}/complex/{id}' - }); -}; - -export const callWithResultFromHeader = (options?: Options) => { - return (options?.client ?? client).post({ - ...options, - url: '/api/v{api-version}/header' - }); -}; - -export const testErrorCode = (options: Options) => { - return (options?.client ?? client).post({ - ...options, - url: '/api/v{api-version}/error' - }); -}; - -export const nonAsciiæøåÆøÅöôêÊ字符串 = (options: Options) => { - return (options?.client ?? client).post({ - ...options, - url: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串' - }); -}; - -/** - * Login User - */ -export const putWithFormUrlEncoded = (options: Options) => { - return (options?.client ?? client).put({ - ...options, - ...urlSearchParamsBodySerializer, - headers: { - 'Content-Type': 'application/x-www-form-urlencoded', - ...options?.headers - }, - url: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串' - }); -}; \ No newline at end of file diff --git a/packages/openapi-ts/test/sample.cjs b/packages/openapi-ts/test/sample.cjs index 241cbbed4..35997199a 100644 --- a/packages/openapi-ts/test/sample.cjs +++ b/packages/openapi-ts/test/sample.cjs @@ -32,6 +32,7 @@ const main = async () => { // asClass: true, // include... // name: '@hey-api/services', + // operationId: false, // serviceNameBuilder: '^Parameters', }, { -- 2.51.2 From 04f9318f720d0804db6de6593e5dd963d024aeb9 Mon Sep 17 00:00:00 2001 From: Lubos Date: Sun, 17 Nov 2024 21:37:13 +0800 Subject: [PATCH 12/13] chore: update fastify example --- .../openapi-ts-fastify/openapi-ts.config.ts | 2 +- .../src/client/fastify.gen.ts | 45 +++------- .../openapi-ts-fastify/src/client/index.ts | 1 - .../src/client/services.gen.ts | 60 ------------- .../src/client/types.gen.ts | 53 ++++++++++-- examples/openapi-ts-fastify/src/handlers.ts | 3 +- .../openapi-ts/src/plugins/fastify/plugin.ts | 84 ++++++++++++++----- .../plugins/fastify/default/fastify.gen.ts | 13 ++- .../plugins/fastify/default/fastify.gen.ts | 13 ++- 9 files changed, 138 insertions(+), 136 deletions(-) delete mode 100644 examples/openapi-ts-fastify/src/client/services.gen.ts diff --git a/examples/openapi-ts-fastify/openapi-ts.config.ts b/examples/openapi-ts-fastify/openapi-ts.config.ts index c9f038d3a..ba017b5b3 100644 --- a/examples/openapi-ts-fastify/openapi-ts.config.ts +++ b/examples/openapi-ts-fastify/openapi-ts.config.ts @@ -10,5 +10,5 @@ export default defineConfig({ lint: 'eslint', path: './src/client', }, - plugins: ['@hey-api/types', '@hey-api/services', 'fastify'], + plugins: ['fastify'], }); diff --git a/examples/openapi-ts-fastify/src/client/fastify.gen.ts b/examples/openapi-ts-fastify/src/client/fastify.gen.ts index f548242ab..e61a8453c 100644 --- a/examples/openapi-ts-fastify/src/client/fastify.gen.ts +++ b/examples/openapi-ts-fastify/src/client/fastify.gen.ts @@ -2,45 +2,24 @@ import type { RouteHandler } from 'fastify'; -export type Pet = { - id: number; - name: string; - tag?: string; -}; - -export type Pets = Array; - -export type Error = { - code: number; - message: string; -}; +import type { + CreatePetsResponses, + ListPetsData, + ListPetsResponses, + ShowPetByIdData, + ShowPetByIdResponses, +} from './types.gen'; export type RouteHandlers = { createPets: RouteHandler<{ - Reply: { - 201: unknown; - }; + Reply: CreatePetsResponses; }>; listPets: RouteHandler<{ - Querystring?: { - /** - * How many items to return at one time (max 100) - */ - limit?: number; - }; - Reply: { - 200: Pets; - }; + Querystring?: ListPetsData['query']; + Reply: ListPetsResponses; }>; showPetById: RouteHandler<{ - Params: { - /** - * The id of the pet to retrieve - */ - petId: string; - }; - Reply: { - 200: Pet; - }; + Params: ShowPetByIdData['path']; + Reply: ShowPetByIdResponses; }>; }; diff --git a/examples/openapi-ts-fastify/src/client/index.ts b/examples/openapi-ts-fastify/src/client/index.ts index 7311eb12c..343d3c8f7 100644 --- a/examples/openapi-ts-fastify/src/client/index.ts +++ b/examples/openapi-ts-fastify/src/client/index.ts @@ -1,3 +1,2 @@ // This file is auto-generated by @hey-api/openapi-ts -export * from './services.gen'; export * from './types.gen'; diff --git a/examples/openapi-ts-fastify/src/client/services.gen.ts b/examples/openapi-ts-fastify/src/client/services.gen.ts deleted file mode 100644 index 40d260228..000000000 --- a/examples/openapi-ts-fastify/src/client/services.gen.ts +++ /dev/null @@ -1,60 +0,0 @@ -// This file is auto-generated by @hey-api/openapi-ts - -import { - createClient, - createConfig, - type Options, -} from '@hey-api/client-fetch'; - -import type { - CreatePetsError, - ListPetsData, - ListPetsError, - ListPetsResponse, - ShowPetByIdData, - ShowPetByIdError, - ShowPetByIdResponse, -} from './types.gen'; - -export const client = createClient(createConfig()); - -/** - * List all pets - */ -export const listPets = ( - options?: Options, -) => - (options?.client ?? client).get< - ListPetsResponse, - ListPetsError, - ThrowOnError - >({ - ...options, - url: '/pets', - }); - -/** - * Create a pet - */ -export const createPets = ( - options?: Options, -) => - (options?.client ?? client).post({ - ...options, - url: '/pets', - }); - -/** - * Info for a specific pet - */ -export const showPetById = ( - options: Options, -) => - (options?.client ?? client).get< - ShowPetByIdResponse, - ShowPetByIdError, - ThrowOnError - >({ - ...options, - url: '/pets/{petId}', - }); diff --git a/examples/openapi-ts-fastify/src/client/types.gen.ts b/examples/openapi-ts-fastify/src/client/types.gen.ts index 8e0f71e19..e9563a3be 100644 --- a/examples/openapi-ts-fastify/src/client/types.gen.ts +++ b/examples/openapi-ts-fastify/src/client/types.gen.ts @@ -24,11 +24,39 @@ export type ListPetsData = { }; }; -export type ListPetsError = Error; +export type ListPetsErrors = { + /** + * unexpected error + */ + default: Error; +}; + +export type ListPetsError = ListPetsErrors[keyof ListPetsErrors]; + +export type ListPetsResponses = { + /** + * A paged array of pets + */ + 200: Pets; +}; + +export type ListPetsResponse = ListPetsResponses[keyof ListPetsResponses]; + +export type CreatePetsErrors = { + /** + * unexpected error + */ + default: Error; +}; -export type ListPetsResponse = Pets; +export type CreatePetsError = CreatePetsErrors[keyof CreatePetsErrors]; -export type CreatePetsError = Error; +export type CreatePetsResponses = { + /** + * Null response + */ + 201: unknown; +}; export type ShowPetByIdData = { body?: never; @@ -41,6 +69,21 @@ export type ShowPetByIdData = { query?: never; }; -export type ShowPetByIdError = Error; +export type ShowPetByIdErrors = { + /** + * unexpected error + */ + default: Error; +}; + +export type ShowPetByIdError = ShowPetByIdErrors[keyof ShowPetByIdErrors]; + +export type ShowPetByIdResponses = { + /** + * Expected response to a valid request + */ + 200: Pet; +}; -export type ShowPetByIdResponse = Pet; +export type ShowPetByIdResponse = + ShowPetByIdResponses[keyof ShowPetByIdResponses]; diff --git a/examples/openapi-ts-fastify/src/handlers.ts b/examples/openapi-ts-fastify/src/handlers.ts index 1907905e1..5f0ebf8ac 100644 --- a/examples/openapi-ts-fastify/src/handlers.ts +++ b/examples/openapi-ts-fastify/src/handlers.ts @@ -1,4 +1,5 @@ -import type { Pet, RouteHandlers } from './client/fastify.gen'; +import type { RouteHandlers } from './client/fastify.gen'; +import type { Pet } from './client/types.gen'; export const serviceHandlers: Pick = { showPetById(request, reply) { diff --git a/packages/openapi-ts/src/plugins/fastify/plugin.ts b/packages/openapi-ts/src/plugins/fastify/plugin.ts index 0a3014eda..cac6ba08b 100644 --- a/packages/openapi-ts/src/plugins/fastify/plugin.ts +++ b/packages/openapi-ts/src/plugins/fastify/plugin.ts @@ -7,6 +7,7 @@ import type { IRPathItemObject, IRPathsObject, } from '../../ir/ir'; +import { operationResponsesMap } from '../../ir/operation'; import { hasParameterGroupObjectRequired } from '../../ir/parameter'; import { operationIrRef } from '../@hey-api/services/plugin'; import type { PluginHandler } from '../types'; @@ -30,7 +31,6 @@ const operationToRouteHandler = ({ $ref: operationIrRef({ id: operation.id, type: 'data' }), namespace: 'type', }); - if (identifierData.name) { if (operation.body) { file.import({ @@ -93,20 +93,44 @@ const operationToRouteHandler = ({ } } + const { errors, responses } = operationResponsesMap(operation); + let errorsTypeReference: ts.TypeReferenceNode | undefined = undefined; const identifierErrors = fileTypes.identifier({ $ref: operationIrRef({ id: operation.id, type: 'errors' }), namespace: 'type', }); - if (identifierErrors.name) { - file.import({ - asType: true, - module: file.relativePathToFile({ context, id: 'types' }), - name: identifierErrors.name, - }); - errorsTypeReference = compiler.typeReferenceNode({ - typeName: identifierErrors.name, - }); + if (identifierErrors.name && errors && errors.properties) { + const keys = Object.keys(errors.properties); + if (keys.length) { + const hasDefaultResponse = keys.includes('default'); + if (!hasDefaultResponse) { + file.import({ + asType: true, + module: file.relativePathToFile({ context, id: 'types' }), + name: identifierErrors.name, + }); + errorsTypeReference = compiler.typeReferenceNode({ + typeName: identifierErrors.name, + }); + } else if (keys.length > 1) { + file.import({ + asType: true, + module: file.relativePathToFile({ context, id: 'types' }), + name: identifierErrors.name, + }); + const errorsType = compiler.typeReferenceNode({ + typeName: identifierErrors.name, + }); + const defaultType = compiler.literalTypeNode({ + literal: compiler.stringLiteral({ text: 'default' }), + }); + errorsTypeReference = compiler.typeReferenceNode({ + typeArguments: [errorsType, defaultType], + typeName: 'Omit', + }); + } + } } let responsesTypeReference: ts.TypeReferenceNode | undefined = undefined; @@ -114,15 +138,37 @@ const operationToRouteHandler = ({ $ref: operationIrRef({ id: operation.id, type: 'responses' }), namespace: 'type', }); - if (identifierResponses.name) { - file.import({ - asType: true, - module: file.relativePathToFile({ context, id: 'types' }), - name: identifierResponses.name, - }); - responsesTypeReference = compiler.typeReferenceNode({ - typeName: identifierResponses.name, - }); + if (identifierResponses.name && responses && responses.properties) { + const keys = Object.keys(responses.properties); + if (keys.length) { + const hasDefaultResponse = keys.includes('default'); + if (!hasDefaultResponse) { + file.import({ + asType: true, + module: file.relativePathToFile({ context, id: 'types' }), + name: identifierResponses.name, + }); + responsesTypeReference = compiler.typeReferenceNode({ + typeName: identifierResponses.name, + }); + } else if (keys.length > 1) { + file.import({ + asType: true, + module: file.relativePathToFile({ context, id: 'types' }), + name: identifierResponses.name, + }); + const responsesType = compiler.typeReferenceNode({ + typeName: identifierResponses.name, + }); + const defaultType = compiler.literalTypeNode({ + literal: compiler.stringLiteral({ text: 'default' }), + }); + responsesTypeReference = compiler.typeReferenceNode({ + typeArguments: [responsesType, defaultType], + typeName: 'Omit', + }); + } + } } const replyTypes = [errorsTypeReference, responsesTypeReference].filter( diff --git a/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/fastify/default/fastify.gen.ts b/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/fastify/default/fastify.gen.ts index b075b001e..b10bb2186 100644 --- a/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/fastify/default/fastify.gen.ts +++ b/packages/openapi-ts/test/__snapshots__/3.0.x/plugins/fastify/default/fastify.gen.ts @@ -1,19 +1,19 @@ // This file is auto-generated by @hey-api/openapi-ts -import type { ImportData, ImportResponses, ApiVversionOdataControllerCountResponses, GetApiVbyApiVersionSimpleOperationData, GetApiVbyApiVersionSimpleOperationErrors, GetApiVbyApiVersionSimpleOperationResponses, DeleteFooData3, CallWithDescriptionsData, DeprecatedCallData, CallWithParametersData, CallWithWeirdParameterNamesData, GetCallWithOptionalParamData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponses, PostApiVbyApiVersionRequestBodyData, PostApiVbyApiVersionFormDataData, CallWithDefaultParametersData, CallWithDefaultOptionalParametersData, CallToTestOrderOfParamsData, CallWithNoContentResponseResponses, CallWithResponseAndNoContentResponseResponses, DummyAResponses, DummyBResponses, CallWithResponseResponses, CallWithDuplicateResponsesErrors, CallWithDuplicateResponsesResponses, CallWithResponsesErrors, CallWithResponsesResponses, CollectionFormatData, TypesData, TypesResponses, UploadFileData, UploadFileResponses, FileResponseData, FileResponseResponses, ComplexTypesData, ComplexTypesErrors, ComplexTypesResponses, MultipartResponseResponses, MultipartRequestData, ComplexParamsData, ComplexParamsResponses, CallWithResultFromHeaderErrors, CallWithResultFromHeaderResponses, TestErrorCodeData, TestErrorCodeErrors, TestErrorCodeResponses, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Responses, PutWithFormUrlEncodedData } from './types.gen'; +import type { ImportData, ImportResponses, ApiVversionOdataControllerCountResponses, GetApiVbyApiVersionSimpleOperationData, GetApiVbyApiVersionSimpleOperationResponses, DeleteFooData3, CallWithDescriptionsData, DeprecatedCallData, CallWithParametersData, CallWithWeirdParameterNamesData, GetCallWithOptionalParamData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponses, PostApiVbyApiVersionRequestBodyData, PostApiVbyApiVersionFormDataData, CallWithDefaultParametersData, CallWithDefaultOptionalParametersData, CallToTestOrderOfParamsData, CallWithNoContentResponseResponses, CallWithResponseAndNoContentResponseResponses, DummyAResponses, DummyBResponses, CallWithDuplicateResponsesErrors, CallWithDuplicateResponsesResponses, CallWithResponsesErrors, CallWithResponsesResponses, CollectionFormatData, TypesData, TypesResponses, UploadFileData, UploadFileResponses, FileResponseData, FileResponseResponses, ComplexTypesData, ComplexTypesErrors, ComplexTypesResponses, MultipartResponseResponses, MultipartRequestData, ComplexParamsData, ComplexParamsResponses, CallWithResultFromHeaderErrors, CallWithResultFromHeaderResponses, TestErrorCodeData, TestErrorCodeErrors, TestErrorCodeResponses, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Responses, PutWithFormUrlEncodedData } from './types.gen'; import type { RouteHandler } from 'fastify'; export type RouteHandlers = { import: RouteHandler<{ Body: ImportData['body']; - Reply: ImportResponses; + Reply: Omit; }>; apiVVersionOdataControllerCount: RouteHandler<{ Reply: ApiVversionOdataControllerCountResponses; }>; getApiVbyApiVersionSimpleOperation: RouteHandler<{ Params: GetApiVbyApiVersionSimpleOperationData['path']; - Reply: GetApiVbyApiVersionSimpleOperationErrors & GetApiVbyApiVersionSimpleOperationResponses; + Reply: GetApiVbyApiVersionSimpleOperationResponses; }>; deleteFoo: RouteHandler<{ Headers: DeleteFooData3['headers']; @@ -75,14 +75,11 @@ export type RouteHandlers = { dummyB: RouteHandler<{ Reply: DummyBResponses; }>; - callWithResponse: RouteHandler<{ - Reply: CallWithResponseResponses; - }>; callWithDuplicateResponses: RouteHandler<{ - Reply: CallWithDuplicateResponsesErrors & CallWithDuplicateResponsesResponses; + Reply: Omit & CallWithDuplicateResponsesResponses; }>; callWithResponses: RouteHandler<{ - Reply: CallWithResponsesErrors & CallWithResponsesResponses; + Reply: Omit & CallWithResponsesResponses; }>; collectionFormat: RouteHandler<{ Querystring: CollectionFormatData['query']; diff --git a/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/fastify/default/fastify.gen.ts b/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/fastify/default/fastify.gen.ts index b075b001e..b10bb2186 100644 --- a/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/fastify/default/fastify.gen.ts +++ b/packages/openapi-ts/test/__snapshots__/3.1.x/plugins/fastify/default/fastify.gen.ts @@ -1,19 +1,19 @@ // This file is auto-generated by @hey-api/openapi-ts -import type { ImportData, ImportResponses, ApiVversionOdataControllerCountResponses, GetApiVbyApiVersionSimpleOperationData, GetApiVbyApiVersionSimpleOperationErrors, GetApiVbyApiVersionSimpleOperationResponses, DeleteFooData3, CallWithDescriptionsData, DeprecatedCallData, CallWithParametersData, CallWithWeirdParameterNamesData, GetCallWithOptionalParamData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponses, PostApiVbyApiVersionRequestBodyData, PostApiVbyApiVersionFormDataData, CallWithDefaultParametersData, CallWithDefaultOptionalParametersData, CallToTestOrderOfParamsData, CallWithNoContentResponseResponses, CallWithResponseAndNoContentResponseResponses, DummyAResponses, DummyBResponses, CallWithResponseResponses, CallWithDuplicateResponsesErrors, CallWithDuplicateResponsesResponses, CallWithResponsesErrors, CallWithResponsesResponses, CollectionFormatData, TypesData, TypesResponses, UploadFileData, UploadFileResponses, FileResponseData, FileResponseResponses, ComplexTypesData, ComplexTypesErrors, ComplexTypesResponses, MultipartResponseResponses, MultipartRequestData, ComplexParamsData, ComplexParamsResponses, CallWithResultFromHeaderErrors, CallWithResultFromHeaderResponses, TestErrorCodeData, TestErrorCodeErrors, TestErrorCodeResponses, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Responses, PutWithFormUrlEncodedData } from './types.gen'; +import type { ImportData, ImportResponses, ApiVversionOdataControllerCountResponses, GetApiVbyApiVersionSimpleOperationData, GetApiVbyApiVersionSimpleOperationResponses, DeleteFooData3, CallWithDescriptionsData, DeprecatedCallData, CallWithParametersData, CallWithWeirdParameterNamesData, GetCallWithOptionalParamData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponses, PostApiVbyApiVersionRequestBodyData, PostApiVbyApiVersionFormDataData, CallWithDefaultParametersData, CallWithDefaultOptionalParametersData, CallToTestOrderOfParamsData, CallWithNoContentResponseResponses, CallWithResponseAndNoContentResponseResponses, DummyAResponses, DummyBResponses, CallWithDuplicateResponsesErrors, CallWithDuplicateResponsesResponses, CallWithResponsesErrors, CallWithResponsesResponses, CollectionFormatData, TypesData, TypesResponses, UploadFileData, UploadFileResponses, FileResponseData, FileResponseResponses, ComplexTypesData, ComplexTypesErrors, ComplexTypesResponses, MultipartResponseResponses, MultipartRequestData, ComplexParamsData, ComplexParamsResponses, CallWithResultFromHeaderErrors, CallWithResultFromHeaderResponses, TestErrorCodeData, TestErrorCodeErrors, TestErrorCodeResponses, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Responses, PutWithFormUrlEncodedData } from './types.gen'; import type { RouteHandler } from 'fastify'; export type RouteHandlers = { import: RouteHandler<{ Body: ImportData['body']; - Reply: ImportResponses; + Reply: Omit; }>; apiVVersionOdataControllerCount: RouteHandler<{ Reply: ApiVversionOdataControllerCountResponses; }>; getApiVbyApiVersionSimpleOperation: RouteHandler<{ Params: GetApiVbyApiVersionSimpleOperationData['path']; - Reply: GetApiVbyApiVersionSimpleOperationErrors & GetApiVbyApiVersionSimpleOperationResponses; + Reply: GetApiVbyApiVersionSimpleOperationResponses; }>; deleteFoo: RouteHandler<{ Headers: DeleteFooData3['headers']; @@ -75,14 +75,11 @@ export type RouteHandlers = { dummyB: RouteHandler<{ Reply: DummyBResponses; }>; - callWithResponse: RouteHandler<{ - Reply: CallWithResponseResponses; - }>; callWithDuplicateResponses: RouteHandler<{ - Reply: CallWithDuplicateResponsesErrors & CallWithDuplicateResponsesResponses; + Reply: Omit & CallWithDuplicateResponsesResponses; }>; callWithResponses: RouteHandler<{ - Reply: CallWithResponsesErrors & CallWithResponsesResponses; + Reply: Omit & CallWithResponsesResponses; }>; collectionFormat: RouteHandler<{ Querystring: CollectionFormatData['query']; -- 2.51.2 From 4182e152965bd7b3398f07e01a50ebaa36f09a6c Mon Sep 17 00:00:00 2001 From: Lubos Date: Sun, 17 Nov 2024 22:40:33 +0800 Subject: [PATCH 13/13] docs: add documentation for Fastify plugin --- docs/.vitepress/config/en.ts | 4 + docs/embed.ts | 7 ++ docs/openapi-ts/configuration.md | 2 +- docs/openapi-ts/fastify.md | 75 +++++++++++++++++++ docs/openapi-ts/migrating.md | 6 ++ docs/openapi-ts/output.md | 2 +- docs/openapi-ts/tanstack-query.md | 4 +- .../openapi-ts-fastify/openapi-ts.config.ts | 2 +- .../openapi-ts-fastify/src/client/index.ts | 1 + .../src/client/services.gen.ts | 60 +++++++++++++++ examples/openapi-ts-fastify/src/handlers.ts | 21 +++--- 11 files changed, 169 insertions(+), 15 deletions(-) create mode 100644 docs/openapi-ts/fastify.md create mode 100644 examples/openapi-ts-fastify/src/client/services.gen.ts diff --git a/docs/.vitepress/config/en.ts b/docs/.vitepress/config/en.ts index 4a44f82c1..fc02a9c79 100644 --- a/docs/.vitepress/config/en.ts +++ b/docs/.vitepress/config/en.ts @@ -47,6 +47,10 @@ export default defineConfig({ }, { items: [ + { + link: '/openapi-ts/fastify', + text: 'Fastify', + }, { link: '/openapi-ts/tanstack-query', text: 'TanStack Query', diff --git a/docs/embed.ts b/docs/embed.ts index 82c2e7492..02ac4cf4d 100644 --- a/docs/embed.ts +++ b/docs/embed.ts @@ -25,6 +25,13 @@ export const embedProject = (projectId: string) => async (event: Event) => { 'openapi-ts.config.ts,src/client/schemas.gen.ts,src/client/services.gen.ts,src/client/types.gen.ts,src/App.tsx', view: 'editor', }); + case 'hey-api-client-fetch-plugin-fastify-example': + return await sdk.embedProjectId(container, projectId, { + height: 700, + openFile: + 'openapi-ts.config.ts,src/client/fastify.gen.ts,src/client/types.gen.ts,src/server.ts', + view: 'editor', + }); case 'hey-api-client-fetch-plugin-tanstack-react-query-example': return await sdk.embedProjectId(container, projectId, { height: 700, diff --git a/docs/openapi-ts/configuration.md b/docs/openapi-ts/configuration.md index e328db1d1..f30645bda 100644 --- a/docs/openapi-ts/configuration.md +++ b/docs/openapi-ts/configuration.md @@ -236,7 +236,7 @@ npx @hey-api/openapi-ts -i path/to/openapi.json -o src/client -c @hey-api/client The experimental parser produces a cleaner output while being faster than the legacy parser. It also supports features such as [Filters](#filters) and more will be added in the future. -The legacy parser will remain enabled for the [legacy clients](/openapi-ts/clients/legacy) regardless of the `experimentalParser` flag value. However, it's unlikely to receive any further updates. +The legacy parser will be used with the [legacy clients](/openapi-ts/clients/legacy) regardless of the `experimentalParser` flag value. However, it's unlikely to receive any further updates. ## Config API diff --git a/docs/openapi-ts/fastify.md b/docs/openapi-ts/fastify.md new file mode 100644 index 000000000..40a128940 --- /dev/null +++ b/docs/openapi-ts/fastify.md @@ -0,0 +1,75 @@ +--- +title: Fastify +description: Fastify plugin for Hey API. Compatible with all our features. +--- + +# Fastify + +::: warning +Fastify plugin is currently in beta. The interface might change before it becomes stable. We encourage you to leave feedback on [GitHub](https://github.com/hey-api/openapi-ts/issues). +::: + +[Fastify](https://fastify.dev/) is a fast and low overhead web framework for Node.js. + + + +## Features + +- seamless integration with `@hey-api/openapi-ts` ecosystem +- type-safe route handlers +- minimal learning curve thanks to extending the underlying technology + +## Installation + +::: warning +Fastify plugin works only with the [experimental parser](/openapi-ts/configuration#parser) which is currently an opt-in feature. +::: + +Ensure you have already [configured](/openapi-ts/get-started) `@hey-api/openapi-ts`. Update your configuration to use the Fastify plugin. + +```js +export default { + client: '@hey-api/client-fetch', + experimentalParser: true, // [!code ++] + input: 'path/to/openapi.json', + output: 'src/client', + plugins: [ + // ...other plugins + 'fastify', // [!code ++] + ], +}; +``` + +You can now generate Fastify artifacts. 🎉 + +## Output + +The Fastify plugin will generate the following artifacts, depending on the input specification. + +## Route Handlers + +Route handlers are generated from all endpoints. The generated interface follows the naming convention of services. + +```ts +const fastify = Fastify(); +const serviceHandlers: RouteHandlers = { + createPets(request, reply) { + reply.code(201).send(); + }, + listPets(request, reply) { + reply.code(200).send([]); + }, + showPetById(request, reply) { + reply.code(200).send({ + id: Number(request.params.petId), + name: 'Kitty', + }); + }, +}; +fastify.register(glue, { serviceHandlers }); +``` + + + diff --git a/docs/openapi-ts/migrating.md b/docs/openapi-ts/migrating.md index 4a8185d28..018e901f8 100644 --- a/docs/openapi-ts/migrating.md +++ b/docs/openapi-ts/migrating.md @@ -50,6 +50,12 @@ This config option is deprecated and will be removed in favor of [clients](./cli This config option is deprecated and will be removed. +## v0.56.0 + +### Deprecated `tree` in `@hey-api/types` + +This config option is deprecated and will be removed when the experimental parser becomes the default. + ## v0.55.0 This release adds the ability to filter your OpenAPI specification before it's processed. This feature will be useful if you are working with a large specification and are interested in generating output only from a small subset. diff --git a/docs/openapi-ts/output.md b/docs/openapi-ts/output.md index be42261ce..62cffdbb6 100644 --- a/docs/openapi-ts/output.md +++ b/docs/openapi-ts/output.md @@ -28,7 +28,7 @@ my-app/ └── package.json ``` -Each file is an artifact generated by a plugin. This is the default output, we will cover customizing it on this page. +Each file is an artifact generated by a Hey API plugin. This is the default output, we will cover customizing it on this page. These files also form the base for third-party plugins. Let's go through each file in the `src/client` folder and explain what it looks like, what it does, and how to use it. diff --git a/docs/openapi-ts/tanstack-query.md b/docs/openapi-ts/tanstack-query.md index c509eee9f..f63fdbcd8 100644 --- a/docs/openapi-ts/tanstack-query.md +++ b/docs/openapi-ts/tanstack-query.md @@ -94,11 +94,11 @@ export default { ::: -You can now run `openapi-ts` to generate TanStack Query artifacts. 🎉 +You can now generate TanStack Query artifacts. 🎉 ## Output -The TanStack Query plugin will optionally generate the following output layers, depending on the input specification. +The TanStack Query plugin will optionally generate the following artifacts, depending on the input specification. ## Queries diff --git a/examples/openapi-ts-fastify/openapi-ts.config.ts b/examples/openapi-ts-fastify/openapi-ts.config.ts index ba017b5b3..fb3cc8aed 100644 --- a/examples/openapi-ts-fastify/openapi-ts.config.ts +++ b/examples/openapi-ts-fastify/openapi-ts.config.ts @@ -10,5 +10,5 @@ export default defineConfig({ lint: 'eslint', path: './src/client', }, - plugins: ['fastify'], + plugins: ['fastify', '@hey-api/services'], }); diff --git a/examples/openapi-ts-fastify/src/client/index.ts b/examples/openapi-ts-fastify/src/client/index.ts index 343d3c8f7..7311eb12c 100644 --- a/examples/openapi-ts-fastify/src/client/index.ts +++ b/examples/openapi-ts-fastify/src/client/index.ts @@ -1,2 +1,3 @@ // This file is auto-generated by @hey-api/openapi-ts +export * from './services.gen'; export * from './types.gen'; diff --git a/examples/openapi-ts-fastify/src/client/services.gen.ts b/examples/openapi-ts-fastify/src/client/services.gen.ts new file mode 100644 index 000000000..40d260228 --- /dev/null +++ b/examples/openapi-ts-fastify/src/client/services.gen.ts @@ -0,0 +1,60 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { + createClient, + createConfig, + type Options, +} from '@hey-api/client-fetch'; + +import type { + CreatePetsError, + ListPetsData, + ListPetsError, + ListPetsResponse, + ShowPetByIdData, + ShowPetByIdError, + ShowPetByIdResponse, +} from './types.gen'; + +export const client = createClient(createConfig()); + +/** + * List all pets + */ +export const listPets = ( + options?: Options, +) => + (options?.client ?? client).get< + ListPetsResponse, + ListPetsError, + ThrowOnError + >({ + ...options, + url: '/pets', + }); + +/** + * Create a pet + */ +export const createPets = ( + options?: Options, +) => + (options?.client ?? client).post({ + ...options, + url: '/pets', + }); + +/** + * Info for a specific pet + */ +export const showPetById = ( + options: Options, +) => + (options?.client ?? client).get< + ShowPetByIdResponse, + ShowPetByIdError, + ThrowOnError + >({ + ...options, + url: '/pets/{petId}', + }); diff --git a/examples/openapi-ts-fastify/src/handlers.ts b/examples/openapi-ts-fastify/src/handlers.ts index 5f0ebf8ac..c4d94692a 100644 --- a/examples/openapi-ts-fastify/src/handlers.ts +++ b/examples/openapi-ts-fastify/src/handlers.ts @@ -1,15 +1,16 @@ import type { RouteHandlers } from './client/fastify.gen'; -import type { Pet } from './client/types.gen'; -export const serviceHandlers: Pick = { +export const serviceHandlers: RouteHandlers = { + createPets(request, reply) { + reply.code(201).send(); + }, + listPets(request, reply) { + reply.code(200).send([]); + }, showPetById(request, reply) { - const { - params: { petId }, - } = request; - const pet: Pet = { - id: Number(petId), - name: 'petname', - }; - reply.code(200).send(pet); + reply.code(200).send({ + id: Number(request.params.petId), + name: 'Kitty', + }); }, };