mirror of
https://github.com/ferdikoomen/openapi-typescript-codegen.git
synced 2025-12-08 20:16:21 +00:00
- Fixed #408
This commit is contained in:
parent
9ab697327e
commit
b871eab07f
@ -17,8 +17,6 @@ export const TYPE_MAPPINGS = new Map<string, PrimaryType>([
|
||||
['boolean', PrimaryType.BOOLEAN],
|
||||
['byte', PrimaryType.NUMBER],
|
||||
['int', PrimaryType.NUMBER],
|
||||
['int32', PrimaryType.NUMBER],
|
||||
['int64', PrimaryType.NUMBER],
|
||||
['integer', PrimaryType.NUMBER],
|
||||
['float', PrimaryType.NUMBER],
|
||||
['double', PrimaryType.NUMBER],
|
||||
|
||||
@ -2,8 +2,8 @@ import { getMappedType } from './getMappedType';
|
||||
|
||||
describe('getMappedType', () => {
|
||||
it('should map types to the basics', () => {
|
||||
expect(getMappedType('File')).toEqual('File');
|
||||
expect(getMappedType('String')).toEqual('string');
|
||||
expect(getMappedType('file')).toEqual('File');
|
||||
expect(getMappedType('string')).toEqual('string');
|
||||
expect(getMappedType('date')).toEqual('string');
|
||||
expect(getMappedType('date-time')).toEqual('string');
|
||||
expect(getMappedType('float')).toEqual('number');
|
||||
|
||||
@ -4,9 +4,9 @@ import { PrimaryType, TYPE_MAPPINGS } from './constants';
|
||||
* Get mapped type for given type to any basic Typescript/Javascript type.
|
||||
*/
|
||||
export function getMappedType(type: string): PrimaryType | undefined {
|
||||
return TYPE_MAPPINGS.get(type.toLowerCase());
|
||||
return TYPE_MAPPINGS.get(type);
|
||||
}
|
||||
|
||||
export function hasMappedType(type: string): boolean {
|
||||
return TYPE_MAPPINGS.has(type.toLowerCase());
|
||||
return TYPE_MAPPINGS.has(type);
|
||||
}
|
||||
|
||||
@ -10,7 +10,7 @@ describe('getType', () => {
|
||||
});
|
||||
|
||||
it('should convert string', () => {
|
||||
const type = getType('String');
|
||||
const type = getType('string');
|
||||
expect(type.type).toEqual('string');
|
||||
expect(type.base).toEqual('string');
|
||||
expect(type.template).toEqual(null);
|
||||
@ -18,7 +18,7 @@ describe('getType', () => {
|
||||
});
|
||||
|
||||
it('should convert string array', () => {
|
||||
const type = getType('Array[String]');
|
||||
const type = getType('array[string]');
|
||||
expect(type.type).toEqual('string[]');
|
||||
expect(type.base).toEqual('string');
|
||||
expect(type.template).toEqual(null);
|
||||
@ -26,7 +26,7 @@ describe('getType', () => {
|
||||
});
|
||||
|
||||
it('should convert template with primary', () => {
|
||||
const type = getType('#/definitions/Link[String]');
|
||||
const type = getType('#/definitions/Link[string]');
|
||||
expect(type.type).toEqual('Link<string>');
|
||||
expect(type.base).toEqual('Link');
|
||||
expect(type.template).toEqual('string');
|
||||
|
||||
@ -1,14 +0,0 @@
|
||||
import { isPrimaryType } from './isPrimaryType';
|
||||
|
||||
describe('isPrimaryType', () => {
|
||||
it('should return true for primary types', () => {
|
||||
expect(isPrimaryType('number')).toBeTruthy();
|
||||
expect(isPrimaryType('boolean')).toBeTruthy();
|
||||
expect(isPrimaryType('string')).toBeTruthy();
|
||||
expect(isPrimaryType('any')).toBeTruthy();
|
||||
expect(isPrimaryType('void')).toBeTruthy();
|
||||
expect(isPrimaryType('null')).toBeTruthy();
|
||||
expect(isPrimaryType('Array')).toBeFalsy();
|
||||
expect(isPrimaryType('MyModel')).toBeFalsy();
|
||||
});
|
||||
});
|
||||
@ -1,19 +0,0 @@
|
||||
import { PrimaryType } from './constants';
|
||||
|
||||
/**
|
||||
* Check if given type is a primary type.
|
||||
* @param type
|
||||
*/
|
||||
export function isPrimaryType(type: string): type is PrimaryType {
|
||||
switch (type.toLowerCase()) {
|
||||
case PrimaryType.FILE:
|
||||
case PrimaryType.OBJECT:
|
||||
case PrimaryType.BOOLEAN:
|
||||
case PrimaryType.NUMBER:
|
||||
case PrimaryType.STRING:
|
||||
case PrimaryType.VOID:
|
||||
case PrimaryType.NULL:
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -17,8 +17,6 @@ export const TYPE_MAPPINGS = new Map<string, PrimaryType>([
|
||||
['boolean', PrimaryType.BOOLEAN],
|
||||
['byte', PrimaryType.NUMBER],
|
||||
['int', PrimaryType.NUMBER],
|
||||
['int32', PrimaryType.NUMBER],
|
||||
['int64', PrimaryType.NUMBER],
|
||||
['integer', PrimaryType.NUMBER],
|
||||
['float', PrimaryType.NUMBER],
|
||||
['double', PrimaryType.NUMBER],
|
||||
|
||||
@ -2,8 +2,8 @@ import { getMappedType } from './getMappedType';
|
||||
|
||||
describe('getMappedType', () => {
|
||||
it('should map types to the basics', () => {
|
||||
expect(getMappedType('File')).toEqual('File');
|
||||
expect(getMappedType('String')).toEqual('string');
|
||||
expect(getMappedType('file')).toEqual('File');
|
||||
expect(getMappedType('string')).toEqual('string');
|
||||
expect(getMappedType('date')).toEqual('string');
|
||||
expect(getMappedType('date-time')).toEqual('string');
|
||||
expect(getMappedType('float')).toEqual('number');
|
||||
|
||||
@ -4,9 +4,9 @@ import { PrimaryType, TYPE_MAPPINGS } from './constants';
|
||||
* Get mapped type for given type to any basic Typescript/Javascript type.
|
||||
*/
|
||||
export function getMappedType(type: string): PrimaryType | undefined {
|
||||
return TYPE_MAPPINGS.get(type.toLowerCase());
|
||||
return TYPE_MAPPINGS.get(type);
|
||||
}
|
||||
|
||||
export function hasMappedType(type: string): boolean {
|
||||
return TYPE_MAPPINGS.has(type.toLowerCase());
|
||||
return TYPE_MAPPINGS.has(type);
|
||||
}
|
||||
|
||||
@ -10,7 +10,7 @@ describe('getType', () => {
|
||||
});
|
||||
|
||||
it('should convert string', () => {
|
||||
const type = getType('String');
|
||||
const type = getType('string');
|
||||
expect(type.type).toEqual('string');
|
||||
expect(type.base).toEqual('string');
|
||||
expect(type.template).toEqual(null);
|
||||
@ -18,7 +18,7 @@ describe('getType', () => {
|
||||
});
|
||||
|
||||
it('should convert string array', () => {
|
||||
const type = getType('Array[String]');
|
||||
const type = getType('array[string]');
|
||||
expect(type.type).toEqual('string[]');
|
||||
expect(type.base).toEqual('string');
|
||||
expect(type.template).toEqual(null);
|
||||
@ -26,7 +26,7 @@ describe('getType', () => {
|
||||
});
|
||||
|
||||
it('should convert template with primary', () => {
|
||||
const type = getType('#/components/schemas/Link[String]');
|
||||
const type = getType('#/components/schemas/Link[string]');
|
||||
expect(type.type).toEqual('Link<string>');
|
||||
expect(type.base).toEqual('Link');
|
||||
expect(type.template).toEqual('string');
|
||||
|
||||
@ -1,14 +0,0 @@
|
||||
import { isPrimaryType } from './isPrimaryType';
|
||||
|
||||
describe('isPrimaryType', () => {
|
||||
it('should return true for primary types', () => {
|
||||
expect(isPrimaryType('number')).toBeTruthy();
|
||||
expect(isPrimaryType('boolean')).toBeTruthy();
|
||||
expect(isPrimaryType('string')).toBeTruthy();
|
||||
expect(isPrimaryType('any')).toBeTruthy();
|
||||
expect(isPrimaryType('void')).toBeTruthy();
|
||||
expect(isPrimaryType('null')).toBeTruthy();
|
||||
expect(isPrimaryType('Array')).toBeFalsy();
|
||||
expect(isPrimaryType('MyModel')).toBeFalsy();
|
||||
});
|
||||
});
|
||||
@ -1,19 +0,0 @@
|
||||
import { PrimaryType } from './constants';
|
||||
|
||||
/**
|
||||
* Check if given type is a primary type.
|
||||
* @param type
|
||||
*/
|
||||
export function isPrimaryType(type: string): type is PrimaryType {
|
||||
switch (type.toLowerCase()) {
|
||||
case PrimaryType.FILE:
|
||||
case PrimaryType.OBJECT:
|
||||
case PrimaryType.BOOLEAN:
|
||||
case PrimaryType.NUMBER:
|
||||
case PrimaryType.STRING:
|
||||
case PrimaryType.VOID:
|
||||
case PrimaryType.NULL:
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -300,6 +300,7 @@ export type { ArrayWithNumbers } from './models/ArrayWithNumbers';
|
||||
export type { ArrayWithProperties } from './models/ArrayWithProperties';
|
||||
export type { ArrayWithReferences } from './models/ArrayWithReferences';
|
||||
export type { ArrayWithStrings } from './models/ArrayWithStrings';
|
||||
export type { Date } from './models/Date';
|
||||
export type { DictionaryWithArray } from './models/DictionaryWithArray';
|
||||
export type { DictionaryWithDictionary } from './models/DictionaryWithDictionary';
|
||||
export type { DictionaryWithProperties } from './models/DictionaryWithProperties';
|
||||
@ -344,6 +345,7 @@ export { $ArrayWithNumbers } from './schemas/$ArrayWithNumbers';
|
||||
export { $ArrayWithProperties } from './schemas/$ArrayWithProperties';
|
||||
export { $ArrayWithReferences } from './schemas/$ArrayWithReferences';
|
||||
export { $ArrayWithStrings } from './schemas/$ArrayWithStrings';
|
||||
export { $Date } from './schemas/$Date';
|
||||
export { $DictionaryWithArray } from './schemas/$DictionaryWithArray';
|
||||
export { $DictionaryWithDictionary } from './schemas/$DictionaryWithDictionary';
|
||||
export { $DictionaryWithProperties } from './schemas/$DictionaryWithProperties';
|
||||
@ -466,6 +468,17 @@ exports[`v2 should generate: ./test/generated/v2/models/ArrayWithStrings.ts 1`]
|
||||
export type ArrayWithStrings = Array<string>;"
|
||||
`;
|
||||
|
||||
exports[`v2 should generate: ./test/generated/v2/models/Date.ts 1`] = `
|
||||
"/* istanbul ignore file */
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
|
||||
/**
|
||||
* This is a type-only model that defines Date as a string
|
||||
*/
|
||||
export type Date = string;"
|
||||
`;
|
||||
|
||||
exports[`v2 should generate: ./test/generated/v2/models/DictionaryWithArray.ts 1`] = `
|
||||
"/* istanbul ignore file */
|
||||
/* tslint:disable */
|
||||
@ -1172,6 +1185,16 @@ export const $ArrayWithStrings = {
|
||||
};"
|
||||
`;
|
||||
|
||||
exports[`v2 should generate: ./test/generated/v2/schemas/$Date.ts 1`] = `
|
||||
"/* istanbul ignore file */
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
|
||||
export const $Date = {
|
||||
type: 'string',
|
||||
};"
|
||||
`;
|
||||
|
||||
exports[`v2 should generate: ./test/generated/v2/schemas/$DictionaryWithArray.ts 1`] = `
|
||||
"/* istanbul ignore file */
|
||||
/* tslint:disable */
|
||||
@ -2621,6 +2644,7 @@ export type { ArrayWithNumbers } from './models/ArrayWithNumbers';
|
||||
export type { ArrayWithProperties } from './models/ArrayWithProperties';
|
||||
export type { ArrayWithReferences } from './models/ArrayWithReferences';
|
||||
export type { ArrayWithStrings } from './models/ArrayWithStrings';
|
||||
export type { Date } from './models/Date';
|
||||
export type { DictionaryWithArray } from './models/DictionaryWithArray';
|
||||
export type { DictionaryWithDictionary } from './models/DictionaryWithDictionary';
|
||||
export type { DictionaryWithProperties } from './models/DictionaryWithProperties';
|
||||
@ -2666,6 +2690,7 @@ export { $ArrayWithNumbers } from './schemas/$ArrayWithNumbers';
|
||||
export { $ArrayWithProperties } from './schemas/$ArrayWithProperties';
|
||||
export { $ArrayWithReferences } from './schemas/$ArrayWithReferences';
|
||||
export { $ArrayWithStrings } from './schemas/$ArrayWithStrings';
|
||||
export { $Date } from './schemas/$Date';
|
||||
export { $DictionaryWithArray } from './schemas/$DictionaryWithArray';
|
||||
export { $DictionaryWithDictionary } from './schemas/$DictionaryWithDictionary';
|
||||
export { $DictionaryWithProperties } from './schemas/$DictionaryWithProperties';
|
||||
@ -2792,6 +2817,17 @@ exports[`v3 should generate: ./test/generated/v3/models/ArrayWithStrings.ts 1`]
|
||||
export type ArrayWithStrings = Array<string>;"
|
||||
`;
|
||||
|
||||
exports[`v3 should generate: ./test/generated/v3/models/Date.ts 1`] = `
|
||||
"/* istanbul ignore file */
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
|
||||
/**
|
||||
* This is a type-only model that defines Date as a string
|
||||
*/
|
||||
export type Date = string;"
|
||||
`;
|
||||
|
||||
exports[`v3 should generate: ./test/generated/v3/models/DictionaryWithArray.ts 1`] = `
|
||||
"/* istanbul ignore file */
|
||||
/* tslint:disable */
|
||||
@ -3516,6 +3552,16 @@ export const $ArrayWithStrings = {
|
||||
};"
|
||||
`;
|
||||
|
||||
exports[`v3 should generate: ./test/generated/v3/schemas/$Date.ts 1`] = `
|
||||
"/* istanbul ignore file */
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
|
||||
export const $Date = {
|
||||
type: 'string',
|
||||
};"
|
||||
`;
|
||||
|
||||
exports[`v3 should generate: ./test/generated/v3/schemas/$DictionaryWithArray.ts 1`] = `
|
||||
"/* istanbul ignore file */
|
||||
/* tslint:disable */
|
||||
|
||||
@ -705,7 +705,7 @@
|
||||
},
|
||||
"SimpleFile": {
|
||||
"description": "This is a simple file",
|
||||
"type": "File"
|
||||
"type": "file"
|
||||
},
|
||||
"SimpleReference": {
|
||||
"description": "This is a simple reference",
|
||||
@ -857,6 +857,10 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"Date": {
|
||||
"description": "This is a type-only model that defines Date as a string",
|
||||
"type": "string"
|
||||
},
|
||||
"ModelWithInteger": {
|
||||
"description": "This is a model with one number property",
|
||||
"type": "object",
|
||||
@ -1003,7 +1007,7 @@
|
||||
"propWithFile": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "File"
|
||||
"type": "file"
|
||||
}
|
||||
},
|
||||
"propWithNumber": {
|
||||
|
||||
@ -869,7 +869,7 @@
|
||||
"in": "formData",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "File"
|
||||
"type": "file"
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -1185,7 +1185,7 @@
|
||||
},
|
||||
"SimpleFile": {
|
||||
"description": "This is a simple file",
|
||||
"type": "File"
|
||||
"type": "file"
|
||||
},
|
||||
"SimpleReference": {
|
||||
"description": "This is a simple reference",
|
||||
@ -1338,6 +1338,10 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"Date": {
|
||||
"description": "This is a type-only model that defines Date as a string",
|
||||
"type": "string"
|
||||
},
|
||||
"ModelWithInteger": {
|
||||
"description": "This is a model with one number property",
|
||||
"type": "object",
|
||||
@ -1465,7 +1469,7 @@
|
||||
"propWithFile": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "File"
|
||||
"type": "file"
|
||||
}
|
||||
},
|
||||
"propWithNumber": {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user