mirror of
https://github.com/ferdikoomen/openapi-typescript-codegen.git
synced 2025-12-08 20:16:21 +00:00
- Added types for some methods
- Fixed build after PR's - Exported Cancelation Error
This commit is contained in:
parent
c39e82fff5
commit
0eb5e91ce4
@ -32,13 +32,13 @@ const handlebarsPlugin = () => ({
|
||||
preventIndent: true,
|
||||
knownHelpersOnly: true,
|
||||
knownHelpers: {
|
||||
escapeSinglequotes: true,
|
||||
equals: true,
|
||||
notEquals: true,
|
||||
containsSpaces: true,
|
||||
union: true,
|
||||
intersection: true,
|
||||
enumerator: true,
|
||||
escapeQuotes: true,
|
||||
},
|
||||
});
|
||||
return `export default ${templateSpec};`;
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import camelCase from 'camelcase';
|
||||
|
||||
const reservedWords = /^(arguments|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|eval|export|extends|false|finally|for|function|if|implements|import|in|instanceof|interface|let|new|null|package|private|protected|public|return|static|super|switch|this|throw|true|try|typeof|var|void|while|with|yield)$/g;
|
||||
const reservedWords =
|
||||
/^(arguments|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|eval|export|extends|false|finally|for|function|if|implements|import|in|instanceof|interface|let|new|null|package|private|protected|public|return|static|super|switch|this|throw|true|try|typeof|var|void|while|with|yield)$/g;
|
||||
|
||||
/**
|
||||
* Replaces any invalid characters from a parameter name.
|
||||
|
||||
@ -23,7 +23,19 @@ export function getModelProperties(
|
||||
if (definition.properties.hasOwnProperty(propertyName)) {
|
||||
const property = definition.properties[propertyName];
|
||||
const propertyRequired = !!definition.required?.includes(propertyName);
|
||||
const propertyValues = {
|
||||
const propertyValues: Omit<
|
||||
Model,
|
||||
| 'export'
|
||||
| 'type'
|
||||
| 'base'
|
||||
| 'template'
|
||||
| 'link'
|
||||
| 'isNullable'
|
||||
| 'imports'
|
||||
| 'enum'
|
||||
| 'enums'
|
||||
| 'properties'
|
||||
> = {
|
||||
name: escapeName(propertyName),
|
||||
description: getComment(property.description),
|
||||
isDefinition: false,
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import camelCase from 'camelcase';
|
||||
|
||||
const reservedWords = /^(arguments|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|eval|export|extends|false|finally|for|function|if|implements|import|in|instanceof|interface|let|new|null|package|private|protected|public|return|static|super|switch|this|throw|true|try|typeof|var|void|while|with|yield)$/g;
|
||||
const reservedWords =
|
||||
/^(arguments|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|eval|export|extends|false|finally|for|function|if|implements|import|in|instanceof|interface|let|new|null|package|private|protected|public|return|static|super|switch|this|throw|true|try|typeof|var|void|while|with|yield)$/g;
|
||||
|
||||
/**
|
||||
* Replaces any invalid characters from a parameter name.
|
||||
|
||||
@ -24,6 +24,9 @@ import { OpenAPI } from './OpenAPI';
|
||||
{{>functions/isBlob}}
|
||||
|
||||
|
||||
{{>functions/isFormData}}
|
||||
|
||||
|
||||
{{>functions/base64}}
|
||||
|
||||
|
||||
|
||||
@ -19,6 +19,9 @@ import { OpenAPI } from './OpenAPI';
|
||||
{{>functions/isBlob}}
|
||||
|
||||
|
||||
{{>functions/isFormData}}
|
||||
|
||||
|
||||
{{>functions/isSuccess}}
|
||||
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
{{#if @root.exportCore}}
|
||||
|
||||
export { ApiError } from './core/ApiError';
|
||||
export { CancelablePromise } from './core/CancelablePromise';
|
||||
export { CancelablePromise, CancelError } from './core/CancelablePromise';
|
||||
export { OpenAPI } from './core/OpenAPI';
|
||||
{{/if}}
|
||||
{{#if @root.exportModels}}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
{
|
||||
type: '{{export}}',
|
||||
{{#if description}}
|
||||
description: '{{{escapeSinglequotes description}}}',
|
||||
description: '{{{escapeQuotes description}}}',
|
||||
{{/if}}
|
||||
contains: [{{#each properties}}{{>schema}}{{#unless @last}}, {{/unless}}{{/each}}],
|
||||
{{#if isReadOnly}}
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
type: '{{{type}}}',
|
||||
{{/if}}
|
||||
{{#if description}}
|
||||
description: '{{{escapeSinglequotes description}}}',
|
||||
description: '{{{escapeQuotes description}}}',
|
||||
{{/if}}
|
||||
{{#if isReadOnly}}
|
||||
isReadOnly: {{{isReadOnly}}},
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
{{#if description}}
|
||||
description: '{{{escapeSinglequotes description}}}',
|
||||
description: '{{{escapeQuotes description}}}',
|
||||
{{/if}}
|
||||
properties: {
|
||||
{{#if properties}}
|
||||
|
||||
@ -1,16 +1,16 @@
|
||||
import { Model } from '../client/interfaces/Model';
|
||||
import { OpenApi } from '../openApi/v3/interfaces/OpenApi';
|
||||
import { OpenApiDiscriminator } from '../openApi/v3/interfaces/OpenApiDiscriminator';
|
||||
import type { Model } from '../client/interfaces/Model';
|
||||
import type { OpenApi } from '../openApi/v3/interfaces/OpenApi';
|
||||
import type { OpenApiDiscriminator } from '../openApi/v3/interfaces/OpenApiDiscriminator';
|
||||
import { stripNamespace } from '../openApi/v3/parser/stripNamespace';
|
||||
import { Dictionary } from './types';
|
||||
import type { Dictionary } from './types';
|
||||
|
||||
const inverseDictionary = (mapObj: Dictionary<string>) => {
|
||||
function inverseDictionary(map: Dictionary<string>): Dictionary<string> {
|
||||
const m2: Dictionary<string> = {};
|
||||
for (const key in mapObj) {
|
||||
m2[mapObj[key]] = key;
|
||||
for (const key in map) {
|
||||
m2[map[key]] = key;
|
||||
}
|
||||
return m2;
|
||||
};
|
||||
}
|
||||
|
||||
export function findOneOfParentDiscriminator(openApi: OpenApi, parent?: Model): OpenApiDiscriminator | undefined {
|
||||
if (openApi.components) {
|
||||
@ -20,9 +20,7 @@ export function findOneOfParentDiscriminator(openApi: OpenApi, parent?: Model):
|
||||
if (parent && schema.oneOf?.length && schema.discriminator) {
|
||||
const isPartOf =
|
||||
schema.oneOf
|
||||
.map(definition => {
|
||||
return definition.$ref && stripNamespace(definition.$ref) == parent.name;
|
||||
})
|
||||
.map(definition => definition.$ref && stripNamespace(definition.$ref) === parent.name)
|
||||
.filter(Boolean).length > 0;
|
||||
if (isPartOf) {
|
||||
return schema.discriminator;
|
||||
@ -31,7 +29,7 @@ export function findOneOfParentDiscriminator(openApi: OpenApi, parent?: Model):
|
||||
}
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
return;
|
||||
}
|
||||
|
||||
export function mapPropertyValue(discriminator: OpenApiDiscriminator, parent: Model): string {
|
||||
|
||||
@ -16,5 +16,7 @@ describe('registerHandlebarHelpers', () => {
|
||||
expect(helpers).toContain('containsSpaces');
|
||||
expect(helpers).toContain('union');
|
||||
expect(helpers).toContain('intersection');
|
||||
expect(helpers).toContain('enumerator');
|
||||
expect(helpers).toContain('escapeQuotes');
|
||||
});
|
||||
});
|
||||
|
||||
@ -10,10 +10,6 @@ export function registerHandlebarHelpers(root: {
|
||||
useOptions: boolean;
|
||||
useUnionTypes: boolean;
|
||||
}): void {
|
||||
Handlebars.registerHelper('escapeQuotes', function (value: string): string {
|
||||
return value.replace(/(')/g, '\\$1');
|
||||
});
|
||||
|
||||
Handlebars.registerHelper(
|
||||
'equals',
|
||||
function (this: any, a: string, b: string, options: Handlebars.HelperOptions): string {
|
||||
@ -83,4 +79,8 @@ export function registerHandlebarHelpers(root: {
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
Handlebars.registerHelper('escapeQuotes', function (value: string): string {
|
||||
return value.replace(/(')/g, '\\$1');
|
||||
});
|
||||
}
|
||||
|
||||
@ -492,7 +492,7 @@ exports[`v2 should generate: ./test/generated/v2/index.ts 1`] = `
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
export { ApiError } from './core/ApiError';
|
||||
export { CancelablePromise } from './core/CancelablePromise';
|
||||
export { CancelablePromise, CancelError } from './core/CancelablePromise';
|
||||
export { OpenAPI } from './core/OpenAPI';
|
||||
|
||||
export type { ArrayWithArray } from './models/ArrayWithArray';
|
||||
@ -3196,7 +3196,7 @@ exports[`v3 should generate: ./test/generated/v3/index.ts 1`] = `
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
export { ApiError } from './core/ApiError';
|
||||
export { CancelablePromise } from './core/CancelablePromise';
|
||||
export { CancelablePromise, CancelError } from './core/CancelablePromise';
|
||||
export { OpenAPI } from './core/OpenAPI';
|
||||
|
||||
export type { ArrayWithArray } from './models/ArrayWithArray';
|
||||
@ -3224,6 +3224,7 @@ export type { EnumFromDescription } from './models/EnumFromDescription';
|
||||
export { EnumWithExtensions } from './models/EnumWithExtensions';
|
||||
export { EnumWithNumbers } from './models/EnumWithNumbers';
|
||||
export { EnumWithStrings } from './models/EnumWithStrings';
|
||||
export type { File } from './models/File';
|
||||
export type { ModelCircle } from './models/ModelCircle';
|
||||
export type { ModelSquare } from './models/ModelSquare';
|
||||
export type { ModelThatExtends } from './models/ModelThatExtends';
|
||||
@ -3278,6 +3279,7 @@ export { $EnumFromDescription } from './schemas/$EnumFromDescription';
|
||||
export { $EnumWithExtensions } from './schemas/$EnumWithExtensions';
|
||||
export { $EnumWithNumbers } from './schemas/$EnumWithNumbers';
|
||||
export { $EnumWithStrings } from './schemas/$EnumWithStrings';
|
||||
export { $File } from './schemas/$File';
|
||||
export { $ModelCircle } from './schemas/$ModelCircle';
|
||||
export { $ModelSquare } from './schemas/$ModelSquare';
|
||||
export { $ModelThatExtends } from './schemas/$ModelThatExtends';
|
||||
@ -3718,6 +3720,21 @@ export enum EnumWithStrings {
|
||||
}"
|
||||
`;
|
||||
|
||||
exports[`v3 should generate: ./test/generated/v3/models/File.ts 1`] = `
|
||||
"/* istanbul ignore file */
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
|
||||
export type File = {
|
||||
readonly id?: string;
|
||||
readonly updated_at?: string;
|
||||
readonly created_at?: string;
|
||||
mime: string;
|
||||
readonly file?: string;
|
||||
}
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`v3 should generate: ./test/generated/v3/models/ModelCircle.ts 1`] = `
|
||||
"/* istanbul ignore file */
|
||||
/* tslint:disable */
|
||||
@ -4539,6 +4556,7 @@ exports[`v3 should generate: ./test/generated/v3/schemas/$CompositionWithOneOfDi
|
||||
/* eslint-disable */
|
||||
export const $CompositionWithOneOfDiscriminator = {
|
||||
type: 'one-of',
|
||||
description: 'This is a model with one property with a \\\\'one of\\\\' relationship where the options are not $ref',
|
||||
contains: [{
|
||||
type: 'ModelCircle',
|
||||
}, {
|
||||
@ -4657,11 +4675,48 @@ export const $EnumWithStrings = {
|
||||
} as const;"
|
||||
`;
|
||||
|
||||
exports[`v3 should generate: ./test/generated/v3/schemas/$File.ts 1`] = `
|
||||
"/* istanbul ignore file */
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
export const $File = {
|
||||
properties: {
|
||||
id: {
|
||||
type: 'string',
|
||||
isReadOnly: true,
|
||||
minLength: 1,
|
||||
},
|
||||
updated_at: {
|
||||
type: 'string',
|
||||
isReadOnly: true,
|
||||
format: 'date-time',
|
||||
},
|
||||
created_at: {
|
||||
type: 'string',
|
||||
isReadOnly: true,
|
||||
format: 'date-time',
|
||||
},
|
||||
mime: {
|
||||
type: 'string',
|
||||
isRequired: true,
|
||||
maxLength: 24,
|
||||
minLength: 1,
|
||||
},
|
||||
file: {
|
||||
type: 'string',
|
||||
isReadOnly: true,
|
||||
format: 'uri',
|
||||
},
|
||||
},
|
||||
} as const;"
|
||||
`;
|
||||
|
||||
exports[`v3 should generate: ./test/generated/v3/schemas/$ModelCircle.ts 1`] = `
|
||||
"/* istanbul ignore file */
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
export const $ModelCircle = {
|
||||
description: 'Circle',
|
||||
properties: {
|
||||
kind: {
|
||||
type: 'string',
|
||||
@ -4679,6 +4734,7 @@ exports[`v3 should generate: ./test/generated/v3/schemas/$ModelSquare.ts 1`] = `
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
export const $ModelSquare = {
|
||||
description: 'Square',
|
||||
properties: {
|
||||
kind: {
|
||||
type: 'string',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user