diff --git a/src/openApi/v2/parser/constants.ts b/src/openApi/v2/parser/constants.ts index 6336efda..d252a416 100644 --- a/src/openApi/v2/parser/constants.ts +++ b/src/openApi/v2/parser/constants.ts @@ -17,8 +17,6 @@ export const TYPE_MAPPINGS = new Map([ ['boolean', PrimaryType.BOOLEAN], ['byte', PrimaryType.NUMBER], ['int', PrimaryType.NUMBER], - ['int32', PrimaryType.NUMBER], - ['int64', PrimaryType.NUMBER], ['integer', PrimaryType.NUMBER], ['float', PrimaryType.NUMBER], ['double', PrimaryType.NUMBER], diff --git a/src/openApi/v2/parser/getMappedType.spec.ts b/src/openApi/v2/parser/getMappedType.spec.ts index 46b82d5b..48205d76 100644 --- a/src/openApi/v2/parser/getMappedType.spec.ts +++ b/src/openApi/v2/parser/getMappedType.spec.ts @@ -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'); diff --git a/src/openApi/v2/parser/getMappedType.ts b/src/openApi/v2/parser/getMappedType.ts index 8764d1f0..2b786e20 100644 --- a/src/openApi/v2/parser/getMappedType.ts +++ b/src/openApi/v2/parser/getMappedType.ts @@ -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); } diff --git a/src/openApi/v2/parser/getType.spec.ts b/src/openApi/v2/parser/getType.spec.ts index b16eaca2..acbeb712 100644 --- a/src/openApi/v2/parser/getType.spec.ts +++ b/src/openApi/v2/parser/getType.spec.ts @@ -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'); expect(type.base).toEqual('Link'); expect(type.template).toEqual('string'); diff --git a/src/openApi/v2/parser/isPrimaryType.spec.ts b/src/openApi/v2/parser/isPrimaryType.spec.ts deleted file mode 100644 index ed3e1774..00000000 --- a/src/openApi/v2/parser/isPrimaryType.spec.ts +++ /dev/null @@ -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(); - }); -}); diff --git a/src/openApi/v2/parser/isPrimaryType.ts b/src/openApi/v2/parser/isPrimaryType.ts deleted file mode 100644 index dfb9e778..00000000 --- a/src/openApi/v2/parser/isPrimaryType.ts +++ /dev/null @@ -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; -} diff --git a/src/openApi/v3/parser/constants.ts b/src/openApi/v3/parser/constants.ts index 7a8632dd..043cf174 100644 --- a/src/openApi/v3/parser/constants.ts +++ b/src/openApi/v3/parser/constants.ts @@ -17,8 +17,6 @@ export const TYPE_MAPPINGS = new Map([ ['boolean', PrimaryType.BOOLEAN], ['byte', PrimaryType.NUMBER], ['int', PrimaryType.NUMBER], - ['int32', PrimaryType.NUMBER], - ['int64', PrimaryType.NUMBER], ['integer', PrimaryType.NUMBER], ['float', PrimaryType.NUMBER], ['double', PrimaryType.NUMBER], diff --git a/src/openApi/v3/parser/getMappedType.spec.ts b/src/openApi/v3/parser/getMappedType.spec.ts index 46b82d5b..48205d76 100644 --- a/src/openApi/v3/parser/getMappedType.spec.ts +++ b/src/openApi/v3/parser/getMappedType.spec.ts @@ -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'); diff --git a/src/openApi/v3/parser/getMappedType.ts b/src/openApi/v3/parser/getMappedType.ts index 8764d1f0..2b786e20 100644 --- a/src/openApi/v3/parser/getMappedType.ts +++ b/src/openApi/v3/parser/getMappedType.ts @@ -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); } diff --git a/src/openApi/v3/parser/getType.spec.ts b/src/openApi/v3/parser/getType.spec.ts index 9c50cfb2..0984014e 100644 --- a/src/openApi/v3/parser/getType.spec.ts +++ b/src/openApi/v3/parser/getType.spec.ts @@ -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'); expect(type.base).toEqual('Link'); expect(type.template).toEqual('string'); diff --git a/src/openApi/v3/parser/isPrimaryType.spec.ts b/src/openApi/v3/parser/isPrimaryType.spec.ts deleted file mode 100644 index ed3e1774..00000000 --- a/src/openApi/v3/parser/isPrimaryType.spec.ts +++ /dev/null @@ -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(); - }); -}); diff --git a/src/openApi/v3/parser/isPrimaryType.ts b/src/openApi/v3/parser/isPrimaryType.ts deleted file mode 100644 index dfb9e778..00000000 --- a/src/openApi/v3/parser/isPrimaryType.ts +++ /dev/null @@ -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; -} diff --git a/test/__snapshots__/index.spec.js.snap b/test/__snapshots__/index.spec.js.snap index 484bfec0..8e8eb9e2 100644 --- a/test/__snapshots__/index.spec.js.snap +++ b/test/__snapshots__/index.spec.js.snap @@ -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;" `; +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;" `; +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 */ diff --git a/test/spec/v2.json b/test/spec/v2.json index 5649e438..b5b39cdd 100644 --- a/test/spec/v2.json +++ b/test/spec/v2.json @@ -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": { diff --git a/test/spec/v3.json b/test/spec/v3.json index daa47fd0..8e752d0c 100644 --- a/test/spec/v3.json +++ b/test/spec/v3.json @@ -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": {