mirror of
https://github.com/ferdikoomen/openapi-typescript-codegen.git
synced 2025-12-08 20:16:21 +00:00
- Fixed enum generation for new composition types
This commit is contained in:
parent
834ae43cb8
commit
b3ba14aa33
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "openapi-typescript-codegen",
|
||||
"version": "0.7.0-beta-2",
|
||||
"version": "0.7.0-beta-3",
|
||||
"description": "Library that generates Typescript clients based on the OpenAPI specification.",
|
||||
"author": "Ferdi Koomen",
|
||||
"homepage": "https://github.com/ferdikoomen/openapi-typescript-codegen",
|
||||
|
||||
@ -9,6 +9,12 @@ import type { {{{this}}} } from './{{{this}}}';
|
||||
|
||||
{{#equals export 'interface'}}
|
||||
{{>exportInterface}}
|
||||
{{else equals export 'one-of'}}
|
||||
{{>exportComposition}}
|
||||
{{else equals export 'any-of'}}
|
||||
{{>exportComposition}}
|
||||
{{else equals export 'all-of'}}
|
||||
{{>exportComposition}}
|
||||
{{else equals export 'enum'}}
|
||||
{{>exportEnum}}
|
||||
{{else}}
|
||||
|
||||
28
src/templates/partials/exportComposition.hbs
Normal file
28
src/templates/partials/exportComposition.hbs
Normal file
@ -0,0 +1,28 @@
|
||||
{{#if description}}
|
||||
/**
|
||||
* {{{description}}}
|
||||
*/
|
||||
{{/if}}
|
||||
export type {{{name}}} = {{>type parent=name}};
|
||||
{{#if enums}}
|
||||
{{#unless @root.useUnionTypes}}
|
||||
|
||||
export namespace {{{name}}} {
|
||||
|
||||
{{#each enums}}
|
||||
{{#if description}}
|
||||
/**
|
||||
* {{{description}}}
|
||||
*/
|
||||
{{/if}}
|
||||
export enum {{{name}}} {
|
||||
{{#each enum}}
|
||||
{{{name}}} = {{{value}}},
|
||||
{{/each}}
|
||||
}
|
||||
|
||||
{{/each}}
|
||||
|
||||
}
|
||||
{{/unless}}
|
||||
{{/if}}
|
||||
@ -6,7 +6,11 @@
|
||||
* {{{description}}}
|
||||
*/
|
||||
{{/if}}
|
||||
{{#if ../parent}}
|
||||
{{>isReadOnly}}{{{name}}}{{>isRequired}}: {{>type parent=../parent}},
|
||||
{{else}}
|
||||
{{>isReadOnly}}{{{name}}}{{>isRequired}}: {{>type}},
|
||||
{{/if}}
|
||||
{{/each}}
|
||||
}{{>isNullable}}
|
||||
{{~else~}}
|
||||
|
||||
@ -1 +1,5 @@
|
||||
{{~#if parent~}}
|
||||
({{#each properties}}{{>type parent=../parent}}{{#unless @last}} & {{/unless}}{{/each}}){{>isNullable}}
|
||||
{{~else~}}
|
||||
({{#each properties}}{{>type}}{{#unless @last}} & {{/unless}}{{/each}}){{>isNullable}}
|
||||
{{~/if~}}
|
||||
|
||||
@ -1 +1,5 @@
|
||||
{{~#if parent~}}
|
||||
({{#each properties}}{{>type parent=../parent}}{{#unless @last}} | {{/unless}}{{/each}}){{>isNullable}}
|
||||
{{~else~}}
|
||||
({{#each properties}}{{>type}}{{#unless @last}} | {{/unless}}{{/each}}){{>isNullable}}
|
||||
{{~/if~}}
|
||||
|
||||
@ -39,6 +39,7 @@ import templateExportSchema from '../templates/exportSchema.hbs';
|
||||
import templateExportService from '../templates/exportService.hbs';
|
||||
import templateIndex from '../templates/index.hbs';
|
||||
import partialBase from '../templates/partials/base.hbs';
|
||||
import partialExportComposition from '../templates/partials/exportComposition.hbs';
|
||||
import partialExportEnum from '../templates/partials/exportEnum.hbs';
|
||||
import partialExportInterface from '../templates/partials/exportInterface.hbs';
|
||||
import partialExportType from '../templates/partials/exportType.hbs';
|
||||
@ -109,6 +110,7 @@ export function registerHandlebarTemplates(): Templates {
|
||||
// Partials for the generations of the models, services, etc.
|
||||
Handlebars.registerPartial('exportEnum', Handlebars.template(partialExportEnum));
|
||||
Handlebars.registerPartial('exportInterface', Handlebars.template(partialExportInterface));
|
||||
Handlebars.registerPartial('exportComposition', Handlebars.template(partialExportComposition));
|
||||
Handlebars.registerPartial('exportType', Handlebars.template(partialExportType));
|
||||
Handlebars.registerPartial('header', Handlebars.template(partialHeader));
|
||||
Handlebars.registerPartial('isNullable', Handlebars.template(partialIsNullable));
|
||||
|
||||
@ -619,7 +619,8 @@ import type { ModelWithString } from './ModelWithString';
|
||||
export type ModelThatExtends = (ModelWithString & {
|
||||
propExtendsA?: string,
|
||||
propExtendsB?: ModelWithString,
|
||||
});"
|
||||
});
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`v2 should generate: ./test/generated/v2/models/ModelThatExtendsExtends.ts 1`] = `
|
||||
@ -636,7 +637,8 @@ import type { ModelWithString } from './ModelWithString';
|
||||
export type ModelThatExtendsExtends = (ModelWithString & ModelThatExtends & {
|
||||
propExtendsC?: string,
|
||||
propExtendsD?: ModelWithString,
|
||||
});"
|
||||
});
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`v2 should generate: ./test/generated/v2/models/ModelWithArray.ts 1`] = `
|
||||
@ -2992,7 +2994,8 @@ import type { ModelWithString } from './ModelWithString';
|
||||
export type ModelThatExtends = (ModelWithString & {
|
||||
propExtendsA?: string,
|
||||
propExtendsB?: ModelWithString,
|
||||
});"
|
||||
});
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`v3 should generate: ./test/generated/v3/models/ModelThatExtendsExtends.ts 1`] = `
|
||||
@ -3009,7 +3012,8 @@ import type { ModelWithString } from './ModelWithString';
|
||||
export type ModelThatExtendsExtends = (ModelWithString & ModelThatExtends & {
|
||||
propExtendsC?: string,
|
||||
propExtendsD?: ModelWithString,
|
||||
});"
|
||||
});
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`v3 should generate: ./test/generated/v3/models/ModelWithArray.ts 1`] = `
|
||||
|
||||
@ -7,8 +7,8 @@ async function generateV2() {
|
||||
input: './test/spec/v2.json',
|
||||
output: './test/generated/v2/',
|
||||
httpClient: OpenAPI.HttpClient.FETCH,
|
||||
useOptions: true,
|
||||
useUnionTypes: true,
|
||||
useOptions: false,
|
||||
useUnionTypes: false,
|
||||
exportCore: true,
|
||||
exportSchemas: true,
|
||||
exportModels: true,
|
||||
@ -21,8 +21,8 @@ async function generateV3() {
|
||||
input: './test/spec/v3.json',
|
||||
output: './test/generated/v3/',
|
||||
httpClient: OpenAPI.HttpClient.FETCH,
|
||||
useOptions: true,
|
||||
useUnionTypes: true,
|
||||
useOptions: false,
|
||||
useUnionTypes: false,
|
||||
exportCore: true,
|
||||
exportSchemas: true,
|
||||
exportModels: true,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user