Skip to content

Commit 2d8aa16

Browse files
committed
- Cleanup and latest dependencies
1 parent bd495d3 commit 2d8aa16

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+204
-270
lines changed

.eslintrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
"@typescript-eslint/explicit-module-boundary-types": 0,
2525
"sort-imports": "off",
2626
"import/order": "off",
27-
"simple-import-sort/sort": "error",
27+
"simple-import-sort/imports": "error",
28+
"simple-import-sort/exports": "error",
2829
"prettier/prettier": ["error"]
2930
}
3031
}

src/client/interfaces/Model.d.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,4 @@ export interface Model extends Schema {
1515
enum: Enum[];
1616
enums: Model[];
1717
properties: Model[];
18-
extendedFrom?: string[];
19-
extendedBy?: string[];
2018
}

src/openApi/v2/interfaces/OpenApiParameter.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { WithEnumExtension } from './Extensions/WithEnumExtension';
2-
import { WithNullableExtension } from './Extensions/WithNullableExtension';
2+
import type { WithNullableExtension } from './Extensions/WithNullableExtension';
33
import type { OpenApiItems } from './OpenApiItems';
44
import type { OpenApiReference } from './OpenApiReference';
55
import type { OpenApiSchema } from './OpenApiSchema';

src/openApi/v2/parser/constants.ts

Lines changed: 0 additions & 44 deletions
This file was deleted.

src/openApi/v2/parser/extendEnum.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ export function extendEnum(enumerators: Enum[], definition: WithEnumExtension):
1212
const descriptions = definition['x-enum-descriptions'];
1313

1414
return enumerators.map((enumerator, index) => ({
15-
name: (names && names[index]) || enumerator.name,
16-
description: (descriptions && descriptions[index]) || enumerator.description,
15+
name: names?.[index] || enumerator.name,
16+
description: descriptions?.[index] || enumerator.description,
1717
value: enumerator.value,
1818
type: enumerator.type,
1919
}));

src/openApi/v2/parser/getEnum.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type { Enum } from '../../../client/interfaces/Enum';
2-
import { PrimaryType } from './constants';
32
import { isDefined } from './isDefined';
43

54
export function getEnum(values?: (string | number)[]): Enum[] {
@@ -14,7 +13,7 @@ export function getEnum(values?: (string | number)[]): Enum[] {
1413
return {
1514
name: `_${value}`,
1615
value: String(value),
17-
type: PrimaryType.NUMBER,
16+
type: 'number',
1817
description: null,
1918
};
2019
}
@@ -25,7 +24,7 @@ export function getEnum(values?: (string | number)[]): Enum[] {
2524
.replace(/([a-z])([A-Z]+)/g, '$1_$2')
2625
.toUpperCase(),
2726
value: `'${value}'`,
28-
type: PrimaryType.STRING,
27+
type: 'string',
2928
description: null,
3029
};
3130
});

src/openApi/v2/parser/getEnumFromDescription.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type { Enum } from '../../../client/interfaces/Enum';
2-
import { PrimaryType } from './constants';
32

43
export function getEnumFromDescription(description: string): Enum[] {
54
// Check if we can find this special format string:
@@ -20,7 +19,7 @@ export function getEnumFromDescription(description: string): Enum[] {
2019
.replace(/([a-z])([A-Z]+)/g, '$1_$2')
2120
.toUpperCase(),
2221
value: String(value),
23-
type: PrimaryType.NUMBER,
22+
type: 'number',
2423
description: null,
2524
});
2625
}

src/openApi/v2/parser/getMappedType.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,31 @@
1-
import { PrimaryType, TYPE_MAPPINGS } from './constants';
1+
export const TYPE_MAPPINGS = new Map<string, string>([
2+
['File', 'File'],
3+
['file', 'File'],
4+
['any', 'any'],
5+
['object', 'any'],
6+
['array', 'any[]'],
7+
['boolean', 'boolean'],
8+
['byte', 'number'],
9+
['int', 'number'],
10+
['integer', 'number'],
11+
['float', 'number'],
12+
['double', 'number'],
13+
['short', 'number'],
14+
['long', 'number'],
15+
['number', 'number'],
16+
['char', 'string'],
17+
['date', 'string'],
18+
['date-time', 'string'],
19+
['password', 'string'],
20+
['string', 'string'],
21+
['void', 'void'],
22+
['null', 'null'],
23+
]);
224

