fork of hey-api/openapi-ts because I need some additional things
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #402 from hey-api/fix/0-39-2

feat: allow choosing naming preference for types

authored by

Lubos and committed by
GitHub
7ad33e17 dad799de

+280 -1341
+6
.changeset/fast-insects-promise.md
··· 1 + --- 2 + "@hey-api/openapi-ts": minor 3 + "openapi-ts-docs": minor 4 + --- 5 + 6 + feat: allow choosing naming convention for types
+5
.changeset/gorgeous-cars-sort.md
··· 1 + --- 2 + "@hey-api/openapi-ts": patch 3 + --- 4 + 5 + fix: rename exportModels to types
+22 -4
docs/openapi-ts/migrating.md
··· 54 54 55 55 ## v0.40.0 56 56 57 - ### Exported `enums.gen.ts` file 58 - 59 - Enums are now re-exported from the main `index.ts` file. This enables a cleaner migration to v0.39.0. 60 - 61 57 ### Renamed `models.gen.ts` file 62 58 63 59 `models.gen.ts` is now called `types.gen.ts`. If you use imports from `models.gen.ts`, you should be able to easily find and replace all instances. ··· 66 62 import type { Model } from 'client/models.gen' // [!code --] 67 63 import type { Model } from 'client/types.gen' // [!code ++] 68 64 ``` 65 + 66 + ### Renamed `exportModels` 67 + 68 + This config option is now called `types`. 69 + 70 + ### PascalCase for types 71 + 72 + You can now choose to export types using the PascalCase naming convention. 73 + 74 + ```js{5} 75 + export default { 76 + input: 'path/to/openapi.json', 77 + output: 'src/client', 78 + types: { 79 + name: 'PascalCase', 80 + }, 81 + } 82 + ``` 83 + 84 + ### Exported `enums.gen.ts` file 85 + 86 + Enums are now re-exported from the main `index.ts` file. 69 87 70 88 ## v0.39.0 71 89
+2 -2
packages/openapi-ts/bin/index.js
··· 22 22 .option('--dry-run [value]', 'Skip writing files to disk?') 23 23 .option('--enums <value>', 'Export enum definitions (javascript, typescript)') 24 24 .option('--exportCore [value]', 'Write core files to disk') 25 - .option('--exportModels [value]', 'Write models to disk') 26 25 .option('--exportServices [value]', 'Write services to disk') 27 26 .option('--format [value]', 'Process output folder with formatter?') 28 27 .option('--lint [value]', 'Process output folder with linter?') ··· 32 31 .option('--request <value>', 'Path to custom request file') 33 32 .option('--schemas [value]', 'Write schemas to disk') 34 33 .option('--serviceResponse [value]', 'Define shape of returned value from service calls') 34 + .option('--types [value]', 'Write types to disk') 35 35 .option('--useDateType [value]', 'Output Date instead of string for the format "date-time" in the models') 36 36 .option('--useOptions [value]', 'Use options instead of arguments') 37 37 .parse(process.argv) ··· 66 66 userConfig = processParams(params, [ 67 67 'dryRun', 68 68 'exportCore', 69 - 'exportModels', 70 69 'exportServices', 71 70 'format', 72 71 'lint', 73 72 'operationId', 74 73 'schemas', 74 + 'types', 75 75 'useDateType', 76 76 'useOptions', 77 77 ]);
+20 -2
packages/openapi-ts/src/index.ts
··· 77 77 } 78 78 }; 79 79 80 + const getTypes = (userConfig: UserConfig): Config['types'] => { 81 + let types: Config['types'] = { 82 + export: true, 83 + name: 'preserve', 84 + }; 85 + if (typeof userConfig.types === 'boolean') { 86 + types.export = userConfig.types; 87 + } else if (typeof userConfig.types === 'string') { 88 + types.include = userConfig.types; 89 + } else { 90 + types = { 91 + ...types, 92 + ...userConfig.types, 93 + }; 94 + } 95 + return types; 96 + }; 97 + 80 98 const initConfig = async (userConfig: UserConfig, dependencies: Dependencies) => { 81 99 const { config: userConfigFromFile } = await loadConfig<UserConfig>({ 82 100 jitiOptions: { ··· 96 114 dryRun = false, 97 115 enums = false, 98 116 exportCore = true, 99 - exportModels = true, 100 117 exportServices = true, 101 118 format = true, 102 119 input, ··· 137 154 138 155 const client = userConfig.client || inferClient(dependencies); 139 156 const output = path.resolve(process.cwd(), userConfig.output); 157 + const types = getTypes(userConfig); 140 158 141 159 return setConfig({ 142 160 base, ··· 145 163 dryRun, 146 164 enums, 147 165 exportCore, 148 - exportModels, 149 166 exportServices, 150 167 format, 151 168 input, ··· 157 174 request, 158 175 schemas, 159 176 serviceResponse, 177 + types, 160 178 useDateType, 161 179 useOptions, 162 180 });
+6 -2
packages/openapi-ts/src/openApi/common/parser/__tests__/operation.spec.ts
··· 10 10 dryRun: true, 11 11 enums: false, 12 12 exportCore: false, 13 - exportModels: false, 14 13 exportServices: false, 15 14 format: false, 16 15 input: '', ··· 20 19 postfixServices: '', 21 20 schemas: false, 22 21 serviceResponse: 'body', 22 + types: { 23 + export: false, 24 + }, 23 25 useDateType: false, 24 26 useOptions: false, 25 27 }; ··· 30 32 dryRun: true, 31 33 enums: false, 32 34 exportCore: false, 33 - exportModels: false, 34 35 exportServices: false, 35 36 format: false, 36 37 input: '', ··· 40 41 postfixServices: '', 41 42 schemas: false, 42 43 serviceResponse: 'body', 44 + types: { 45 + export: false, 46 + }, 43 47 useDateType: false, 44 48 useOptions: false, 45 49 };
+1 -1
packages/openapi-ts/src/openApi/v2/parser/__tests__/getServices.spec.ts
··· 11 11 dryRun: true, 12 12 enums: false, 13 13 exportCore: true, 14 - exportModels: true, 15 14 exportServices: true, 16 15 format: false, 17 16 input: '', ··· 21 20 postfixServices: 'Service', 22 21 schemas: true, 23 22 serviceResponse: 'body', 23 + types: {}, 24 24 useDateType: false, 25 25 useOptions: true, 26 26 });
+1 -1
packages/openapi-ts/src/openApi/v3/parser/__tests__/getServices.spec.ts
··· 11 11 dryRun: true, 12 12 enums: false, 13 13 exportCore: true, 14 - exportModels: true, 15 14 exportServices: true, 16 15 format: false, 17 16 input: '', ··· 21 20 postfixServices: 'Service', 22 21 schemas: true, 23 22 serviceResponse: 'body', 23 + types: {}, 24 24 useDateType: false, 25 25 useOptions: true, 26 26 });
+27 -7
packages/openapi-ts/src/types/config.ts
··· 29 29 */ 30 30 exportCore?: boolean; 31 31 /** 32 - * Generate models? 33 - * @default true 34 - */ 35 - exportModels?: boolean | string; 36 - /** 37 32 * Generate services? 38 33 * @default true 39 34 */ ··· 85 80 */ 86 81 serviceResponse?: 'body' | 'response'; 87 82 /** 83 + * Generate types? 84 + * @default true 85 + */ 86 + types?: 87 + | boolean 88 + | string 89 + | { 90 + /** 91 + * Generate types? 92 + * @default true 93 + */ 94 + export?: boolean; 95 + /** 96 + * Include only types matching regular expression 97 + */ 98 + include?: string; 99 + /** 100 + * Use your preferred naming pattern 101 + * @default 'preserve' 102 + */ 103 + name?: 'PascalCase' | 'preserve'; 104 + }; 105 + /** 88 106 * Output Date instead of string for the format "date-time" in the models 89 107 * @default false 90 108 */ ··· 96 114 useOptions?: boolean; 97 115 } 98 116 99 - export type Config = Omit<Required<UserConfig>, 'base' | 'name' | 'request'> & 100 - Pick<UserConfig, 'base' | 'name' | 'request'>; 117 + export type Config = Omit<Required<UserConfig>, 'base' | 'name' | 'request' | 'types'> & 118 + Pick<UserConfig, 'base' | 'name' | 'request'> & { 119 + types: Extract<Required<UserConfig>['types'], object>; 120 + };
+2 -2
packages/openapi-ts/src/utils/__tests__/handlebars.spec.ts
··· 12 12 dryRun: false, 13 13 enums: 'javascript', 14 14 exportCore: true, 15 - exportModels: true, 16 15 exportServices: true, 17 16 format: true, 18 17 input: '', ··· 22 21 postfixServices: '', 23 22 schemas: true, 24 23 serviceResponse: 'body', 24 + types: {}, 25 25 useDateType: false, 26 26 useOptions: false, 27 27 }); ··· 42 42 dryRun: false, 43 43 enums: 'javascript', 44 44 exportCore: true, 45 - exportModels: true, 46 45 exportServices: true, 47 46 format: true, 48 47 input: '', ··· 52 51 postfixServices: '', 53 52 schemas: true, 54 53 serviceResponse: 'body', 54 + types: {}, 55 55 useDateType: false, 56 56 useOptions: false, 57 57 });
+1 -1
packages/openapi-ts/src/utils/write/__tests__/class.spec.ts
··· 17 17 dryRun: false, 18 18 enums: 'javascript', 19 19 exportCore: true, 20 - exportModels: true, 21 20 exportServices: true, 22 21 format: false, 23 22 input: '', ··· 28 27 postfixServices: '', 29 28 schemas: true, 30 29 serviceResponse: 'body', 30 + types: {}, 31 31 useDateType: false, 32 32 useOptions: true, 33 33 });
+1 -1
packages/openapi-ts/src/utils/write/__tests__/client.spec.ts
··· 17 17 dryRun: false, 18 18 enums: 'javascript', 19 19 exportCore: true, 20 - exportModels: true, 21 20 exportServices: true, 22 21 format: true, 23 22 input: '', ··· 27 26 postfixServices: 'Service', 28 27 schemas: true, 29 28 serviceResponse: 'body', 29 + types: {}, 30 30 useDateType: false, 31 31 useOptions: false, 32 32 });
+3 -3
packages/openapi-ts/src/utils/write/__tests__/core.spec.ts
··· 31 31 dryRun: false, 32 32 enums: 'javascript', 33 33 exportCore: true, 34 - exportModels: true, 35 34 exportServices: true, 36 35 format: false, 37 36 input: '', ··· 42 41 postfixServices: '', 43 42 schemas: true, 44 43 serviceResponse: 'body', 44 + types: {}, 45 45 useDateType: false, 46 46 useOptions: true, 47 47 }); ··· 71 71 dryRun: false, 72 72 enums: 'javascript', 73 73 exportCore: true, 74 - exportModels: true, 75 74 exportServices: true, 76 75 format: false, 77 76 input: '', ··· 82 81 postfixServices: '', 83 82 schemas: true, 84 83 serviceResponse: 'body', 84 + types: {}, 85 85 useDateType: false, 86 86 useOptions: true, 87 87 }); ··· 112 112 dryRun: false, 113 113 enums: 'javascript', 114 114 exportCore: true, 115 - exportModels: true, 116 115 exportServices: true, 117 116 format: false, 118 117 input: '', ··· 123 122 postfixServices: '', 124 123 schemas: true, 125 124 serviceResponse: 'body', 125 + types: {}, 126 126 useDateType: false, 127 127 useOptions: true, 128 128 });
+1 -1
packages/openapi-ts/src/utils/write/__tests__/index.spec.ts
··· 17 17 dryRun: false, 18 18 enums: 'javascript', 19 19 exportCore: true, 20 - exportModels: true, 21 20 exportServices: true, 22 21 format: false, 23 22 input: '', ··· 27 26 postfixServices: 'Service', 28 27 schemas: true, 29 28 serviceResponse: 'body', 29 + types: {}, 30 30 useDateType: false, 31 31 useOptions: true, 32 32 });
+14 -13
packages/openapi-ts/src/utils/write/__tests__/models.spec.ts
··· 17 17 dryRun: false, 18 18 enums: 'javascript', 19 19 exportCore: true, 20 - exportModels: true, 21 20 exportServices: true, 22 21 format: false, 23 22 input: '', ··· 28 27 postfixServices: '', 29 28 schemas: true, 30 29 serviceResponse: 'body', 30 + types: {}, 31 31 useDateType: false, 32 32 useOptions: true, 33 33 }); ··· 59 59 version: 'v1', 60 60 }; 61 61 62 - const fileEnums = new TypeScriptFile({ 63 - dir: '/', 64 - name: 'enums.ts', 65 - }); 66 - const fileModels = new TypeScriptFile({ 67 - dir: '/', 68 - name: 'models.ts', 69 - }); 62 + const files = { 63 + enums: new TypeScriptFile({ 64 + dir: '/', 65 + name: 'enums.ts', 66 + }), 67 + types: new TypeScriptFile({ 68 + dir: '/', 69 + name: 'models.ts', 70 + }), 71 + }; 70 72 71 73 await processTypesAndEnums({ 72 74 client, 73 - fileEnums, 74 - fileModels, 75 + files, 75 76 }); 76 77 77 - fileEnums.write(); 78 - fileModels.write(); 78 + files.enums.write(); 79 + files.types.write(); 79 80 80 81 expect(writeFileSync).toHaveBeenCalledWith(path.resolve('/models.gen.ts'), expect.anything()); 81 82 });
+1 -1
packages/openapi-ts/src/utils/write/__tests__/schemas.spec.ts
··· 18 18 dryRun: false, 19 19 enums: 'javascript', 20 20 exportCore: true, 21 - exportModels: true, 22 21 exportServices: true, 23 22 format: false, 24 23 input: '', ··· 29 28 postfixServices: '', 30 29 schemas: true, 31 30 serviceResponse: 'body', 31 + types: {}, 32 32 useDateType: false, 33 33 useOptions: true, 34 34 });
+1 -1
packages/openapi-ts/src/utils/write/__tests__/services.spec.ts
··· 17 17 dryRun: false, 18 18 enums: false, 19 19 exportCore: true, 20 - exportModels: true, 21 20 exportServices: true, 22 21 format: false, 23 22 input: '', ··· 27 26 postfixServices: 'Service', 28 27 schemas: true, 29 28 serviceResponse: 'body', 29 + types: {}, 30 30 useDateType: false, 31 31 useOptions: false, 32 32 });
+4 -4
packages/openapi-ts/src/utils/write/client.ts
··· 27 27 client.services = client.services.filter(service => regexp.test(service.name)); 28 28 } 29 29 30 - if (typeof config.exportModels === 'string') { 31 - const regexp = new RegExp(config.exportModels); 30 + if (config.types.include) { 31 + const regexp = new RegExp(config.types.include); 32 32 client.models = client.models.filter(model => regexp.test(model.name)); 33 33 } 34 34 ··· 62 62 name: 'services.ts', 63 63 }); 64 64 } 65 - if (config.exportModels) { 65 + if (config.types.export) { 66 66 files.types = new TypeScriptFile({ 67 67 dir: config.output, 68 68 name: 'types.ts', ··· 70 70 } 71 71 72 72 await processSchemas({ file: files.schemas, openApi }); 73 - await processTypesAndEnums({ client, fileEnums: files.enums, fileModels: files.types }); 73 + await processTypesAndEnums({ client, files }); 74 74 await processServices({ client, files }); 75 75 76 76 // deprecated files
+17 -9
packages/openapi-ts/src/utils/write/models.ts
··· 1 + import camelcase from 'camelcase'; 2 + 1 3 import { type Comments, compiler, type Node, TypeScriptFile } from '../../compiler'; 2 4 import { addLeadingComment } from '../../compiler/utils'; 3 5 import type { Model, OperationParameter, Service } from '../../openApi'; ··· 91 93 } 92 94 }; 93 95 96 + const transformName = (name: string) => { 97 + const config = getConfig(); 98 + if (config.types.name === 'PascalCase') { 99 + return camelcase(name, { pascalCase: true }); 100 + } 101 + return name; 102 + }; 103 + 94 104 const processType = (client: Client, model: Model, onNode: OnNode) => { 95 105 const comment = [model.description && escapeComment(model.description), model.deprecated && '@deprecated']; 96 - const node = compiler.typedef.alias(model.name, toType(model), comment); 106 + const node = compiler.typedef.alias(transformName(model.name), toType(model), comment); 97 107 onNode(node); 98 108 }; 99 109 ··· 216 226 217 227 export const processTypesAndEnums = async ({ 218 228 client, 219 - fileEnums, 220 - fileModels, 229 + files, 221 230 }: { 222 231 client: Client; 223 - fileEnums?: TypeScriptFile; 224 - fileModels?: TypeScriptFile; 232 + files: Record<string, TypeScriptFile>; 225 233 }): Promise<void> => { 226 234 for (const model of client.models) { 227 235 processModel(client, model, (node, type) => { 228 236 if (type === 'enum') { 229 - fileEnums?.add(node); 237 + files.enums?.add(node); 230 238 } else { 231 - fileModels?.add(node); 239 + files.types?.add(node); 232 240 } 233 241 }); 234 242 } 235 243 236 - if (client.services.length) { 244 + if (files.services && client.services.length) { 237 245 processServiceTypes(client.services, node => { 238 - fileModels?.add(node); 246 + files.types?.add(node); 239 247 }); 240 248 } 241 249 };
+8
packages/openapi-ts/test/__snapshots__/test/generated/v3/schemas.gen.ts.snap
··· 1 1 // This file is auto-generated by @hey-api/openapi-ts 2 2 3 + export const $camelCaseCommentWithBreaks = { 4 + description: `Testing multiline comments in string: First line 5 + Second line 6 + 7 + Fourth line`, 8 + type: 'integer', 9 + } as const; 10 + 3 11 export const $CommentWithBreaks = { 4 12 description: `Testing multiline comments in string: First line 5 13 Second line
+8
packages/openapi-ts/test/__snapshots__/test/generated/v3/types.gen.ts.snap
··· 6 6 * 7 7 * Fourth line 8 8 */ 9 + export type camelCaseCommentWithBreaks = number; 10 + 11 + /** 12 + * Testing multiline comments in string: First line 13 + * Second line 14 + * 15 + * Fourth line 16 + */ 9 17 export type CommentWithBreaks = number; 10 18 11 19 /**
+8
packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/schemas.gen.ts.snap
··· 1 1 // This file is auto-generated by @hey-api/openapi-ts 2 2 3 + export const $camelCaseCommentWithBreaks = { 4 + description: `Testing multiline comments in string: First line 5 + Second line 6 + 7 + Fourth line`, 8 + type: 'integer', 9 + } as const; 10 + 3 11 export const $CommentWithBreaks = { 4 12 description: `Testing multiline comments in string: First line 5 13 Second line
+8
packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/types.gen.ts.snap
··· 6 6 * 7 7 * Fourth line 8 8 */ 9 + export type camelCaseCommentWithBreaks = number; 10 + 11 + /** 12 + * Testing multiline comments in string: First line 13 + * Second line 14 + * 15 + * Fourth line 16 + */ 9 17 export type CommentWithBreaks = number; 10 18 11 19 /**
+8
packages/openapi-ts/test/__snapshots__/test/generated/v3_client/types.gen.ts.snap
··· 6 6 * 7 7 * Fourth line 8 8 */ 9 + export type camelCaseCommentWithBreaks = number; 10 + 11 + /** 12 + * Testing multiline comments in string: First line 13 + * Second line 14 + * 15 + * Fourth line 16 + */ 9 17 export type CommentWithBreaks = number; 10 18 11 19 /**
+8
packages/openapi-ts/test/__snapshots__/test/generated/v3_date/schemas.gen.ts.snap
··· 1 1 // This file is auto-generated by @hey-api/openapi-ts 2 2 3 + export const $camelCaseCommentWithBreaks = { 4 + description: `Testing multiline comments in string: First line 5 + Second line 6 + 7 + Fourth line`, 8 + type: 'integer', 9 + } as const; 10 + 3 11 export const $CommentWithBreaks = { 4 12 description: `Testing multiline comments in string: First line 5 13 Second line
-602
packages/openapi-ts/test/__snapshots__/test/generated/v3_date/types.gen.ts.snap
··· 14 14 patternWithNewline?: string; 15 15 patternWithBacktick?: string; 16 16 }; 17 - 18 - export type $OpenApiTs = { 19 - '/api/v{api-version}/no-tag': { 20 - post: { 21 - req: { 22 - requestBody: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; 23 - }; 24 - res: { 25 - 200: ModelWithReadOnlyAndWriteOnly; 26 - }; 27 - }; 28 - }; 29 - '/api/v{api-version}/simple/$count': { 30 - get: { 31 - res: { 32 - /** 33 - * Success 34 - */ 35 - 200: Model_From_Zendesk; 36 - }; 37 - }; 38 - }; 39 - '/api/v{api-version}/foo/{foo}/bar/{bar}': { 40 - delete: { 41 - req: { 42 - /** 43 - * bar in method 44 - */ 45 - bar: string; 46 - /** 47 - * foo in method 48 - */ 49 - foo: string; 50 - }; 51 - }; 52 - }; 53 - '/api/v{api-version}/parameters/{parameterPath}': { 54 - post: { 55 - req: { 56 - fooAllOfEnum: ModelWithNestedArrayEnumsDataFoo; 57 - fooRefEnum?: ModelWithNestedArrayEnumsDataFoo; 58 - /** 59 - * This is the parameter that goes into the cookie 60 - */ 61 - parameterCookie: string | null; 62 - /** 63 - * This is the parameter that goes into the form data 64 - */ 65 - parameterForm: string | null; 66 - /** 67 - * This is the parameter that goes into the header 68 - */ 69 - parameterHeader: string | null; 70 - /** 71 - * This is the parameter that goes into the path 72 - */ 73 - parameterPath: string | null; 74 - /** 75 - * This is the parameter that goes into the query params 76 - */ 77 - parameterQuery: string | null; 78 - /** 79 - * This is the parameter that goes into the body 80 - */ 81 - requestBody: ModelWithString | null; 82 - }; 83 - }; 84 - }; 85 - '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}': { 86 - post: { 87 - req: { 88 - /** 89 - * This is the parameter with a reserved keyword 90 - */ 91 - _default?: string; 92 - /** 93 - * This is the parameter that goes into the cookie 94 - */ 95 - parameterCookie: string | null; 96 - /** 97 - * This is the parameter that goes into the request form data 98 - */ 99 - parameterForm: string | null; 100 - /** 101 - * This is the parameter that goes into the request header 102 - */ 103 - parameterHeader: string | null; 104 - /** 105 - * This is the parameter that goes into the path 106 - */ 107 - parameterPath1?: string; 108 - /** 109 - * This is the parameter that goes into the path 110 - */ 111 - parameterPath2?: string; 112 - /** 113 - * This is the parameter that goes into the path 114 - */ 115 - parameterPath3?: string; 116 - /** 117 - * This is the parameter that goes into the request query params 118 - */ 119 - parameterQuery: string | null; 120 - /** 121 - * This is the parameter that goes into the body 122 - */ 123 - requestBody: ModelWithString | null; 124 - }; 125 - }; 126 - }; 127 - '/api/v{api-version}/parameters/': { 128 - get: { 129 - req: { 130 - /** 131 - * This is an optional parameter 132 - */ 133 - parameter?: string; 134 - /** 135 - * This is a required parameter 136 - */ 137 - requestBody: ModelWithOneOfEnum; 138 - }; 139 - }; 140 - post: { 141 - req: { 142 - /** 143 - * This is a required parameter 144 - */ 145 - parameter: Pageable; 146 - /** 147 - * This is an optional parameter 148 - */ 149 - requestBody?: ModelWithString; 150 - }; 151 - }; 152 - }; 153 - '/api/v{api-version}/descriptions/': { 154 - post: { 155 - req: { 156 - /** 157 - * Testing backticks in string: `backticks` and ```multiple backticks``` should work 158 - */ 159 - parameterWithBackticks?: unknown; 160 - /** 161 - * Testing multiline comments in string: First line 162 - * Second line 163 - * 164 - * Fourth line 165 - */ 166 - parameterWithBreaks?: unknown; 167 - /** 168 - * Testing expression placeholders in string: ${expression} should work 169 - */ 170 - parameterWithExpressionPlaceholders?: unknown; 171 - /** 172 - * Testing quotes in string: 'single quote''' and "double quotes""" should work 173 - */ 174 - parameterWithQuotes?: unknown; 175 - /** 176 - * Testing reserved characters in string: * inline * and ** inline ** should work 177 - */ 178 - parameterWithReservedCharacters?: unknown; 179 - /** 180 - * Testing slashes in string: \backwards\\\ and /forwards/// should work 181 - */ 182 - parameterWithSlashes?: unknown; 183 - }; 184 - }; 185 - }; 186 - '/api/v{api-version}/parameters/deprecated': { 187 - post: { 188 - req: { 189 - /** 190 - * This parameter is deprecated 191 - * @deprecated 192 - */ 193 - parameter: DeprecatedModel | null; 194 - }; 195 - }; 196 - }; 197 - '/api/v{api-version}/requestBody/': { 198 - post: { 199 - req: { 200 - /** 201 - * A reusable request body 202 - */ 203 - foo?: ModelWithString; 204 - /** 205 - * This is a reusable parameter 206 - */ 207 - parameter?: string; 208 - }; 209 - }; 210 - }; 211 - '/api/v{api-version}/formData/': { 212 - post: { 213 - req: { 214 - /** 215 - * A reusable request body 216 - */ 217 - formData?: ModelWithString; 218 - /** 219 - * This is a reusable parameter 220 - */ 221 - parameter?: string; 222 - }; 223 - }; 224 - }; 225 - '/api/v{api-version}/defaults': { 226 - get: { 227 - req: { 228 - /** 229 - * This is a simple boolean with default value 230 - */ 231 - parameterBoolean?: boolean | null; 232 - /** 233 - * This is a simple enum with default value 234 - */ 235 - parameterEnum?: 'Success' | 'Warning' | 'Error'; 236 - /** 237 - * This is a simple model with default value 238 - */ 239 - parameterModel?: ModelWithString | null; 240 - /** 241 - * This is a simple number with default value 242 - */ 243 - parameterNumber?: number | null; 244 - /** 245 - * This is a simple string with default value 246 - */ 247 - parameterString?: string | null; 248 - }; 249 - }; 250 - post: { 251 - req: { 252 - /** 253 - * This is a simple boolean that is optional with default value 254 - */ 255 - parameterBoolean?: boolean; 256 - /** 257 - * This is a simple enum that is optional with default value 258 - */ 259 - parameterEnum?: 'Success' | 'Warning' | 'Error'; 260 - /** 261 - * This is a simple model that is optional with default value 262 - */ 263 - parameterModel?: ModelWithString; 264 - /** 265 - * This is a simple number that is optional with default value 266 - */ 267 - parameterNumber?: number; 268 - /** 269 - * This is a simple string that is optional with default value 270 - */ 271 - parameterString?: string; 272 - }; 273 - }; 274 - put: { 275 - req: { 276 - /** 277 - * This is a optional string with default 278 - */ 279 - parameterOptionalStringWithDefault?: string; 280 - /** 281 - * This is a optional string with empty default 282 - */ 283 - parameterOptionalStringWithEmptyDefault?: string; 284 - /** 285 - * This is a optional string with no default 286 - */ 287 - parameterOptionalStringWithNoDefault?: string; 288 - /** 289 - * This is a string that can be null with default 290 - */ 291 - parameterStringNullableWithDefault?: string | null; 292 - /** 293 - * This is a string that can be null with no default 294 - */ 295 - parameterStringNullableWithNoDefault?: string | null; 296 - /** 297 - * This is a string with default 298 - */ 299 - parameterStringWithDefault: string; 300 - /** 301 - * This is a string with empty default 302 - */ 303 - parameterStringWithEmptyDefault: string; 304 - /** 305 - * This is a string with no default 306 - */ 307 - parameterStringWithNoDefault: string; 308 - }; 309 - }; 310 - }; 311 - '/api/v{api-version}/no-content': { 312 - get: { 313 - res: { 314 - /** 315 - * Success 316 - */ 317 - 204: void; 318 - }; 319 - }; 320 - }; 321 - '/api/v{api-version}/multiple-tags/response-and-no-content': { 322 - get: { 323 - res: { 324 - /** 325 - * Response is a simple number 326 - */ 327 - 200: number; 328 - /** 329 - * Success 330 - */ 331 - 204: void; 332 - }; 333 - }; 334 - }; 335 - '/api/v{api-version}/response': { 336 - get: { 337 - res: { 338 - 200: ModelWithString; 339 - }; 340 - }; 341 - post: { 342 - res: { 343 - /** 344 - * Message for default response 345 - */ 346 - 200: ModelWithString; 347 - }; 348 - }; 349 - put: { 350 - res: { 351 - /** 352 - * Message for default response 353 - */ 354 - 200: ModelWithString; 355 - /** 356 - * Message for 201 response 357 - */ 358 - 201: ModelThatExtends; 359 - /** 360 - * Message for 202 response 361 - */ 362 - 202: ModelThatExtendsExtends; 363 - }; 364 - }; 365 - }; 366 - '/api/v{api-version}/multiple-tags/a': { 367 - get: { 368 - res: { 369 - /** 370 - * Success 371 - */ 372 - 204: void; 373 - }; 374 - }; 375 - }; 376 - '/api/v{api-version}/multiple-tags/b': { 377 - get: { 378 - res: { 379 - /** 380 - * Success 381 - */ 382 - 204: void; 383 - }; 384 - }; 385 - }; 386 - '/api/v{api-version}/collectionFormat': { 387 - get: { 388 - req: { 389 - /** 390 - * This is an array parameter that is sent as csv format (comma-separated values) 391 - */ 392 - parameterArrayCsv: Array<string> | null; 393 - /** 394 - * This is an array parameter that is sent as multi format (multiple parameter instances) 395 - */ 396 - parameterArrayMulti: Array<string> | null; 397 - /** 398 - * This is an array parameter that is sent as pipes format (pipe-separated values) 399 - */ 400 - parameterArrayPipes: Array<string> | null; 401 - /** 402 - * This is an array parameter that is sent as ssv format (space-separated values) 403 - */ 404 - parameterArraySsv: Array<string> | null; 405 - /** 406 - * This is an array parameter that is sent as tsv format (tab-separated values) 407 - */ 408 - parameterArrayTsv: Array<string> | null; 409 - }; 410 - }; 411 - }; 412 - '/api/v{api-version}/types': { 413 - get: { 414 - req: { 415 - /** 416 - * This is a number parameter 417 - */ 418 - id?: number; 419 - /** 420 - * This is an array parameter 421 - */ 422 - parameterArray: Array<string> | null; 423 - /** 424 - * This is a boolean parameter 425 - */ 426 - parameterBoolean: boolean | null; 427 - /** 428 - * This is a dictionary parameter 429 - */ 430 - parameterDictionary: { 431 - [key: string]: unknown; 432 - } | null; 433 - /** 434 - * This is an enum parameter 435 - */ 436 - parameterEnum: 'Success' | 'Warning' | 'Error' | null; 437 - /** 438 - * This is a number parameter 439 - */ 440 - parameterNumber: number; 441 - /** 442 - * This is an object parameter 443 - */ 444 - parameterObject: { 445 - [key: string]: unknown; 446 - } | null; 447 - /** 448 - * This is a string parameter 449 - */ 450 - parameterString: string | null; 451 - }; 452 - res: { 453 - /** 454 - * Response is a simple number 455 - */ 456 - 200: number; 457 - /** 458 - * Response is a simple string 459 - */ 460 - 201: string; 461 - /** 462 - * Response is a simple boolean 463 - */ 464 - 202: boolean; 465 - /** 466 - * Response is a simple object 467 - */ 468 - 203: { 469 - [key: string]: unknown; 470 - }; 471 - }; 472 - }; 473 - }; 474 - '/api/v{api-version}/upload': { 475 - post: { 476 - req: { 477 - /** 478 - * Supply a file reference for upload 479 - */ 480 - file: Blob | File; 481 - }; 482 - res: { 483 - 200: boolean; 484 - }; 485 - }; 486 - }; 487 - '/api/v{api-version}/file/{id}': { 488 - get: { 489 - req: { 490 - id: string; 491 - }; 492 - res: { 493 - /** 494 - * Success 495 - */ 496 - 200: Blob | File; 497 - }; 498 - }; 499 - }; 500 - '/api/v{api-version}/complex': { 501 - get: { 502 - req: { 503 - /** 504 - * Parameter containing object 505 - */ 506 - parameterObject: { 507 - first?: { 508 - second?: { 509 - third?: string; 510 - }; 511 - }; 512 - }; 513 - /** 514 - * Parameter containing reference 515 - */ 516 - parameterReference: ModelWithString; 517 - }; 518 - res: { 519 - /** 520 - * Successful response 521 - */ 522 - 200: Array<ModelWithString>; 523 - }; 524 - }; 525 - }; 526 - '/api/v{api-version}/complex/{id}': { 527 - put: { 528 - req: { 529 - id: number; 530 - requestBody?: { 531 - readonly key: string | null; 532 - name: string | null; 533 - enabled?: boolean; 534 - readonly type: 'Monkey' | 'Horse' | 'Bird'; 535 - listOfModels?: Array<ModelWithString> | null; 536 - listOfStrings?: Array<string> | null; 537 - parameters: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; 538 - readonly user?: { 539 - readonly id?: number; 540 - readonly name?: string | null; 541 - }; 542 - }; 543 - }; 544 - res: { 545 - /** 546 - * Success 547 - */ 548 - 200: ModelWithString; 549 - }; 550 - }; 551 - }; 552 - '/api/v{api-version}/multipart': { 553 - post: { 554 - req: { 555 - formData?: { 556 - content?: Blob | File; 557 - data?: ModelWithString | null; 558 - }; 559 - }; 560 - }; 561 - get: { 562 - res: { 563 - /** 564 - * OK 565 - */ 566 - 200: { 567 - file?: Blob | File; 568 - metadata?: { 569 - foo?: string; 570 - bar?: string; 571 - }; 572 - }; 573 - }; 574 - }; 575 - }; 576 - '/api/v{api-version}/header': { 577 - post: { 578 - res: { 579 - /** 580 - * Successful response 581 - */ 582 - 200: string; 583 - }; 584 - }; 585 - }; 586 - '/api/v{api-version}/error': { 587 - post: { 588 - req: { 589 - /** 590 - * Status code to return 591 - */ 592 - status: number; 593 - }; 594 - res: { 595 - /** 596 - * Custom message: Successful response 597 - */ 598 - 200: unknown; 599 - }; 600 - }; 601 - }; 602 - '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串': { 603 - post: { 604 - req: { 605 - /** 606 - * Dummy input param 607 - */ 608 - nonAsciiParamæøåÆøÅöôêÊ: number; 609 - }; 610 - res: { 611 - /** 612 - * Successful response 613 - */ 614 - 200: Array<NonAsciiStringæøåÆØÅöôêÊ字符串>; 615 - }; 616 - }; 617 - }; 618 - };
+8
packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/schemas.gen.ts.snap
··· 1 1 // This file is auto-generated by @hey-api/openapi-ts 2 2 3 + export const $camelCaseCommentWithBreaks = { 4 + description: `Testing multiline comments in string: First line 5 + Second line 6 + 7 + Fourth line`, 8 + type: 'integer', 9 + } as const; 10 + 3 11 export const $CommentWithBreaks = { 4 12 description: `Testing multiline comments in string: First line 5 13 Second line
+8
packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/types.gen.ts.snap
··· 6 6 * 7 7 * Fourth line 8 8 */ 9 + export type camelCaseCommentWithBreaks = number; 10 + 11 + /** 12 + * Testing multiline comments in string: First line 13 + * Second line 14 + * 15 + * Fourth line 16 + */ 9 17 export type CommentWithBreaks = number; 10 18 11 19 /**
+8 -602
packages/openapi-ts/test/__snapshots__/test/generated/v3_models/types.gen.ts.snap
··· 6 6 * 7 7 * Fourth line 8 8 */ 9 + export type camelCaseCommentWithBreaks = number; 10 + 11 + /** 12 + * Testing multiline comments in string: First line 13 + * Second line 14 + * 15 + * Fourth line 16 + */ 9 17 export type CommentWithBreaks = number; 10 18 11 19 /** ··· 787 795 * Parameter with illegal characters 788 796 */ 789 797 export type x_Foo_Bar = string; 790 - 791 - export type $OpenApiTs = { 792 - '/api/v{api-version}/no-tag': { 793 - post: { 794 - req: { 795 - requestBody: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; 796 - }; 797 - res: { 798 - 200: ModelWithReadOnlyAndWriteOnly; 799 - }; 800 - }; 801 - }; 802 - '/api/v{api-version}/simple/$count': { 803 - get: { 804 - res: { 805 - /** 806 - * Success 807 - */ 808 - 200: Model_From_Zendesk; 809 - }; 810 - }; 811 - }; 812 - '/api/v{api-version}/foo/{foo}/bar/{bar}': { 813 - delete: { 814 - req: { 815 - /** 816 - * bar in method 817 - */ 818 - bar: string; 819 - /** 820 - * foo in method 821 - */ 822 - foo: string; 823 - }; 824 - }; 825 - }; 826 - '/api/v{api-version}/parameters/{parameterPath}': { 827 - post: { 828 - req: { 829 - fooAllOfEnum: ModelWithNestedArrayEnumsDataFoo; 830 - fooRefEnum?: ModelWithNestedArrayEnumsDataFoo; 831 - /** 832 - * This is the parameter that goes into the cookie 833 - */ 834 - parameterCookie: string | null; 835 - /** 836 - * This is the parameter that goes into the form data 837 - */ 838 - parameterForm: string | null; 839 - /** 840 - * This is the parameter that goes into the header 841 - */ 842 - parameterHeader: string | null; 843 - /** 844 - * This is the parameter that goes into the path 845 - */ 846 - parameterPath: string | null; 847 - /** 848 - * This is the parameter that goes into the query params 849 - */ 850 - parameterQuery: string | null; 851 - /** 852 - * This is the parameter that goes into the body 853 - */ 854 - requestBody: ModelWithString | null; 855 - }; 856 - }; 857 - }; 858 - '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}': { 859 - post: { 860 - req: { 861 - /** 862 - * This is the parameter with a reserved keyword 863 - */ 864 - _default?: string; 865 - /** 866 - * This is the parameter that goes into the cookie 867 - */ 868 - parameterCookie: string | null; 869 - /** 870 - * This is the parameter that goes into the request form data 871 - */ 872 - parameterForm: string | null; 873 - /** 874 - * This is the parameter that goes into the request header 875 - */ 876 - parameterHeader: string | null; 877 - /** 878 - * This is the parameter that goes into the path 879 - */ 880 - parameterPath1?: string; 881 - /** 882 - * This is the parameter that goes into the path 883 - */ 884 - parameterPath2?: string; 885 - /** 886 - * This is the parameter that goes into the path 887 - */ 888 - parameterPath3?: string; 889 - /** 890 - * This is the parameter that goes into the request query params 891 - */ 892 - parameterQuery: string | null; 893 - /** 894 - * This is the parameter that goes into the body 895 - */ 896 - requestBody: ModelWithString | null; 897 - }; 898 - }; 899 - }; 900 - '/api/v{api-version}/parameters/': { 901 - get: { 902 - req: { 903 - /** 904 - * This is an optional parameter 905 - */ 906 - parameter?: string; 907 - /** 908 - * This is a required parameter 909 - */ 910 - requestBody: ModelWithOneOfEnum; 911 - }; 912 - }; 913 - post: { 914 - req: { 915 - /** 916 - * This is a required parameter 917 - */ 918 - parameter: Pageable; 919 - /** 920 - * This is an optional parameter 921 - */ 922 - requestBody?: ModelWithString; 923 - }; 924 - }; 925 - }; 926 - '/api/v{api-version}/descriptions/': { 927 - post: { 928 - req: { 929 - /** 930 - * Testing backticks in string: `backticks` and ```multiple backticks``` should work 931 - */ 932 - parameterWithBackticks?: unknown; 933 - /** 934 - * Testing multiline comments in string: First line 935 - * Second line 936 - * 937 - * Fourth line 938 - */ 939 - parameterWithBreaks?: unknown; 940 - /** 941 - * Testing expression placeholders in string: ${expression} should work 942 - */ 943 - parameterWithExpressionPlaceholders?: unknown; 944 - /** 945 - * Testing quotes in string: 'single quote''' and "double quotes""" should work 946 - */ 947 - parameterWithQuotes?: unknown; 948 - /** 949 - * Testing reserved characters in string: * inline * and ** inline ** should work 950 - */ 951 - parameterWithReservedCharacters?: unknown; 952 - /** 953 - * Testing slashes in string: \backwards\\\ and /forwards/// should work 954 - */ 955 - parameterWithSlashes?: unknown; 956 - }; 957 - }; 958 - }; 959 - '/api/v{api-version}/parameters/deprecated': { 960 - post: { 961 - req: { 962 - /** 963 - * This parameter is deprecated 964 - * @deprecated 965 - */ 966 - parameter: DeprecatedModel | null; 967 - }; 968 - }; 969 - }; 970 - '/api/v{api-version}/requestBody/': { 971 - post: { 972 - req: { 973 - /** 974 - * A reusable request body 975 - */ 976 - foo?: ModelWithString; 977 - /** 978 - * This is a reusable parameter 979 - */ 980 - parameter?: string; 981 - }; 982 - }; 983 - }; 984 - '/api/v{api-version}/formData/': { 985 - post: { 986 - req: { 987 - /** 988 - * A reusable request body 989 - */ 990 - formData?: ModelWithString; 991 - /** 992 - * This is a reusable parameter 993 - */ 994 - parameter?: string; 995 - }; 996 - }; 997 - }; 998 - '/api/v{api-version}/defaults': { 999 - get: { 1000 - req: { 1001 - /** 1002 - * This is a simple boolean with default value 1003 - */ 1004 - parameterBoolean?: boolean | null; 1005 - /** 1006 - * This is a simple enum with default value 1007 - */ 1008 - parameterEnum?: 'Success' | 'Warning' | 'Error'; 1009 - /** 1010 - * This is a simple model with default value 1011 - */ 1012 - parameterModel?: ModelWithString | null; 1013 - /** 1014 - * This is a simple number with default value 1015 - */ 1016 - parameterNumber?: number | null; 1017 - /** 1018 - * This is a simple string with default value 1019 - */ 1020 - parameterString?: string | null; 1021 - }; 1022 - }; 1023 - post: { 1024 - req: { 1025 - /** 1026 - * This is a simple boolean that is optional with default value 1027 - */ 1028 - parameterBoolean?: boolean; 1029 - /** 1030 - * This is a simple enum that is optional with default value 1031 - */ 1032 - parameterEnum?: 'Success' | 'Warning' | 'Error'; 1033 - /** 1034 - * This is a simple model that is optional with default value 1035 - */ 1036 - parameterModel?: ModelWithString; 1037 - /** 1038 - * This is a simple number that is optional with default value 1039 - */ 1040 - parameterNumber?: number; 1041 - /** 1042 - * This is a simple string that is optional with default value 1043 - */ 1044 - parameterString?: string; 1045 - }; 1046 - }; 1047 - put: { 1048 - req: { 1049 - /** 1050 - * This is a optional string with default 1051 - */ 1052 - parameterOptionalStringWithDefault?: string; 1053 - /** 1054 - * This is a optional string with empty default 1055 - */ 1056 - parameterOptionalStringWithEmptyDefault?: string; 1057 - /** 1058 - * This is a optional string with no default 1059 - */ 1060 - parameterOptionalStringWithNoDefault?: string; 1061 - /** 1062 - * This is a string that can be null with default 1063 - */ 1064 - parameterStringNullableWithDefault?: string | null; 1065 - /** 1066 - * This is a string that can be null with no default 1067 - */ 1068 - parameterStringNullableWithNoDefault?: string | null; 1069 - /** 1070 - * This is a string with default 1071 - */ 1072 - parameterStringWithDefault: string; 1073 - /** 1074 - * This is a string with empty default 1075 - */ 1076 - parameterStringWithEmptyDefault: string; 1077 - /** 1078 - * This is a string with no default 1079 - */ 1080 - parameterStringWithNoDefault: string; 1081 - }; 1082 - }; 1083 - }; 1084 - '/api/v{api-version}/no-content': { 1085 - get: { 1086 - res: { 1087 - /** 1088 - * Success 1089 - */ 1090 - 204: void; 1091 - }; 1092 - }; 1093 - }; 1094 - '/api/v{api-version}/multiple-tags/response-and-no-content': { 1095 - get: { 1096 - res: { 1097 - /** 1098 - * Response is a simple number 1099 - */ 1100 - 200: number; 1101 - /** 1102 - * Success 1103 - */ 1104 - 204: void; 1105 - }; 1106 - }; 1107 - }; 1108 - '/api/v{api-version}/response': { 1109 - get: { 1110 - res: { 1111 - 200: ModelWithString; 1112 - }; 1113 - }; 1114 - post: { 1115 - res: { 1116 - /** 1117 - * Message for default response 1118 - */ 1119 - 200: ModelWithString; 1120 - }; 1121 - }; 1122 - put: { 1123 - res: { 1124 - /** 1125 - * Message for default response 1126 - */ 1127 - 200: ModelWithString; 1128 - /** 1129 - * Message for 201 response 1130 - */ 1131 - 201: ModelThatExtends; 1132 - /** 1133 - * Message for 202 response 1134 - */ 1135 - 202: ModelThatExtendsExtends; 1136 - }; 1137 - }; 1138 - }; 1139 - '/api/v{api-version}/multiple-tags/a': { 1140 - get: { 1141 - res: { 1142 - /** 1143 - * Success 1144 - */ 1145 - 204: void; 1146 - }; 1147 - }; 1148 - }; 1149 - '/api/v{api-version}/multiple-tags/b': { 1150 - get: { 1151 - res: { 1152 - /** 1153 - * Success 1154 - */ 1155 - 204: void; 1156 - }; 1157 - }; 1158 - }; 1159 - '/api/v{api-version}/collectionFormat': { 1160 - get: { 1161 - req: { 1162 - /** 1163 - * This is an array parameter that is sent as csv format (comma-separated values) 1164 - */ 1165 - parameterArrayCsv: Array<string> | null; 1166 - /** 1167 - * This is an array parameter that is sent as multi format (multiple parameter instances) 1168 - */ 1169 - parameterArrayMulti: Array<string> | null; 1170 - /** 1171 - * This is an array parameter that is sent as pipes format (pipe-separated values) 1172 - */ 1173 - parameterArrayPipes: Array<string> | null; 1174 - /** 1175 - * This is an array parameter that is sent as ssv format (space-separated values) 1176 - */ 1177 - parameterArraySsv: Array<string> | null; 1178 - /** 1179 - * This is an array parameter that is sent as tsv format (tab-separated values) 1180 - */ 1181 - parameterArrayTsv: Array<string> | null; 1182 - }; 1183 - }; 1184 - }; 1185 - '/api/v{api-version}/types': { 1186 - get: { 1187 - req: { 1188 - /** 1189 - * This is a number parameter 1190 - */ 1191 - id?: number; 1192 - /** 1193 - * This is an array parameter 1194 - */ 1195 - parameterArray: Array<string> | null; 1196 - /** 1197 - * This is a boolean parameter 1198 - */ 1199 - parameterBoolean: boolean | null; 1200 - /** 1201 - * This is a dictionary parameter 1202 - */ 1203 - parameterDictionary: { 1204 - [key: string]: unknown; 1205 - } | null; 1206 - /** 1207 - * This is an enum parameter 1208 - */ 1209 - parameterEnum: 'Success' | 'Warning' | 'Error' | null; 1210 - /** 1211 - * This is a number parameter 1212 - */ 1213 - parameterNumber: number; 1214 - /** 1215 - * This is an object parameter 1216 - */ 1217 - parameterObject: { 1218 - [key: string]: unknown; 1219 - } | null; 1220 - /** 1221 - * This is a string parameter 1222 - */ 1223 - parameterString: string | null; 1224 - }; 1225 - res: { 1226 - /** 1227 - * Response is a simple number 1228 - */ 1229 - 200: number; 1230 - /** 1231 - * Response is a simple string 1232 - */ 1233 - 201: string; 1234 - /** 1235 - * Response is a simple boolean 1236 - */ 1237 - 202: boolean; 1238 - /** 1239 - * Response is a simple object 1240 - */ 1241 - 203: { 1242 - [key: string]: unknown; 1243 - }; 1244 - }; 1245 - }; 1246 - }; 1247 - '/api/v{api-version}/upload': { 1248 - post: { 1249 - req: { 1250 - /** 1251 - * Supply a file reference for upload 1252 - */ 1253 - file: Blob | File; 1254 - }; 1255 - res: { 1256 - 200: boolean; 1257 - }; 1258 - }; 1259 - }; 1260 - '/api/v{api-version}/file/{id}': { 1261 - get: { 1262 - req: { 1263 - id: string; 1264 - }; 1265 - res: { 1266 - /** 1267 - * Success 1268 - */ 1269 - 200: Blob | File; 1270 - }; 1271 - }; 1272 - }; 1273 - '/api/v{api-version}/complex': { 1274 - get: { 1275 - req: { 1276 - /** 1277 - * Parameter containing object 1278 - */ 1279 - parameterObject: { 1280 - first?: { 1281 - second?: { 1282 - third?: string; 1283 - }; 1284 - }; 1285 - }; 1286 - /** 1287 - * Parameter containing reference 1288 - */ 1289 - parameterReference: ModelWithString; 1290 - }; 1291 - res: { 1292 - /** 1293 - * Successful response 1294 - */ 1295 - 200: Array<ModelWithString>; 1296 - }; 1297 - }; 1298 - }; 1299 - '/api/v{api-version}/complex/{id}': { 1300 - put: { 1301 - req: { 1302 - id: number; 1303 - requestBody?: { 1304 - readonly key: string | null; 1305 - name: string | null; 1306 - enabled?: boolean; 1307 - readonly type: 'Monkey' | 'Horse' | 'Bird'; 1308 - listOfModels?: Array<ModelWithString> | null; 1309 - listOfStrings?: Array<string> | null; 1310 - parameters: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; 1311 - readonly user?: { 1312 - readonly id?: number; 1313 - readonly name?: string | null; 1314 - }; 1315 - }; 1316 - }; 1317 - res: { 1318 - /** 1319 - * Success 1320 - */ 1321 - 200: ModelWithString; 1322 - }; 1323 - }; 1324 - }; 1325 - '/api/v{api-version}/multipart': { 1326 - post: { 1327 - req: { 1328 - formData?: { 1329 - content?: Blob | File; 1330 - data?: ModelWithString | null; 1331 - }; 1332 - }; 1333 - }; 1334 - get: { 1335 - res: { 1336 - /** 1337 - * OK 1338 - */ 1339 - 200: { 1340 - file?: Blob | File; 1341 - metadata?: { 1342 - foo?: string; 1343 - bar?: string; 1344 - }; 1345 - }; 1346 - }; 1347 - }; 1348 - }; 1349 - '/api/v{api-version}/header': { 1350 - post: { 1351 - res: { 1352 - /** 1353 - * Successful response 1354 - */ 1355 - 200: string; 1356 - }; 1357 - }; 1358 - }; 1359 - '/api/v{api-version}/error': { 1360 - post: { 1361 - req: { 1362 - /** 1363 - * Status code to return 1364 - */ 1365 - status: number; 1366 - }; 1367 - res: { 1368 - /** 1369 - * Custom message: Successful response 1370 - */ 1371 - 200: unknown; 1372 - }; 1373 - }; 1374 - }; 1375 - '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串': { 1376 - post: { 1377 - req: { 1378 - /** 1379 - * Dummy input param 1380 - */ 1381 - nonAsciiParamæøåÆøÅöôêÊ: number; 1382 - }; 1383 - res: { 1384 - /** 1385 - * Successful response 1386 - */ 1387 - 200: Array<NonAsciiStringæøåÆØÅöôêÊ字符串>; 1388 - }; 1389 - }; 1390 - }; 1391 - };
+3
packages/openapi-ts/test/__snapshots__/test/generated/v3_pascalcase/index.ts.snap
··· 1 + // This file is auto-generated by @hey-api/openapi-ts 2 + 3 + export * from './types.gen';
+9
packages/openapi-ts/test/__snapshots__/test/generated/v3_pascalcase/types.gen.ts.snap
··· 1 + // This file is auto-generated by @hey-api/openapi-ts 2 + 3 + /** 4 + * Testing multiline comments in string: First line 5 + * Second line 6 + * 7 + * Fourth line 8 + */ 9 + export type CamelCaseCommentWithBreaks = number;
+8 -8
packages/openapi-ts/test/bin.spec.ts
··· 111 111 'true', 112 112 '--exportServices', 113 113 'true', 114 - '--exportModels', 114 + '--types', 115 115 'true', 116 116 '--schemas', 117 117 'true', ··· 131 131 './test/generated/bin', 132 132 '--exportServices', 133 133 '^(Simple|Types)', 134 - '--exportModels', 134 + '--types', 135 135 '^(Simple|Types)', 136 136 '--dry-run', 137 137 'true', ··· 206 206 '--debug', 207 207 '--exportCore', 208 208 'false', 209 - '--exportModels', 209 + '--types', 210 210 'false', 211 211 '--schemas', 212 212 'false', ··· 228 228 expect(result.stderr.toString()).toContain('debug: true'); 229 229 expect(result.stderr.toString()).toContain('dryRun: true'); 230 230 expect(result.stderr.toString()).toContain('exportCore: false'); 231 - expect(result.stderr.toString()).toContain('exportModels: false'); 231 + expect(result.stderr.toString()).toContain('types: false'); 232 232 expect(result.stderr.toString()).toContain('exportServices: false'); 233 233 expect(result.stderr.toString()).toContain('format: false'); 234 234 expect(result.stderr.toString()).toContain('lint: false'); ··· 248 248 '--debug', 249 249 '--exportCore', 250 250 'true', 251 - '--exportModels', 251 + '--types', 252 252 'true', 253 253 '--schemas', 254 254 'true', ··· 270 270 expect(result.stderr.toString()).toContain('debug: true'); 271 271 expect(result.stderr.toString()).toContain('dryRun: true'); 272 272 expect(result.stderr.toString()).toContain('exportCore: true'); 273 - expect(result.stderr.toString()).toContain('exportModels: true'); 273 + expect(result.stderr.toString()).toContain('types: true'); 274 274 expect(result.stderr.toString()).toContain('exportServices: true'); 275 275 expect(result.stderr.toString()).toContain('format: true'); 276 276 expect(result.stderr.toString()).toContain('lint: true'); ··· 289 289 './test/generated/bin', 290 290 '--debug', 291 291 '--exportCore', 292 - '--exportModels', 292 + '--types', 293 293 'foo', 294 294 '--schemas', 295 295 '--exportServices', ··· 311 311 expect(result.stderr.toString()).toContain('schemas: true'); 312 312 expect(result.stderr.toString()).toContain('useDateType: true'); 313 313 expect(result.stderr.toString()).toContain('useOptions: true'); 314 - expect(result.stderr.toString()).toContain("exportModels: 'foo"); 314 + expect(result.stderr.toString()).toContain("types: 'foo"); 315 315 expect(result.stderr.toString()).toContain("exportServices: 'bar'"); 316 316 }); 317 317 });
+49 -74
packages/openapi-ts/test/index.spec.ts
··· 3 3 import { sync } from 'glob'; 4 4 import { describe, expect, it } from 'vitest'; 5 5 6 - import { createClient, UserConfig } from '../'; 6 + import { createClient } from '../'; 7 + import type { UserConfig } from '../src/types/config'; 7 8 8 9 const V2_SPEC_PATH = './test/spec/v2.json'; 9 10 const V3_SPEC_PATH = './test/spec/v3.json'; ··· 20 21 client: 'fetch', 21 22 enums: 'javascript', 22 23 exportCore: true, 23 - exportModels: true, 24 24 exportServices: true, 25 25 input: '', 26 26 output: '', 27 27 schemas: true, 28 + types: true, 28 29 useOptions: true, 29 30 } as UserConfig, 30 31 description: 'generate fetch client', ··· 45 46 }); 46 47 47 48 describe('OpenAPI v3', () => { 49 + const config: UserConfig = { 50 + client: 'fetch', 51 + enums: 'javascript', 52 + exportCore: true, 53 + exportServices: true, 54 + input: '', 55 + output: '', 56 + schemas: true, 57 + types: true, 58 + useOptions: true, 59 + }; 60 + 48 61 it.each([ 49 62 { 50 63 config: { 51 - client: 'fetch', 52 - enums: 'javascript', 53 - exportCore: true, 54 - exportModels: true, 55 - exportServices: true, 56 - input: '', 57 - output: '', 58 - schemas: true, 59 - useOptions: true, 60 - } as UserConfig, 64 + ...config, 65 + }, 61 66 description: 'generate fetch client', 62 67 name: 'v3', 63 68 }, 64 69 { 65 70 config: { 71 + ...config, 66 72 client: 'angular', 67 73 enums: false, 68 - exportCore: true, 69 - exportModels: true, 70 - exportServices: true, 71 - input: '', 72 - output: '', 73 - schemas: true, 74 - useOptions: true, 75 74 } as UserConfig, 76 75 description: 'generate angular client', 77 76 name: 'v3_angular', 78 77 }, 79 78 { 80 79 config: { 80 + ...config, 81 81 client: 'node', 82 82 enums: false, 83 - exportCore: true, 84 - exportModels: false, 85 83 exportServices: false, 86 - input: '', 87 - output: '', 88 84 schemas: false, 89 - useOptions: true, 85 + types: false, 90 86 } as UserConfig, 91 87 description: 'generate node client', 92 88 name: 'v3_node', 93 89 }, 94 90 { 95 91 config: { 92 + ...config, 96 93 client: 'axios', 97 94 enums: false, 98 - exportCore: true, 99 - exportModels: false, 100 95 exportServices: false, 101 - input: '', 102 - output: '', 103 96 schemas: false, 104 - useOptions: true, 97 + types: false, 105 98 } as UserConfig, 106 99 description: 'generate axios client', 107 100 name: 'v3_axios', 108 101 }, 109 102 { 110 103 config: { 104 + ...config, 111 105 client: 'xhr', 112 106 enums: false, 113 - exportCore: true, 114 - exportModels: false, 115 107 exportServices: false, 116 - input: '', 117 - output: '', 118 108 schemas: false, 119 - useOptions: true, 109 + types: false, 120 110 } as UserConfig, 121 111 description: 'generate xhr client', 122 112 name: 'v3_xhr', 123 113 }, 124 114 { 125 115 config: { 126 - client: 'fetch', 127 - enums: 'javascript', 116 + ...config, 128 117 exportCore: false, 129 - exportModels: '^ModelWithPattern', 130 118 exportServices: false, 131 - input: '', 132 - output: '', 133 - schemas: true, 119 + types: '^ModelWithPattern', 134 120 useDateType: true, 135 - useOptions: true, 136 121 } as UserConfig, 137 122 description: 'generate Date types', 138 123 name: 'v3_date', 139 124 }, 140 125 { 141 126 config: { 142 - client: 'fetch', 143 - enums: 'javascript', 144 - exportCore: true, 145 - exportModels: '^ModelWithString', 127 + ...config, 146 128 exportServices: '^Defaults', 147 - input: '', 148 - output: '', 149 129 schemas: false, 130 + types: '^ModelWithString', 150 131 useDateType: true, 151 132 useOptions: false, 152 133 } as UserConfig, ··· 155 136 }, 156 137 { 157 138 config: { 158 - client: 'fetch', 159 - enums: 'javascript', 160 - exportCore: true, 161 - exportModels: '^ModelWithString', 139 + ...config, 162 140 exportServices: '^Defaults', 163 - input: '', 164 - output: '', 165 141 schemas: false, 142 + types: '^ModelWithString', 166 143 useDateType: true, 167 - useOptions: true, 168 144 } as UserConfig, 169 145 description: 'generate optional arguments', 170 146 name: 'v3_options', 171 147 }, 172 148 { 173 149 config: { 174 - client: 'fetch', 175 - enums: 'javascript', 176 - exportCore: true, 177 - exportModels: true, 178 - exportServices: true, 179 - input: '', 150 + ...config, 180 151 name: 'ApiClient', 181 - output: '', 182 152 schemas: false, 183 153 useDateType: true, 184 - useOptions: true, 185 154 } as UserConfig, 186 155 description: 'generate client', 187 156 name: 'v3_client', 188 157 }, 189 158 { 190 159 config: { 191 - client: 'fetch', 160 + ...config, 192 161 enums: 'typescript', 193 - exportCore: true, 194 - exportModels: true, 195 - exportServices: true, 196 - input: '', 197 - output: '', 198 - schemas: true, 199 - useOptions: true, 200 162 } as UserConfig, 201 163 description: 'generate TypeScript enums', 202 164 name: 'v3_enums_typescript', 203 165 }, 204 166 { 205 167 config: { 206 - client: 'fetch', 168 + ...config, 169 + enums: false, 207 170 exportCore: false, 208 - exportModels: true, 209 171 exportServices: false, 210 - input: '', 211 - output: '', 212 172 schemas: false, 213 173 } as UserConfig, 214 174 description: 'generate models', 215 175 name: 'v3_models', 176 + }, 177 + { 178 + config: { 179 + ...config, 180 + enums: false, 181 + exportCore: false, 182 + exportServices: false, 183 + schemas: false, 184 + types: { 185 + include: '^camelCaseCommentWithBreaks', 186 + name: 'PascalCase', 187 + }, 188 + } as UserConfig, 189 + description: 'generate pascalcase types', 190 + name: 'v3_pascalcase', 216 191 }, 217 192 ])('$description', async ({ name, config }) => { 218 193 const output = toOutputPath(name);
+4
packages/openapi-ts/test/spec/v3.json
··· 1625 1625 } 1626 1626 }, 1627 1627 "schemas": { 1628 + "camelCaseCommentWithBreaks": { 1629 + "description": "Testing multiline comments in string: First line\nSecond line\n\nFourth line", 1630 + "type": "integer" 1631 + }, 1628 1632 "CommentWithBreaks": { 1629 1633 "description": "Testing multiline comments in string: First line\nSecond line\n\nFourth line", 1630 1634 "type": "integer"