Merge pull request #1192 from mb21/keywords

Escape reserved keywords in schema names
This commit is contained in:
Ferdi Koomen 2022-10-28 10:41:33 +02:00 committed by GitHub
commit fe22880894
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 75 additions and 51 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

@ -1,6 +1,7 @@
import type { Model } from '../../../client/interfaces/Model';
import type { OpenApi } from '../interfaces/OpenApi';
import { getModel } from './getModel';
import { reservedWords } from './getOperationParameterName';
import { getType } from './getType';
export const getModels = (openApi: OpenApi): Model[] => {
@ -10,7 +11,7 @@ export const getModels = (openApi: OpenApi): Model[] => {
if (openApi.components.schemas.hasOwnProperty(definitionName)) {
const definition = openApi.components.schemas[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

@ -1,6 +1,6 @@
import camelCase from 'camelcase';
const reservedWords =
export 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;
/**

View File

@ -549,54 +549,7 @@ export { CancelablePromise, CancelError } from './core/CancelablePromise';
export { OpenAPI } from './core/OpenAPI';
export type { OpenAPIConfig } from './core/OpenAPI';
export type { ArrayWithArray as ArrayWithArrayDto } from './models/ArrayWithArray';
export type { ArrayWithBooleans as ArrayWithBooleansDto } from './models/ArrayWithBooleans';
export type { ArrayWithNumbers as ArrayWithNumbersDto } from './models/ArrayWithNumbers';
export type { ArrayWithProperties as ArrayWithPropertiesDto } from './models/ArrayWithProperties';
export type { ArrayWithReferences as ArrayWithReferencesDto } from './models/ArrayWithReferences';
export type { ArrayWithStrings as ArrayWithStringsDto } from './models/ArrayWithStrings';
export type { CommentWithBackticks as CommentWithBackticksDto } from './models/CommentWithBackticks';
export type { CommentWithBreaks as CommentWithBreaksDto } from './models/CommentWithBreaks';
export type { CommentWithExpressionPlaceholders as CommentWithExpressionPlaceholdersDto } from './models/CommentWithExpressionPlaceholders';
export type { CommentWithQuotes as CommentWithQuotesDto } from './models/CommentWithQuotes';
export type { CommentWithReservedCharacters as CommentWithReservedCharactersDto } from './models/CommentWithReservedCharacters';
export type { CommentWithSlashes as CommentWithSlashesDto } from './models/CommentWithSlashes';
export type { Date as DateDto } from './models/Date';
export type { DictionaryWithArray as DictionaryWithArrayDto } from './models/DictionaryWithArray';
export type { DictionaryWithDictionary as DictionaryWithDictionaryDto } from './models/DictionaryWithDictionary';
export type { DictionaryWithProperties as DictionaryWithPropertiesDto } from './models/DictionaryWithProperties';
export type { DictionaryWithReference as DictionaryWithReferenceDto } from './models/DictionaryWithReference';
export type { DictionaryWithString as DictionaryWithStringDto } from './models/DictionaryWithString';
export type { EnumFromDescription as EnumFromDescriptionDto } from './models/EnumFromDescription';
export { EnumWithExtensions as EnumWithExtensionsDto } from './models/EnumWithExtensions';
export { EnumWithNumbers as EnumWithNumbersDto } from './models/EnumWithNumbers';
export { EnumWithStrings as EnumWithStringsDto } from './models/EnumWithStrings';
export type { ModelThatExtends as ModelThatExtendsDto } from './models/ModelThatExtends';
export type { ModelThatExtendsExtends as ModelThatExtendsExtendsDto } from './models/ModelThatExtendsExtends';
export type { ModelWithArray as ModelWithArrayDto } from './models/ModelWithArray';
export type { ModelWithBoolean as ModelWithBooleanDto } from './models/ModelWithBoolean';
export type { ModelWithCircularReference as ModelWithCircularReferenceDto } from './models/ModelWithCircularReference';
export type { ModelWithDictionary as ModelWithDictionaryDto } from './models/ModelWithDictionary';
export type { ModelWithDuplicateImports as ModelWithDuplicateImportsDto } from './models/ModelWithDuplicateImports';
export type { ModelWithDuplicateProperties as ModelWithDuplicatePropertiesDto } from './models/ModelWithDuplicateProperties';
export { ModelWithEnum as ModelWithEnumDto } from './models/ModelWithEnum';
export type { ModelWithEnumFromDescription as ModelWithEnumFromDescriptionDto } from './models/ModelWithEnumFromDescription';
export type { ModelWithInteger as ModelWithIntegerDto } from './models/ModelWithInteger';
export type { ModelWithNestedEnums as ModelWithNestedEnumsDto } from './models/ModelWithNestedEnums';
export type { ModelWithNestedProperties as ModelWithNestedPropertiesDto } from './models/ModelWithNestedProperties';
export type { ModelWithNullableString as ModelWithNullableStringDto } from './models/ModelWithNullableString';
export type { ModelWithOrderedProperties as ModelWithOrderedPropertiesDto } from './models/ModelWithOrderedProperties';
export type { ModelWithPattern as ModelWithPatternDto } from './models/ModelWithPattern';
export type { ModelWithProperties as ModelWithPropertiesDto } from './models/ModelWithProperties';
export type { ModelWithReference as ModelWithReferenceDto } from './models/ModelWithReference';
export type { ModelWithString as ModelWithStringDto } from './models/ModelWithString';
export type { SimpleBoolean as SimpleBooleanDto } from './models/SimpleBoolean';
export type { SimpleFile as SimpleFileDto } from './models/SimpleFile';
export type { SimpleInteger as SimpleIntegerDto } from './models/SimpleInteger';
export type { SimpleReference as SimpleReferenceDto } from './models/SimpleReference';
export type { SimpleString as SimpleStringDto } from './models/SimpleString';
export type { SimpleStringWithPattern as SimpleStringWithPatternDto } from './models/SimpleStringWithPattern';
export { $_default } from './schemas/$_default';
export { $ArrayWithArray } from './schemas/$ArrayWithArray';
export { $ArrayWithBooleans } from './schemas/$ArrayWithBooleans';
export { $ArrayWithNumbers } from './schemas/$ArrayWithNumbers';
@ -664,6 +617,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 */
@ -1441,6 +1406,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 */
@ -3614,6 +3593,7 @@ export { CancelablePromise, CancelError } from './core/CancelablePromise';
export { OpenAPI } from './core/OpenAPI';
export type { OpenAPIConfig } from './core/OpenAPI';
export { $ArrayWithArray } from './schemas/$ArrayWithArray';
export { $ArrayWithBooleans } from './schemas/$ArrayWithBooleans';
export { $ArrayWithNumbers } from './schemas/$ArrayWithNumbers';
@ -3706,6 +3686,18 @@ export { UploadService } from './services/UploadService';
"
`;
exports[`v3 should generate: ./test/generated/v3/models/_default.ts 1`] = `
"/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
export type _default = {
name?: string;
};
"
`;
exports[`v3 should generate: ./test/generated/v3/models/ArrayWithArray.ts 1`] = `
"/* istanbul ignore file */
/* tslint:disable */
@ -4831,6 +4823,20 @@ export type SimpleStringWithPattern = string | null;
"
`;
exports[`v3 should generate: ./test/generated/v3/schemas/$_default.ts 1`] = `
"/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
export const $_default = {
properties: {
name: {
type: 'string',
},
},
} as const;
"
`;
exports[`v3 should generate: ./test/generated/v3/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",

View File

@ -2511,6 +2511,14 @@
}
}
},
"default": {
"type": "object",
"properties": {
"name": {
"type": "string"
}
}
},
"Pageable": {
"type": "object",
"properties": {