Escape reserved keywords in schema names for v2, closes #1186

This commit is contained in:
Mauro Bieg 2022-08-10 11:12:18 +02:00
parent 05db3b97f8
commit 5d140cb860
3 changed files with 38 additions and 1 deletions

View File

@ -1,4 +1,5 @@
import type { Model } from '../../../client/interfaces/Model';
import { reservedWords } from '../../v3/parser/getOperationParameterName';
import type { OpenApi } from '../interfaces/OpenApi';
import { getModel } from './getModel';
import { getType } from './getType';
@ -9,7 +10,7 @@ export const getModels = (openApi: OpenApi): Model[] => {
if (openApi.definitions.hasOwnProperty(definitionName)) {
const definition = openApi.definitions[definitionName];
const definitionType = getType(definitionName);
const model = getModel(openApi, definition, true, definitionType.base);
const model = getModel(openApi, definition, true, definitionType.base.replace(reservedWords, '_$1'));
models.push(model);
}
}

View File

@ -548,6 +548,7 @@ export { CancelablePromise, CancelError } from './core/CancelablePromise';
export { OpenAPI } from './core/OpenAPI';
export type { OpenAPIConfig } from './core/OpenAPI';
export type { _default } from './models/_default';
export type { ArrayWithArray } from './models/ArrayWithArray';
export type { ArrayWithBooleans } from './models/ArrayWithBooleans';
export type { ArrayWithNumbers } from './models/ArrayWithNumbers';
@ -596,6 +597,7 @@ export type { SimpleReference } from './models/SimpleReference';
export type { SimpleString } from './models/SimpleString';
export type { SimpleStringWithPattern } from './models/SimpleStringWithPattern';
export { $_default } from './schemas/$_default';
export { $ArrayWithArray } from './schemas/$ArrayWithArray';
export { $ArrayWithBooleans } from './schemas/$ArrayWithBooleans';
export { $ArrayWithNumbers } from './schemas/$ArrayWithNumbers';
@ -663,6 +665,18 @@ export { TypesService } from './services/TypesService';
"
`;
exports[`v2 should generate: ./test/generated/v2/models/_default.ts 1`] = `
"/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
export type _default = {
name?: string;
};
"
`;
exports[`v2 should generate: ./test/generated/v2/models/ArrayWithArray.ts 1`] = `
"/* istanbul ignore file */
/* tslint:disable */
@ -1439,6 +1453,20 @@ export type SimpleStringWithPattern = string;
"
`;
exports[`v2 should generate: ./test/generated/v2/schemas/$_default.ts 1`] = `
"/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
export const $_default = {
properties: {
name: {
type: 'string',
},
},
} as const;
"
`;
exports[`v2 should generate: ./test/generated/v2/schemas/$ArrayWithArray.ts 1`] = `
"/* istanbul ignore file */
/* tslint:disable */

View File

@ -1466,6 +1466,14 @@
}
]
},
"default": {
"type": "object",
"properties": {
"name": {
"type": "string"
}
}
},
"ModelWithPattern": {
"description": "This is a model that contains a some patterns",
"type": "object",