From 1f52b260807531edb2c14003473ea4907007ecdb Mon Sep 17 00:00:00 2001 From: Lubos Date: Mon, 1 Jul 2024 06:39:32 +0100 Subject: [PATCH] fix: generate service types when types are enabled, even if services are disabled --- .changeset/great-planets-kick.md | 5 + packages/openapi-ts/src/utils/write/types.ts | 4 +- .../test/generated/v3_date/types.gen.ts.snap | 774 ++++++++ .../generated/v3_models/types.gen.ts.snap | 871 --------- .../generated/v3_pascalcase/types.gen.ts.snap | 776 +++++++- .../{v3_models => v3_types}/index.ts.snap | 0 .../test/generated/v3_types/types.gen.ts.snap | 1645 +++++++++++++++++ packages/openapi-ts/test/index.spec.ts | 20 +- 8 files changed, 3210 insertions(+), 885 deletions(-) create mode 100644 .changeset/great-planets-kick.md delete mode 100644 packages/openapi-ts/test/__snapshots__/test/generated/v3_models/types.gen.ts.snap rename packages/openapi-ts/test/__snapshots__/test/generated/{v3_models => v3_types}/index.ts.snap (100%) create mode 100644 packages/openapi-ts/test/__snapshots__/test/generated/v3_types/types.gen.ts.snap diff --git a/.changeset/great-planets-kick.md b/.changeset/great-planets-kick.md new file mode 100644 index 000000000..a6bcaa4d7 --- /dev/null +++ b/.changeset/great-planets-kick.md @@ -0,0 +1,5 @@ +--- +'@hey-api/openapi-ts': patch +--- + +fix: generate service types when types are enabled, even if services are disabled diff --git a/packages/openapi-ts/src/utils/write/types.ts b/packages/openapi-ts/src/utils/write/types.ts index 6c005f070..707bbaf2a 100644 --- a/packages/openapi-ts/src/utils/write/types.ts +++ b/packages/openapi-ts/src/utils/write/types.ts @@ -528,7 +528,5 @@ export const processTypes = async ({ processModel({ client, model, onNode }); } - if (files.services && client.services.length) { - processServiceTypes({ client, onNode }); - } + processServiceTypes({ client, onNode }); }; diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_date/types.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_date/types.gen.ts.snap index c47f050ea..fde9802d2 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_date/types.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_date/types.gen.ts.snap @@ -13,4 +13,778 @@ export type ModelWithPattern = { patternWithSingleQuotes?: string; patternWithNewline?: string; patternWithBacktick?: string; +}; + +export type PostServiceWithEmptyTagData = { + requestBody: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; +}; + +export type PostServiceWithEmptyTagResponse = ModelWithReadOnlyAndWriteOnly; + +export type ApiVversionOdataControllerCountResponse = Model_From_Zendesk; + +export type DeleteFooData = { + /** + * bar in method + */ + barParam: string; + /** + * foo in method + */ + fooParam: string; + /** + * Parameter with illegal characters + */ + xFooBar: ModelWithString; +}; + +export type CallWithDescriptionsData = { + /** + * Testing backticks in string: `backticks` and ```multiple backticks``` should work + */ + parameterWithBackticks?: unknown; + /** + * Testing multiline comments in string: First line + * Second line + * + * Fourth line + */ + parameterWithBreaks?: unknown; + /** + * Testing expression placeholders in string: ${expression} should work + */ + parameterWithExpressionPlaceholders?: unknown; + /** + * Testing quotes in string: 'single quote''' and "double quotes""" should work + */ + parameterWithQuotes?: unknown; + /** + * Testing reserved characters in string: * inline * and ** inline ** should work + */ + parameterWithReservedCharacters?: unknown; + /** + * Testing slashes in string: \backwards\\\ and /forwards/// should work + */ + parameterWithSlashes?: unknown; +}; + +export type DeprecatedCallData = { + /** + * This parameter is deprecated + * @deprecated + */ + parameter: DeprecatedModel | null; +}; + +export type CallWithParametersData = { + fooAllOfEnum: ModelWithNestedArrayEnumsDataFoo; + fooRefEnum?: ModelWithNestedArrayEnumsDataFoo; + /** + * This is the parameter that goes into the cookie + */ + parameterCookie: string | null; + /** + * This is the parameter that goes into the form data + */ + parameterForm: string | null; + /** + * This is the parameter that goes into the header + */ + parameterHeader: string | null; + /** + * This is the parameter that goes into the path + */ + parameterPath: string | null; + /** + * This is the parameter that goes into the query params + */ + parameterQuery: string | null; + /** + * This is the parameter that goes into the body + */ + requestBody: ModelWithString | null; +}; + +export type CallWithWeirdParameterNamesData = { + /** + * This is the parameter with a reserved keyword + */ + _default?: string; + /** + * This is the parameter that goes into the cookie + */ + parameterCookie: string | null; + /** + * This is the parameter that goes into the request form data + */ + parameterForm: string | null; + /** + * This is the parameter that goes into the request header + */ + parameterHeader: string | null; + /** + * This is the parameter that goes into the path + */ + parameterPath1?: string; + /** + * This is the parameter that goes into the path + */ + parameterPath2?: string; + /** + * This is the parameter that goes into the path + */ + parameterPath3?: string; + /** + * This is the parameter that goes into the request query params + */ + parameterQuery: string | null; + /** + * This is the parameter that goes into the body + */ + requestBody: ModelWithString | null; +}; + +export type GetCallWithOptionalParamData = { + /** + * This is an optional parameter + */ + parameter?: string; + /** + * This is a required parameter + */ + requestBody: ModelWithOneOfEnum; +}; + +export type PostCallWithOptionalParamData = { + /** + * This is a required parameter + */ + parameter: Pageable; + /** + * This is an optional parameter + */ + requestBody?: ModelWithString; +}; + +export type PostApiRequestBodyData = { + /** + * A reusable request body + */ + foo?: ModelWithString; + /** + * This is a reusable parameter + */ + parameter?: string; +}; + +export type PostApiFormDataData = { + /** + * A reusable request body + */ + formData?: ModelWithString; + /** + * This is a reusable parameter + */ + parameter?: string; +}; + +export type CallWithDefaultParametersData = { + /** + * 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; + /** + * This is a simple number with default value + */ + parameterNumber?: number | null; + /** + * This is a simple string with default value + */ + parameterString?: string | null; +}; + +export type CallWithDefaultOptionalParametersData = { + /** + * 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; + /** + * This is a simple number that is optional with default value + */ + parameterNumber?: number; + /** + * This is a simple string that is optional with default value + */ + parameterString?: string; +}; + +export type CallToTestOrderOfParamsData = { + /** + * 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 that can be null with default + */ + parameterStringNullableWithDefault?: string | null; + /** + * This is a string that can be null with no default + */ + parameterStringNullableWithNoDefault?: string | null; + /** + * 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; +}; + +export type CallWithNoContentResponseResponse = void; + +export type CallWithResponseAndNoContentResponseResponse = number | void; + +export type DummyAResponse = void; + +export type DummyBResponse = void; + +export type CallWithResponseResponse = ModelWithString; + +export type CallWithDuplicateResponsesResponse = ModelWithBoolean & ModelWithInteger | ModelWithString; + +export type CallWithResponsesResponse = { + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; + readonly value?: Array; +} | ModelThatExtends | ModelThatExtendsExtends; + +export type CollectionFormatData = { + /** + * This is an array parameter that is sent as csv format (comma-separated values) + */ + parameterArrayCsv: Array<(string)> | null; + /** + * This is an array parameter that is sent as multi format (multiple parameter instances) + */ + parameterArrayMulti: Array<(string)> | null; + /** + * This is an array parameter that is sent as pipes format (pipe-separated values) + */ + parameterArrayPipes: Array<(string)> | null; + /** + * This is an array parameter that is sent as ssv format (space-separated values) + */ + parameterArraySsv: Array<(string)> | null; + /** + * This is an array parameter that is sent as tsv format (tab-separated values) + */ + parameterArrayTsv: Array<(string)> | null; +}; + +export type TypesData = { + /** + * This is a number parameter + */ + id?: number; + /** + * This is an array parameter + */ + parameterArray: Array<(string)> | null; + /** + * This is a boolean parameter + */ + parameterBoolean: boolean | null; + /** + * This is a dictionary parameter + */ + parameterDictionary: { + [key: string]: unknown; + } | null; + /** + * This is an enum parameter + */ + parameterEnum: 'Success' | 'Warning' | 'Error' | null; + /** + * This is a number parameter + */ + parameterNumber: number; + /** + * This is an object parameter + */ + parameterObject: { + [key: string]: unknown; + } | null; + /** + * This is a string parameter + */ + parameterString: string | null; +}; + +export type TypesResponse = number | string | boolean | { + [key: string]: unknown; +}; + +export type UploadFileData = { + /** + * Supply a file reference for upload + */ + file: (Blob | File); +}; + +export type UploadFileResponse = boolean; + +export type FileResponseData = { + id: string; +}; + +export type FileResponseResponse = (Blob | File); + +export type ComplexTypesData = { + /** + * Parameter containing object + */ + parameterObject: { + first?: { + second?: { + third?: string; + }; + }; + }; + /** + * Parameter containing reference + */ + parameterReference: ModelWithString; +}; + +export type ComplexTypesResponse = Array; + +export type MultipartRequestData = { + formData?: { + content?: (Blob | File); + data?: ModelWithString | null; + }; +}; + +export type MultipartResponseResponse = { + file?: (Blob | File); + metadata?: { + foo?: string; + bar?: string; + }; +}; + +export type ComplexParamsData = { + id: number; + requestBody?: { + readonly key: string | null; + name: string | null; + enabled?: boolean; + readonly type: 'Monkey' | 'Horse' | 'Bird'; + listOfModels?: Array | null; + listOfStrings?: Array<(string)> | null; + parameters: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; + readonly user?: { + readonly id?: number; + readonly name?: string | null; + }; + }; +}; + +export type ComplexParamsResponse = ModelWithString; + +export type CallWithResultFromHeaderResponse = string; + +export type TestErrorCodeData = { + /** + * Status code to return + */ + status: number; +}; + +export type TestErrorCodeResponse = unknown; + +export type NonAsciiæøåÆøÅöôêÊ字符串Data = { + /** + * Dummy input param + */ + nonAsciiParamæøåÆøÅöôêÊ: number; +}; + +export type NonAsciiæøåÆøÅöôêÊ字符串Response = Array; + +export type $OpenApiTs = { + '/api/v{api-version}/no-tag': { + post: { + req: PostServiceWithEmptyTagData; + res: { + default: ModelWithReadOnlyAndWriteOnly; + }; + }; + }; + '/api/v{api-version}/simple/$count': { + get: { + res: { + /** + * Success + */ + 200: Model_From_Zendesk; + }; + }; + }; + '/api/v{api-version}/foo/{foo_param}/bar/{BarParam}': { + delete: { + req: DeleteFooData; + }; + }; + '/api/v{api-version}/descriptions/': { + post: { + req: CallWithDescriptionsData; + }; + }; + '/api/v{api-version}/parameters/deprecated': { + post: { + req: DeprecatedCallData; + }; + }; + '/api/v{api-version}/parameters/{parameterPath}': { + post: { + req: CallWithParametersData; + }; + }; + '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}': { + post: { + req: CallWithWeirdParameterNamesData; + }; + }; + '/api/v{api-version}/parameters/': { + get: { + req: GetCallWithOptionalParamData; + }; + post: { + req: PostCallWithOptionalParamData; + }; + }; + '/api/v{api-version}/requestBody/': { + post: { + req: PostApiRequestBodyData; + }; + }; + '/api/v{api-version}/formData/': { + post: { + req: PostApiFormDataData; + }; + }; + '/api/v{api-version}/defaults': { + get: { + req: CallWithDefaultParametersData; + }; + post: { + req: CallWithDefaultOptionalParametersData; + }; + put: { + req: CallToTestOrderOfParamsData; + }; + }; + '/api/v{api-version}/no-content': { + get: { + res: { + /** + * Success + */ + 204: void; + }; + }; + }; + '/api/v{api-version}/multiple-tags/response-and-no-content': { + get: { + res: { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; + }; + }; + }; + '/api/v{api-version}/multiple-tags/a': { + get: { + res: { + /** + * Success + */ + 204: void; + }; + }; + }; + '/api/v{api-version}/multiple-tags/b': { + get: { + res: { + /** + * Success + */ + 204: void; + }; + }; + }; + '/api/v{api-version}/response': { + get: { + res: { + default: ModelWithString; + }; + }; + post: { + res: { + /** + * Message for 200 response + */ + 200: ModelWithBoolean & ModelWithInteger; + /** + * Message for 201 response + */ + 201: ModelWithString; + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for 4XX errors + */ + '4XX': DictionaryWithArray; + /** + * Message for default response + */ + default: ModelWithBoolean; + }; + }; + put: { + res: { + /** + * 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; + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for default response + */ + default: ModelWithString; + }; + }; + }; + '/api/v{api-version}/collectionFormat': { + get: { + req: CollectionFormatData; + }; + }; + '/api/v{api-version}/types': { + get: { + req: TypesData; + res: { + /** + * 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: { + [key: string]: unknown; + }; + }; + }; + }; + '/api/v{api-version}/upload': { + post: { + req: UploadFileData; + res: { + 200: boolean; + }; + }; + }; + '/api/v{api-version}/file/{id}': { + get: { + req: FileResponseData; + res: { + /** + * Success + */ + 200: (Blob | File); + }; + }; + }; + '/api/v{api-version}/complex': { + get: { + req: ComplexTypesData; + res: { + /** + * Successful response + */ + 200: Array; + /** + * 400 `server` error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; + }; + }; + }; + '/api/v{api-version}/multipart': { + post: { + req: MultipartRequestData; + }; + get: { + res: { + /** + * OK + */ + 200: { + file?: (Blob | File); + metadata?: { + foo?: string; + bar?: string; + }; + }; + }; + }; + }; + '/api/v{api-version}/complex/{id}': { + put: { + req: ComplexParamsData; + res: { + /** + * Success + */ + 200: ModelWithString; + }; + }; + }; + '/api/v{api-version}/header': { + post: { + res: { + /** + * Successful response + */ + 200: string; + /** + * 400 server error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; + }; + }; + }; + '/api/v{api-version}/error': { + post: { + req: TestErrorCodeData; + res: { + /** + * Custom message: Successful response + */ + 200: unknown; + /** + * 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; + }; + }; + }; + '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串': { + post: { + req: NonAsciiæøåÆøÅöôêÊ字符串Data; + res: { + /** + * Successful response + */ + 200: Array; + }; + }; + }; }; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_models/types.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_models/types.gen.ts.snap deleted file mode 100644 index 0b59bff27..000000000 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_models/types.gen.ts.snap +++ /dev/null @@ -1,871 +0,0 @@ -// This file is auto-generated by @hey-api/openapi-ts - -/** - * 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<(number)>; - -/** - * This is a simple array with booleans - */ -export type ArrayWithBooleans = Array<(boolean)>; - -/** - * This is a simple array with strings - */ -export type ArrayWithStrings = Array<(string)>; - -/** - * 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 simple enum with strings - */ -export type 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?: boolean; -}; - -/** - * These are the HTTP error code enums - */ -export type statusCode = '100' | '200 FOO' | '300 FOO_BAR' | '400 foo-bar' | '500 foo.bar' | '600 foo&bar'; - -/** - * This is a model with one enum with escaped name - */ -export type ModelWithEnumWithHyphen = { - 'foo-bar-baz-qux'?: '3.0'; -}; - -export type 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<(number)>; - /** - * 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<((Blob | File))>; - propWithNumber?: Array<(number)>; -}; - -/** - * This is a model with one property containing an array - */ -export type ModelWithArray = { - prop?: Array; - propWithFile?: Array<((Blob | File))>; - propWithNumber?: Array<(number)>; -}; - -/** - * 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: 'circle'; - radius?: number; -}; - -/** - * Square - */ -export type ModelSquare = { - kind: 'square'; - sideLength?: number; -}; - -/** - * This is a model with one property with a 'one of' relationship where the options are not $ref - */ -export type CompositionWithOneOfDiscriminator = ModelCircle | 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<(ModelWithDictionary | null)> | Array<(ModelWithArray | null)>; -}; - -export type e_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<(e_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<(boolean)>; -}; -}; - -/** - * This is a model that contains a dictionary of complex arrays (composited) within composition - */ -export type CompositionWithOneOfAndComplexArrayDictionary = { - propA?: boolean | { - [key: string]: Array<(number | string)>; -}; -}; - -/** - * 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 & { - firstName: string; - lastname: string; - age: number; -}; - -/** - * 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<(string)>; -}; - -/** - * This is a free-form object without additionalProperties. - */ -export type FreeFormObjectWithoutAdditionalProperties = { - [key: string]: unknown; -}; - -/** - * 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 = { - [key: string]: unknown; -}; - -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; -}; - -export type NestedAnyOfArraysNullable = { - nullableArray?: Array<(string | boolean)> | null; -}; - -export type CompositionWithOneOfAndProperties = { - foo: ParameterSimpleParameter; - baz: number | null; - qux: number; -} | { - 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 foo = 'Bar'; - -export type ModelWithNestedArrayEnumsDataFoo = 'foo' | 'bar'; - -export type ModelWithNestedArrayEnumsDataBar = 'baz' | 'qux'; - -export type ModelWithNestedArrayEnumsData = { - foo?: Array; - bar?: Array; -}; - -export type ModelWithNestedArrayEnums = { - array_strings?: Array<(string)>; - 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 | string, - number | string -]; - -export type ModelWithAnyOfConstantSizeArrayAndIntersect = [ - number & string, - number & string -]; - -export type ModelWithNumericEnumUnion = { - /** - * Период - */ - value?: -10 | -1 | 0 | 1 | 3 | 6 | 12; -}; - -/** - * Период - */ -export type 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; -}; - -/** - * 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; - -/** - * This is a reusable parameter - */ -export type ParameterSimpleParameter = string; - -/** - * Parameter with illegal characters - */ -export type Parameterx_Foo_Bar = ModelWithString; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_pascalcase/types.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_pascalcase/types.gen.ts.snap index e6d615aca..2592f14bf 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_pascalcase/types.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_pascalcase/types.gen.ts.snap @@ -14,4 +14,778 @@ export type CamelCaseCommentWithBreaks = number; export type ArrayWithProperties = Array<{ '16x16'?: CamelCaseCommentWithBreaks; bar?: string; -}>; \ No newline at end of file +}>; + +export type PostServiceWithEmptyTagData = { + requestBody: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; +}; + +export type PostServiceWithEmptyTagResponse = ModelWithReadOnlyAndWriteOnly; + +export type ApiVversionOdataControllerCountResponse = ModelFromZendesk; + +export type DeleteFooData = { + /** + * bar in method + */ + barParam: string; + /** + * foo in method + */ + fooParam: string; + /** + * Parameter with illegal characters + */ + xFooBar: ModelWithString; +}; + +export type CallWithDescriptionsData = { + /** + * Testing backticks in string: `backticks` and ```multiple backticks``` should work + */ + parameterWithBackticks?: unknown; + /** + * Testing multiline comments in string: First line + * Second line + * + * Fourth line + */ + parameterWithBreaks?: unknown; + /** + * Testing expression placeholders in string: ${expression} should work + */ + parameterWithExpressionPlaceholders?: unknown; + /** + * Testing quotes in string: 'single quote''' and "double quotes""" should work + */ + parameterWithQuotes?: unknown; + /** + * Testing reserved characters in string: * inline * and ** inline ** should work + */ + parameterWithReservedCharacters?: unknown; + /** + * Testing slashes in string: \backwards\\\ and /forwards/// should work + */ + parameterWithSlashes?: unknown; +}; + +export type DeprecatedCallData = { + /** + * This parameter is deprecated + * @deprecated + */ + parameter: DeprecatedModel | null; +}; + +export type CallWithParametersData = { + fooAllOfEnum: ModelWithNestedArrayEnumsDataFoo; + fooRefEnum?: ModelWithNestedArrayEnumsDataFoo; + /** + * This is the parameter that goes into the cookie + */ + parameterCookie: string | null; + /** + * This is the parameter that goes into the form data + */ + parameterForm: string | null; + /** + * This is the parameter that goes into the header + */ + parameterHeader: string | null; + /** + * This is the parameter that goes into the path + */ + parameterPath: string | null; + /** + * This is the parameter that goes into the query params + */ + parameterQuery: string | null; + /** + * This is the parameter that goes into the body + */ + requestBody: ModelWithString | null; +}; + +export type CallWithWeirdParameterNamesData = { + /** + * This is the parameter with a reserved keyword + */ + _default?: string; + /** + * This is the parameter that goes into the cookie + */ + parameterCookie: string | null; + /** + * This is the parameter that goes into the request form data + */ + parameterForm: string | null; + /** + * This is the parameter that goes into the request header + */ + parameterHeader: string | null; + /** + * This is the parameter that goes into the path + */ + parameterPath1?: string; + /** + * This is the parameter that goes into the path + */ + parameterPath2?: string; + /** + * This is the parameter that goes into the path + */ + parameterPath3?: string; + /** + * This is the parameter that goes into the request query params + */ + parameterQuery: string | null; + /** + * This is the parameter that goes into the body + */ + requestBody: ModelWithString | null; +}; + +export type GetCallWithOptionalParamData = { + /** + * This is an optional parameter + */ + parameter?: string; + /** + * This is a required parameter + */ + requestBody: ModelWithOneOfEnum; +}; + +export type PostCallWithOptionalParamData = { + /** + * This is a required parameter + */ + parameter: Pageable; + /** + * This is an optional parameter + */ + requestBody?: ModelWithString; +}; + +export type PostApiRequestBodyData = { + /** + * A reusable request body + */ + foo?: ModelWithString; + /** + * This is a reusable parameter + */ + parameter?: string; +}; + +export type PostApiFormDataData = { + /** + * A reusable request body + */ + formData?: ModelWithString; + /** + * This is a reusable parameter + */ + parameter?: string; +}; + +export type CallWithDefaultParametersData = { + /** + * 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; + /** + * This is a simple number with default value + */ + parameterNumber?: number | null; + /** + * This is a simple string with default value + */ + parameterString?: string | null; +}; + +export type CallWithDefaultOptionalParametersData = { + /** + * 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; + /** + * This is a simple number that is optional with default value + */ + parameterNumber?: number; + /** + * This is a simple string that is optional with default value + */ + parameterString?: string; +}; + +export type CallToTestOrderOfParamsData = { + /** + * 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 that can be null with default + */ + parameterStringNullableWithDefault?: string | null; + /** + * This is a string that can be null with no default + */ + parameterStringNullableWithNoDefault?: string | null; + /** + * 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; +}; + +export type CallWithNoContentResponseResponse = void; + +export type CallWithResponseAndNoContentResponseResponse = number | void; + +export type DummyAResponse = void; + +export type DummyBResponse = void; + +export type CallWithResponseResponse = ModelWithString; + +export type CallWithDuplicateResponsesResponse = ModelWithBoolean & ModelWithInteger | ModelWithString; + +export type CallWithResponsesResponse = { + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; + readonly value?: Array; +} | ModelThatExtends | ModelThatExtendsExtends; + +export type CollectionFormatData = { + /** + * This is an array parameter that is sent as csv format (comma-separated values) + */ + parameterArrayCsv: Array<(string)> | null; + /** + * This is an array parameter that is sent as multi format (multiple parameter instances) + */ + parameterArrayMulti: Array<(string)> | null; + /** + * This is an array parameter that is sent as pipes format (pipe-separated values) + */ + parameterArrayPipes: Array<(string)> | null; + /** + * This is an array parameter that is sent as ssv format (space-separated values) + */ + parameterArraySsv: Array<(string)> | null; + /** + * This is an array parameter that is sent as tsv format (tab-separated values) + */ + parameterArrayTsv: Array<(string)> | null; +}; + +export type TypesData = { + /** + * This is a number parameter + */ + id?: number; + /** + * This is an array parameter + */ + parameterArray: Array<(string)> | null; + /** + * This is a boolean parameter + */ + parameterBoolean: boolean | null; + /** + * This is a dictionary parameter + */ + parameterDictionary: { + [key: string]: unknown; + } | null; + /** + * This is an enum parameter + */ + parameterEnum: 'Success' | 'Warning' | 'Error' | null; + /** + * This is a number parameter + */ + parameterNumber: number; + /** + * This is an object parameter + */ + parameterObject: { + [key: string]: unknown; + } | null; + /** + * This is a string parameter + */ + parameterString: string | null; +}; + +export type TypesResponse = number | string | boolean | { + [key: string]: unknown; +}; + +export type UploadFileData = { + /** + * Supply a file reference for upload + */ + file: (Blob | File); +}; + +export type UploadFileResponse = boolean; + +export type FileResponseData = { + id: string; +}; + +export type FileResponseResponse = (Blob | File); + +export type ComplexTypesData = { + /** + * Parameter containing object + */ + parameterObject: { + first?: { + second?: { + third?: string; + }; + }; + }; + /** + * Parameter containing reference + */ + parameterReference: ModelWithString; +}; + +export type ComplexTypesResponse = Array; + +export type MultipartRequestData = { + formData?: { + content?: (Blob | File); + data?: ModelWithString | null; + }; +}; + +export type MultipartResponseResponse = { + file?: (Blob | File); + metadata?: { + foo?: string; + bar?: string; + }; +}; + +export type ComplexParamsData = { + id: number; + requestBody?: { + readonly key: string | null; + name: string | null; + enabled?: boolean; + readonly type: 'Monkey' | 'Horse' | 'Bird'; + listOfModels?: Array | null; + listOfStrings?: Array<(string)> | null; + parameters: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; + readonly user?: { + readonly id?: number; + readonly name?: string | null; + }; + }; +}; + +export type ComplexParamsResponse = ModelWithString; + +export type CallWithResultFromHeaderResponse = string; + +export type TestErrorCodeData = { + /** + * Status code to return + */ + status: number; +}; + +export type TestErrorCodeResponse = unknown; + +export type NonAsciiæøåÆøÅöôêÊ字符串Data = { + /** + * Dummy input param + */ + nonAsciiParamæøåÆøÅöôêÊ: number; +}; + +export type NonAsciiæøåÆøÅöôêÊ字符串Response = Array; + +export type $OpenApiTs = { + '/api/v{api-version}/no-tag': { + post: { + req: PostServiceWithEmptyTagData; + res: { + default: ModelWithReadOnlyAndWriteOnly; + }; + }; + }; + '/api/v{api-version}/simple/$count': { + get: { + res: { + /** + * Success + */ + 200: ModelFromZendesk; + }; + }; + }; + '/api/v{api-version}/foo/{foo_param}/bar/{BarParam}': { + delete: { + req: DeleteFooData; + }; + }; + '/api/v{api-version}/descriptions/': { + post: { + req: CallWithDescriptionsData; + }; + }; + '/api/v{api-version}/parameters/deprecated': { + post: { + req: DeprecatedCallData; + }; + }; + '/api/v{api-version}/parameters/{parameterPath}': { + post: { + req: CallWithParametersData; + }; + }; + '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}': { + post: { + req: CallWithWeirdParameterNamesData; + }; + }; + '/api/v{api-version}/parameters/': { + get: { + req: GetCallWithOptionalParamData; + }; + post: { + req: PostCallWithOptionalParamData; + }; + }; + '/api/v{api-version}/requestBody/': { + post: { + req: PostApiRequestBodyData; + }; + }; + '/api/v{api-version}/formData/': { + post: { + req: PostApiFormDataData; + }; + }; + '/api/v{api-version}/defaults': { + get: { + req: CallWithDefaultParametersData; + }; + post: { + req: CallWithDefaultOptionalParametersData; + }; + put: { + req: CallToTestOrderOfParamsData; + }; + }; + '/api/v{api-version}/no-content': { + get: { + res: { + /** + * Success + */ + 204: void; + }; + }; + }; + '/api/v{api-version}/multiple-tags/response-and-no-content': { + get: { + res: { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; + }; + }; + }; + '/api/v{api-version}/multiple-tags/a': { + get: { + res: { + /** + * Success + */ + 204: void; + }; + }; + }; + '/api/v{api-version}/multiple-tags/b': { + get: { + res: { + /** + * Success + */ + 204: void; + }; + }; + }; + '/api/v{api-version}/response': { + get: { + res: { + default: ModelWithString; + }; + }; + post: { + res: { + /** + * Message for 200 response + */ + 200: ModelWithBoolean & ModelWithInteger; + /** + * Message for 201 response + */ + 201: ModelWithString; + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for 4XX errors + */ + '4XX': DictionaryWithArray; + /** + * Message for default response + */ + default: ModelWithBoolean; + }; + }; + put: { + res: { + /** + * 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; + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for default response + */ + default: ModelWithString; + }; + }; + }; + '/api/v{api-version}/collectionFormat': { + get: { + req: CollectionFormatData; + }; + }; + '/api/v{api-version}/types': { + get: { + req: TypesData; + res: { + /** + * 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: { + [key: string]: unknown; + }; + }; + }; + }; + '/api/v{api-version}/upload': { + post: { + req: UploadFileData; + res: { + 200: boolean; + }; + }; + }; + '/api/v{api-version}/file/{id}': { + get: { + req: FileResponseData; + res: { + /** + * Success + */ + 200: (Blob | File); + }; + }; + }; + '/api/v{api-version}/complex': { + get: { + req: ComplexTypesData; + res: { + /** + * Successful response + */ + 200: Array; + /** + * 400 `server` error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; + }; + }; + }; + '/api/v{api-version}/multipart': { + post: { + req: MultipartRequestData; + }; + get: { + res: { + /** + * OK + */ + 200: { + file?: (Blob | File); + metadata?: { + foo?: string; + bar?: string; + }; + }; + }; + }; + }; + '/api/v{api-version}/complex/{id}': { + put: { + req: ComplexParamsData; + res: { + /** + * Success + */ + 200: ModelWithString; + }; + }; + }; + '/api/v{api-version}/header': { + post: { + res: { + /** + * Successful response + */ + 200: string; + /** + * 400 server error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; + }; + }; + }; + '/api/v{api-version}/error': { + post: { + req: TestErrorCodeData; + res: { + /** + * Custom message: Successful response + */ + 200: unknown; + /** + * 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; + }; + }; + }; + '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串': { + post: { + req: NonAsciiæøåÆøÅöôêÊ字符串Data; + res: { + /** + * Successful response + */ + 200: Array; + }; + }; + }; +}; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_models/index.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_types/index.ts.snap similarity index 100% rename from packages/openapi-ts/test/__snapshots__/test/generated/v3_models/index.ts.snap rename to packages/openapi-ts/test/__snapshots__/test/generated/v3_types/index.ts.snap diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_types/types.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_types/types.gen.ts.snap new file mode 100644 index 000000000..38fb354cb --- /dev/null +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_types/types.gen.ts.snap @@ -0,0 +1,1645 @@ +// This file is auto-generated by @hey-api/openapi-ts + +/** + * 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<(number)>; + +/** + * This is a simple array with booleans + */ +export type ArrayWithBooleans = Array<(boolean)>; + +/** + * This is a simple array with strings + */ +export type ArrayWithStrings = Array<(string)>; + +/** + * 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 simple enum with strings + */ +export type 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?: boolean; +}; + +/** + * These are the HTTP error code enums + */ +export type statusCode = '100' | '200 FOO' | '300 FOO_BAR' | '400 foo-bar' | '500 foo.bar' | '600 foo&bar'; + +/** + * This is a model with one enum with escaped name + */ +export type ModelWithEnumWithHyphen = { + 'foo-bar-baz-qux'?: '3.0'; +}; + +export type 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<(number)>; + /** + * 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<((Blob | File))>; + propWithNumber?: Array<(number)>; +}; + +/** + * This is a model with one property containing an array + */ +export type ModelWithArray = { + prop?: Array; + propWithFile?: Array<((Blob | File))>; + propWithNumber?: Array<(number)>; +}; + +/** + * 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: 'circle'; + radius?: number; +}; + +/** + * Square + */ +export type ModelSquare = { + kind: 'square'; + sideLength?: number; +}; + +/** + * This is a model with one property with a 'one of' relationship where the options are not $ref + */ +export type CompositionWithOneOfDiscriminator = ModelCircle | 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<(ModelWithDictionary | null)> | Array<(ModelWithArray | null)>; +}; + +export type e_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<(e_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<(boolean)>; +}; +}; + +/** + * This is a model that contains a dictionary of complex arrays (composited) within composition + */ +export type CompositionWithOneOfAndComplexArrayDictionary = { + propA?: boolean | { + [key: string]: Array<(number | string)>; +}; +}; + +/** + * 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 & { + firstName: string; + lastname: string; + age: number; +}; + +/** + * 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<(string)>; +}; + +/** + * This is a free-form object without additionalProperties. + */ +export type FreeFormObjectWithoutAdditionalProperties = { + [key: string]: unknown; +}; + +/** + * 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 = { + [key: string]: unknown; +}; + +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; +}; + +export type NestedAnyOfArraysNullable = { + nullableArray?: Array<(string | boolean)> | null; +}; + +export type CompositionWithOneOfAndProperties = { + foo: ParameterSimpleParameter; + baz: number | null; + qux: number; +} | { + 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 foo = 'Bar'; + +export type ModelWithNestedArrayEnumsDataFoo = 'foo' | 'bar'; + +export type ModelWithNestedArrayEnumsDataBar = 'baz' | 'qux'; + +export type ModelWithNestedArrayEnumsData = { + foo?: Array; + bar?: Array; +}; + +export type ModelWithNestedArrayEnums = { + array_strings?: Array<(string)>; + 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 | string, + number | string +]; + +export type ModelWithAnyOfConstantSizeArrayAndIntersect = [ + number & string, + number & string +]; + +export type ModelWithNumericEnumUnion = { + /** + * Период + */ + value?: -10 | -1 | 0 | 1 | 3 | 6 | 12; +}; + +/** + * Период + */ +export type 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; +}; + +/** + * 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; + +/** + * This is a reusable parameter + */ +export type ParameterSimpleParameter = string; + +/** + * Parameter with illegal characters + */ +export type Parameterx_Foo_Bar = ModelWithString; + +export type PostServiceWithEmptyTagData = { + requestBody: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; +}; + +export type PostServiceWithEmptyTagResponse3 = ModelWithReadOnlyAndWriteOnly; + +export type ApiVversionOdataControllerCountResponse = Model_From_Zendesk; + +export type DeleteFooData3 = { + /** + * bar in method + */ + barParam: string; + /** + * foo in method + */ + fooParam: string; + /** + * Parameter with illegal characters + */ + xFooBar: ModelWithString; +}; + +export type CallWithDescriptionsData = { + /** + * Testing backticks in string: `backticks` and ```multiple backticks``` should work + */ + parameterWithBackticks?: unknown; + /** + * Testing multiline comments in string: First line + * Second line + * + * Fourth line + */ + parameterWithBreaks?: unknown; + /** + * Testing expression placeholders in string: ${expression} should work + */ + parameterWithExpressionPlaceholders?: unknown; + /** + * Testing quotes in string: 'single quote''' and "double quotes""" should work + */ + parameterWithQuotes?: unknown; + /** + * Testing reserved characters in string: * inline * and ** inline ** should work + */ + parameterWithReservedCharacters?: unknown; + /** + * Testing slashes in string: \backwards\\\ and /forwards/// should work + */ + parameterWithSlashes?: unknown; +}; + +export type DeprecatedCallData = { + /** + * This parameter is deprecated + * @deprecated + */ + parameter: DeprecatedModel | null; +}; + +export type CallWithParametersData = { + fooAllOfEnum: ModelWithNestedArrayEnumsDataFoo; + fooRefEnum?: ModelWithNestedArrayEnumsDataFoo; + /** + * This is the parameter that goes into the cookie + */ + parameterCookie: string | null; + /** + * This is the parameter that goes into the form data + */ + parameterForm: string | null; + /** + * This is the parameter that goes into the header + */ + parameterHeader: string | null; + /** + * This is the parameter that goes into the path + */ + parameterPath: string | null; + /** + * This is the parameter that goes into the query params + */ + parameterQuery: string | null; + /** + * This is the parameter that goes into the body + */ + requestBody: ModelWithString | null; +}; + +export type CallWithWeirdParameterNamesData = { + /** + * This is the parameter with a reserved keyword + */ + _default?: string; + /** + * This is the parameter that goes into the cookie + */ + parameterCookie: string | null; + /** + * This is the parameter that goes into the request form data + */ + parameterForm: string | null; + /** + * This is the parameter that goes into the request header + */ + parameterHeader: string | null; + /** + * This is the parameter that goes into the path + */ + parameterPath1?: string; + /** + * This is the parameter that goes into the path + */ + parameterPath2?: string; + /** + * This is the parameter that goes into the path + */ + parameterPath3?: string; + /** + * This is the parameter that goes into the request query params + */ + parameterQuery: string | null; + /** + * This is the parameter that goes into the body + */ + requestBody: ModelWithString | null; +}; + +export type GetCallWithOptionalParamData = { + /** + * This is an optional parameter + */ + parameter?: string; + /** + * This is a required parameter + */ + requestBody: ModelWithOneOfEnum; +}; + +export type PostCallWithOptionalParamData = { + /** + * This is a required parameter + */ + parameter: Pageable; + /** + * This is an optional parameter + */ + requestBody?: ModelWithString; +}; + +export type PostApiRequestBodyData = { + /** + * A reusable request body + */ + foo?: ModelWithString; + /** + * This is a reusable parameter + */ + parameter?: string; +}; + +export type PostApiFormDataData = { + /** + * A reusable request body + */ + formData?: ModelWithString; + /** + * This is a reusable parameter + */ + parameter?: string; +}; + +export type CallWithDefaultParametersData = { + /** + * 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; + /** + * This is a simple number with default value + */ + parameterNumber?: number | null; + /** + * This is a simple string with default value + */ + parameterString?: string | null; +}; + +export type CallWithDefaultOptionalParametersData = { + /** + * 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; + /** + * This is a simple number that is optional with default value + */ + parameterNumber?: number; + /** + * This is a simple string that is optional with default value + */ + parameterString?: string; +}; + +export type CallToTestOrderOfParamsData = { + /** + * 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 that can be null with default + */ + parameterStringNullableWithDefault?: string | null; + /** + * This is a string that can be null with no default + */ + parameterStringNullableWithNoDefault?: string | null; + /** + * 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; +}; + +export type CallWithNoContentResponseResponse = void; + +export type CallWithResponseAndNoContentResponseResponse = number | void; + +export type DummyAResponse = void; + +export type DummyBResponse = void; + +export type CallWithResponseResponse = ModelWithString; + +export type CallWithDuplicateResponsesResponse = ModelWithBoolean & ModelWithInteger | ModelWithString; + +export type CallWithResponsesResponse = { + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; + readonly value?: Array; +} | ModelThatExtends | ModelThatExtendsExtends; + +export type CollectionFormatData = { + /** + * This is an array parameter that is sent as csv format (comma-separated values) + */ + parameterArrayCsv: Array<(string)> | null; + /** + * This is an array parameter that is sent as multi format (multiple parameter instances) + */ + parameterArrayMulti: Array<(string)> | null; + /** + * This is an array parameter that is sent as pipes format (pipe-separated values) + */ + parameterArrayPipes: Array<(string)> | null; + /** + * This is an array parameter that is sent as ssv format (space-separated values) + */ + parameterArraySsv: Array<(string)> | null; + /** + * This is an array parameter that is sent as tsv format (tab-separated values) + */ + parameterArrayTsv: Array<(string)> | null; +}; + +export type TypesData = { + /** + * This is a number parameter + */ + id?: number; + /** + * This is an array parameter + */ + parameterArray: Array<(string)> | null; + /** + * This is a boolean parameter + */ + parameterBoolean: boolean | null; + /** + * This is a dictionary parameter + */ + parameterDictionary: { + [key: string]: unknown; + } | null; + /** + * This is an enum parameter + */ + parameterEnum: 'Success' | 'Warning' | 'Error' | null; + /** + * This is a number parameter + */ + parameterNumber: number; + /** + * This is an object parameter + */ + parameterObject: { + [key: string]: unknown; + } | null; + /** + * This is a string parameter + */ + parameterString: string | null; +}; + +export type TypesResponse = number | string | boolean | { + [key: string]: unknown; +}; + +export type UploadFileData = { + /** + * Supply a file reference for upload + */ + file: (Blob | File); +}; + +export type UploadFileResponse = boolean; + +export type FileResponseData = { + id: string; +}; + +export type FileResponseResponse = (Blob | File); + +export type ComplexTypesData = { + /** + * Parameter containing object + */ + parameterObject: { + first?: { + second?: { + third?: string; + }; + }; + }; + /** + * Parameter containing reference + */ + parameterReference: ModelWithString; +}; + +export type ComplexTypesResponse = Array; + +export type MultipartRequestData = { + formData?: { + content?: (Blob | File); + data?: ModelWithString | null; + }; +}; + +export type MultipartResponseResponse = { + file?: (Blob | File); + metadata?: { + foo?: string; + bar?: string; + }; +}; + +export type ComplexParamsData = { + id: number; + requestBody?: { + readonly key: string | null; + name: string | null; + enabled?: boolean; + readonly type: 'Monkey' | 'Horse' | 'Bird'; + listOfModels?: Array | null; + listOfStrings?: Array<(string)> | null; + parameters: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; + readonly user?: { + readonly id?: number; + readonly name?: string | null; + }; + }; +}; + +export type ComplexParamsResponse = ModelWithString; + +export type CallWithResultFromHeaderResponse = string; + +export type TestErrorCodeData = { + /** + * Status code to return + */ + status: number; +}; + +export type TestErrorCodeResponse = unknown; + +export type NonAsciiæøåÆøÅöôêÊ字符串Data = { + /** + * Dummy input param + */ + nonAsciiParamæøåÆøÅöôêÊ: number; +}; + +export type NonAsciiæøåÆøÅöôêÊ字符串Response = Array; + +export type $OpenApiTs = { + '/api/v{api-version}/no-tag': { + post: { + req: PostServiceWithEmptyTagData; + res: { + default: ModelWithReadOnlyAndWriteOnly; + }; + }; + }; + '/api/v{api-version}/simple/$count': { + get: { + res: { + /** + * Success + */ + 200: Model_From_Zendesk; + }; + }; + }; + '/api/v{api-version}/foo/{foo_param}/bar/{BarParam}': { + delete: { + req: DeleteFooData3; + }; + }; + '/api/v{api-version}/descriptions/': { + post: { + req: CallWithDescriptionsData; + }; + }; + '/api/v{api-version}/parameters/deprecated': { + post: { + req: DeprecatedCallData; + }; + }; + '/api/v{api-version}/parameters/{parameterPath}': { + post: { + req: CallWithParametersData; + }; + }; + '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}': { + post: { + req: CallWithWeirdParameterNamesData; + }; + }; + '/api/v{api-version}/parameters/': { + get: { + req: GetCallWithOptionalParamData; + }; + post: { + req: PostCallWithOptionalParamData; + }; + }; + '/api/v{api-version}/requestBody/': { + post: { + req: PostApiRequestBodyData; + }; + }; + '/api/v{api-version}/formData/': { + post: { + req: PostApiFormDataData; + }; + }; + '/api/v{api-version}/defaults': { + get: { + req: CallWithDefaultParametersData; + }; + post: { + req: CallWithDefaultOptionalParametersData; + }; + put: { + req: CallToTestOrderOfParamsData; + }; + }; + '/api/v{api-version}/no-content': { + get: { + res: { + /** + * Success + */ + 204: void; + }; + }; + }; + '/api/v{api-version}/multiple-tags/response-and-no-content': { + get: { + res: { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; + }; + }; + }; + '/api/v{api-version}/multiple-tags/a': { + get: { + res: { + /** + * Success + */ + 204: void; + }; + }; + }; + '/api/v{api-version}/multiple-tags/b': { + get: { + res: { + /** + * Success + */ + 204: void; + }; + }; + }; + '/api/v{api-version}/response': { + get: { + res: { + default: ModelWithString; + }; + }; + post: { + res: { + /** + * Message for 200 response + */ + 200: ModelWithBoolean & ModelWithInteger; + /** + * Message for 201 response + */ + 201: ModelWithString; + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for 4XX errors + */ + '4XX': DictionaryWithArray; + /** + * Message for default response + */ + default: ModelWithBoolean; + }; + }; + put: { + res: { + /** + * 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; + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for default response + */ + default: ModelWithString; + }; + }; + }; + '/api/v{api-version}/collectionFormat': { + get: { + req: CollectionFormatData; + }; + }; + '/api/v{api-version}/types': { + get: { + req: TypesData; + res: { + /** + * 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: { + [key: string]: unknown; + }; + }; + }; + }; + '/api/v{api-version}/upload': { + post: { + req: UploadFileData; + res: { + 200: boolean; + }; + }; + }; + '/api/v{api-version}/file/{id}': { + get: { + req: FileResponseData; + res: { + /** + * Success + */ + 200: (Blob | File); + }; + }; + }; + '/api/v{api-version}/complex': { + get: { + req: ComplexTypesData; + res: { + /** + * Successful response + */ + 200: Array; + /** + * 400 `server` error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; + }; + }; + }; + '/api/v{api-version}/multipart': { + post: { + req: MultipartRequestData; + }; + get: { + res: { + /** + * OK + */ + 200: { + file?: (Blob | File); + metadata?: { + foo?: string; + bar?: string; + }; + }; + }; + }; + }; + '/api/v{api-version}/complex/{id}': { + put: { + req: ComplexParamsData; + res: { + /** + * Success + */ + 200: ModelWithString; + }; + }; + }; + '/api/v{api-version}/header': { + post: { + res: { + /** + * Successful response + */ + 200: string; + /** + * 400 server error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; + }; + }; + }; + '/api/v{api-version}/error': { + post: { + req: TestErrorCodeData; + res: { + /** + * Custom message: Successful response + */ + 200: unknown; + /** + * 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; + }; + }; + }; + '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串': { + post: { + req: NonAsciiæøåÆøÅöôêÊ字符串Data; + res: { + /** + * Successful response + */ + 200: Array; + }; + }; + }; +}; \ No newline at end of file diff --git a/packages/openapi-ts/test/index.spec.ts b/packages/openapi-ts/test/index.spec.ts index 56a88e824..e4b0615a6 100644 --- a/packages/openapi-ts/test/index.spec.ts +++ b/packages/openapi-ts/test/index.spec.ts @@ -194,16 +194,6 @@ describe('OpenAPI v3', () => { description: 'generate TypeScript enums', name: 'v3_enums_typescript', }, - { - config: createConfig({ - exportCore: false, - schemas: false, - services: false, - types: {}, - }), - description: 'generate models', - name: 'v3_models', - }, { config: createConfig({ exportCore: false, @@ -264,6 +254,16 @@ describe('OpenAPI v3', () => { description: 'generate tree-shakeable services', name: 'v3_tree_shakeable', }, + { + config: createConfig({ + exportCore: false, + schemas: false, + services: false, + types: {}, + }), + description: 'generate only types', + name: 'v3_types', + }, ]; it.each(clientScenarios.concat(allScenarios))(