325
/**
426
* Get mapped type for given type to any basic Typescript/Javascript type.
527
*/
6-
export function getMappedType(type: string): PrimaryType | undefined {
28+
export function getMappedType(type: string): string | undefined {
729
return TYPE_MAPPINGS.get(type);
830
}
931

src/openApi/v2/parser/getModel.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import type { Model } from '../../../client/interfaces/Model';
22
import type { OpenApi } from '../interfaces/OpenApi';
33
import type { OpenApiSchema } from '../interfaces/OpenApiSchema';
4-
import { PrimaryType } from './constants';
54
import { extendEnum } from './extendEnum';
65
import { getComment } from './getComment';
76
import { getEnum } from './getEnum';
@@ -14,8 +13,8 @@ export function getModel(openApi: OpenApi, definition: OpenApiSchema, isDefiniti
1413
const model: Model = {
1514
name: name,
1615
export: 'interface',
17-
type: PrimaryType.OBJECT,
18-
base: PrimaryType.OBJECT,
16+
type: 'any',
17+
base: 'any',
1918
template: null,
2019
link: null,
2120
description: getComment(definition.description),
@@ -59,8 +58,8 @@ export function getModel(openApi: OpenApi, definition: OpenApiSchema, isDefiniti
5958
const extendedEnumerators = extendEnum(enumerators, definition);
6059
if (extendedEnumerators.length) {
6160
model.export = 'enum';
62-
model.type = PrimaryType.STRING;
63-
model.base = PrimaryType.STRING;
61+
model.type = 'string';
62+
model.base = 'string';
6463
model.enum.push(...extendedEnumerators);
6564
return model;
6665
}
@@ -70,8 +69,8 @@ export function getModel(openApi: OpenApi, definition: OpenApiSchema, isDefiniti
7069
const enumerators = getEnumFromDescription(definition.description);
7170
if (enumerators.length) {
7271
model.export = 'enum';
73-
model.type = PrimaryType.NUMBER;
74-
model.base = PrimaryType.NUMBER;
72+
model.type = 'number';
73+
model.base = 'number';
7574
model.enum.push(...enumerators);
7675
return model;
7776
}
@@ -98,7 +97,7 @@ export function getModel(openApi: OpenApi, definition: OpenApiSchema, isDefiniti
9897
}
9998
}
10099

101-
if (definition.type === 'object' && definition.additionalProperties && typeof definition.additionalProperties === 'object') {
100+
if (definition.type === 'object' && typeof definition.additionalProperties === 'object') {
102101
if (definition.additionalProperties.$ref) {
103102
const additionalProperties = getType(definition.additionalProperties.$ref);
104103
model.export = 'dictionary';
@@ -121,10 +120,10 @@ export function getModel(openApi: OpenApi, definition: OpenApiSchema, isDefiniti
121120

122121
if (definition.type === 'object' || definition.allOf) {
123122
model.export = 'interface';
124-
model.type = PrimaryType.OBJECT;
125-
model.base = PrimaryType.OBJECT;
123+
model.type = 'any';
124+
model.base = 'any';
126125

127-
if (definition.allOf && definition.allOf.length) {
126+
if (definition.allOf?.length) {
128127
definition.allOf.forEach(parent => {
129128
if (parent.$ref) {
130129
const parentRef = getType(parent.$ref);

src/openApi/v2/parser/getModelProperties.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,19 @@ import type { OpenApi } from '../interfaces/OpenApi';
33
import type { OpenApiSchema } from '../interfaces/OpenApiSchema';
44
import { escapeName } from './escapeName';
55
import { getComment } from './getComment';
6+
import type { getModel } from './getModel';
67
import { getPattern } from './getPattern';
78
import { getType } from './getType';
89

9-
// Fix for circular dependency between getModel and getModelProperties
10-
export type GetModel = (openApi: OpenApi, definition: OpenApiSchema, isDefinition?: boolean, name?: string) => Model;
10+
// Fix for circular dependency
11+
export type GetModelFn = typeof getModel;
1112

12-
export function getModelProperties(openApi: OpenApi, definition: OpenApiSchema, getModel: GetModel): Model[] {
13+
export function getModelProperties(openApi: OpenApi, definition: OpenApiSchema, getModel: GetModelFn): Model[] {
1314
const models: Model[] = [];
1415
for (const propertyName in definition.properties) {
1516
if (definition.properties.hasOwnProperty(propertyName)) {
1617
const property = definition.properties[propertyName];
17-
const propertyRequired = definition.required && definition.required.includes(propertyName);
18+
const propertyRequired = definition.required?.includes(propertyName);
1819
if (property.$ref) {
1920
const model = getType(property.$ref);
2021
models.push({

0 commit comments

Comments
 (0)