mirror of
https://github.com/ferdikoomen/openapi-typescript-codegen.git
synced 2025-12-08 20:16:21 +00:00
Fixed escape of property names
This commit is contained in:
parent
107895a7fd
commit
6cce73bddc
7
src/openApi/v2/parser/escapeName.spec.ts
Normal file
7
src/openApi/v2/parser/escapeName.spec.ts
Normal file
@ -0,0 +1,7 @@
|
||||
import { escapeName } from './escapeName';
|
||||
|
||||
describe('escapeName', () => {
|
||||
it('should escape', () => {
|
||||
expect(escapeName('')).toEqual('');
|
||||
});
|
||||
});
|
||||
9
src/openApi/v2/parser/escapeName.ts
Normal file
9
src/openApi/v2/parser/escapeName.ts
Normal file
@ -0,0 +1,9 @@
|
||||
export function escapeName(value: string): string {
|
||||
if (value) {
|
||||
const validName = /^[a-zA-Z_$][\w$]+$/g.test(value);
|
||||
if (!validName) {
|
||||
return `'${value}'`;
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
@ -1,6 +1,7 @@
|
||||
import type { Model } from '../../../client/interfaces/Model';
|
||||
import type { OpenApi } from '../interfaces/OpenApi';
|
||||
import type { OpenApiSchema } from '../interfaces/OpenApiSchema';
|
||||
import { escapeName } from './escapeName';
|
||||
import { getComment } from './getComment';
|
||||
import { getType } from './getType';
|
||||
|
||||
@ -16,7 +17,7 @@ export function getModelProperties(openApi: OpenApi, definition: OpenApiSchema,
|
||||
if (property.$ref) {
|
||||
const model = getType(property.$ref);
|
||||
models.push({
|
||||
name: propertyName,
|
||||
name: escapeName(propertyName),
|
||||
export: 'reference',
|
||||
type: model.type,
|
||||
base: model.base,
|
||||
@ -50,7 +51,7 @@ export function getModelProperties(openApi: OpenApi, definition: OpenApiSchema,
|
||||
} else {
|
||||
const model = getModel(openApi, property);
|
||||
models.push({
|
||||
name: propertyName,
|
||||
name: escapeName(propertyName),
|
||||
export: model.export,
|
||||
type: model.type,
|
||||
base: model.base,
|
||||
|
||||
7
src/openApi/v3/parser/escapeName.spec.ts
Normal file
7
src/openApi/v3/parser/escapeName.spec.ts
Normal file
@ -0,0 +1,7 @@
|
||||
import { escapeName } from './escapeName';
|
||||
|
||||
describe('escapeName', () => {
|
||||
it('should escape', () => {
|
||||
expect(escapeName('')).toEqual('');
|
||||
});
|
||||
});
|
||||
9
src/openApi/v3/parser/escapeName.ts
Normal file
9
src/openApi/v3/parser/escapeName.ts
Normal file
@ -0,0 +1,9 @@
|
||||
export function escapeName(value: string): string {
|
||||
if (value) {
|
||||
const validName = /^[a-zA-Z_$][\w$]+$/g.test(value);
|
||||
if (!validName) {
|
||||
return `'${value}'`;
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
@ -1,6 +1,7 @@
|
||||
import type { Model } from '../../../client/interfaces/Model';
|
||||
import type { OpenApi } from '../interfaces/OpenApi';
|
||||
import type { OpenApiSchema } from '../interfaces/OpenApiSchema';
|
||||
import { escapeName } from './escapeName';
|
||||
import { getComment } from './getComment';
|
||||
import { getType } from './getType';
|
||||
|
||||
@ -16,7 +17,7 @@ export function getModelProperties(openApi: OpenApi, definition: OpenApiSchema,
|
||||
if (property.$ref) {
|
||||
const model = getType(property.$ref);
|
||||
models.push({
|
||||
name: propertyName,
|
||||
name: escapeName(propertyName),
|
||||
export: 'reference',
|
||||
type: model.type,
|
||||
base: model.base,
|
||||
@ -50,7 +51,7 @@ export function getModelProperties(openApi: OpenApi, definition: OpenApiSchema,
|
||||
} else {
|
||||
const model = getModel(openApi, property);
|
||||
models.push({
|
||||
name: propertyName,
|
||||
name: escapeName(propertyName),
|
||||
export: model.export,
|
||||
type: model.type,
|
||||
base: model.base,
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user