Skip to content

Commit 433b4f1

Browse files
author
Ferdi Koomen
committed
- Working on support for formData in v3
1 parent fa2bab0 commit 433b4f1

37 files changed

+405
-110
lines changed

.prettierrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
"singleQuote": true,
44
"trailingComma": "es5",
55
"arrowParens": "avoid",
6-
"printWidth": 200,
6+
"printWidth": 120,
77
"tabWidth": 4
88
}

src/client/interfaces/Schema.d.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,18 @@ export interface Schema {
33
isReadOnly: boolean;
44
isRequired: boolean;
55
isNullable: boolean;
6-
format?: 'int32' | 'int64' | 'float' | 'double' | 'string' | 'boolean' | 'byte' | 'binary' | 'date' | 'date-time' | 'password';
6+
format?:
7+
| 'int32'
8+
| 'int64'
9+
| 'float'
10+
| 'double'
11+
| 'string'
12+
| 'boolean'
13+
| 'byte'
14+
| 'binary'
15+
| 'date'
16+
| 'date-time'
17+
| 'password';
718
maximum?: number;
819
exclusiveMaximum?: boolean;
920
minimum?: number;

src/index.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,39 @@ export async function generate({
6666
const client = parseV2(openApi);
6767
const clientFinal = postProcessClient(client);
6868
if (!write) break;
69-
await writeClient(clientFinal, templates, output, httpClient, useOptions, useUnionTypes, exportCore, exportServices, exportModels, exportSchemas, request);
69+
await writeClient(
70+
clientFinal,
71+
templates,
72+
output,
73+
httpClient,
74+
useOptions,
75+
useUnionTypes,
76+
exportCore,
77+
exportServices,
78+
exportModels,
79+
exportSchemas,
80+
request
81+
);
7082
break;
7183
}
7284

7385
case OpenApiVersion.V3: {
7486
const client = parseV3(openApi);
7587
const clientFinal = postProcessClient(client);
7688
if (!write) break;
77-
await writeClient(clientFinal, templates, output, httpClient, useOptions, useUnionTypes, exportCore, exportServices, exportModels, exportSchemas, request);
89+
await writeClient(
90+
clientFinal,
91+
templates,
92+
output,
93+
httpClient,
94+
useOptions,
95+
useUnionTypes,
96+
exportCore,
97+
exportServices,
98+
exportModels,
99+
exportSchemas,
100+
request
101+
);
78102
break;
79103
}
80104
}

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,18 @@ import type { OpenApiItems } from './OpenApiItems';
77
export interface OpenApiHeader {
88
description?: string;
99
type: 'string' | 'number' | 'integer' | 'boolean' | 'array';
10-
format?: 'int32' | 'int64' | 'float' | 'double' | 'string' | 'boolean' | 'byte' | 'binary' | 'date' | 'date-time' | 'password';
10+
format?:
11+
| 'int32'
12+
| 'int64'
13+
| 'float'
14+
| 'double'
15+
| 'string'
16+
| 'boolean'
17+
| 'byte'
18+
| 'binary'
19+
| 'date'
20+
| 'date-time'
21+
| 'password';
1122
items?: Dictionary<OpenApiItems>;
1223
collectionFormat?: 'csv' | 'ssv' | 'tsv' | 'pipes';
1324
default?: any;

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,18 @@ import type { WithEnumExtension } from './Extensions/WithEnumExtension';
55
*/
66
export interface OpenApiItems extends WithEnumExtension {
77
type?: string;
8-
format?: 'int32' | 'int64' | 'float' | 'double' | 'string' | 'boolean' | 'byte' | 'binary' | 'date' | 'date-time' | 'password';
8+
format?:
9+
| 'int32'
10+
| 'int64'
11+
| 'float'
12+
| 'double'
13+
| 'string'
14+
| 'boolean'
15+
| 'byte'
16+
| 'binary'
17+
| 'date'
18+
| 'date-time'
19+
| 'password';
920
items?: OpenApiItems;
1021
collectionFormat?: 'csv' | 'ssv' | 'tsv' | 'pipes';
1122
default?: any;

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,18 @@ export interface OpenApiParameter extends OpenApiReference, WithEnumExtension, W
1414
required?: boolean;
1515
schema?: OpenApiSchema;
1616
type?: string;
17-
format?: 'int32' | 'int64' | 'float' | 'double' | 'string' | 'boolean' | 'byte' | 'binary' | 'date' | 'date-time' | 'password';
17+
format?:
18+
| 'int32'
19+
| 'int64'
20+
| 'float'
21+
| 'double'
22+
| 'string'
23+
| 'boolean'
24+
| 'byte'
25+
| 'binary'
26+
| 'date'
27+
| 'date-time'
28+
| 'password';
1829
allowEmptyValue?: boolean;
1930
items?: OpenApiItems;
2031
collectionFormat?: 'csv' | 'ssv' | 'tsv' | 'pipes' | 'multi';

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,18 @@ export interface OpenApiSchema extends OpenApiReference, WithEnumExtension, With
2828
required?: string[];
2929
enum?: (string | number)[];
3030
type?: string;
31-
format?: 'int32' | 'int64' | 'float' | 'double' | 'string' | 'boolean' | 'byte' | 'binary' | 'date' | 'date-time' | 'password';
31+
format?:
32+
| 'int32'
33+
| 'int64'
34+
| 'float'
35+
| 'double'
36+
| 'string'
37+
| 'boolean'
38+
| 'byte'
39+
| 'binary'
40+
| 'date'
41+
| 'date-time'
42+
| 'password';
3243
items?: OpenApiSchema;
3344
allOf?: OpenApiSchema[];
3445
properties?: Dictionary<OpenApiSchema>;

src/openApi/v2/parser/getComment.spec.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,25 @@ import { getComment } from './getComment';
44

55
describe('getComment', () => {
66
it('should parse comments', () => {
7-
const multiline = 'Testing multiline comments.' + EOL + ' * This must go to the next line.' + EOL + ' * ' + EOL + ' * This will contain a break.';
7+
const multiline =
8+
'Testing multiline comments.' +
9+
EOL +
10+
' * This must go to the next line.' +
11+
EOL +
12+
' * ' +
13+
EOL +
14+
' * This will contain a break.';
815
expect(getComment('')).toEqual(null);
916
expect(getComment('Hello')).toEqual('Hello');
1017
expect(getComment('Hello World!')).toEqual('Hello World!');
1118
expect(getComment('Testing */escape/*')).toEqual('Testing *_/escape/*');
12-
expect(getComment('Testing multiline comments.\nThis must go to the next line.\n\nThis will contain a break.')).toEqual(multiline);
13-
expect(getComment('Testing multiline comments.\r\nThis must go to the next line.\r\n\r\nThis will contain a break.')).toEqual(multiline);
19+
expect(
20+
getComment('Testing multiline comments.\nThis must go to the next line.\n\nThis will contain a break.')
21+
).toEqual(multiline);
22+
expect(
23+
getComment(
24+
'Testing multiline comments.\r\nThis must go to the next line.\r\n\r\nThis will contain a break.'
25+
)
26+
).toEqual(multiline);
1427
});
1528
});

src/openApi/v2/parser/getModel.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@ import { getModelComposition } from './getModelComposition';
1010
import { getModelProperties } from './getModelProperties';
1111
import { getType } from './getType';
1212

13-
export function getModel(openApi: OpenApi, definition: OpenApiSchema, isDefinition: boolean = false, name: string = ''): Model {
13+
export function getModel(
14+
openApi: OpenApi,
15+
definition: OpenApiSchema,
16+
isDefinition: boolean = false,
17+
name: string = ''
18+
): Model {
1419
const model: Model = {
1520
name,
1621
export: 'interface',

src/openApi/v2/parser/getModelComposition.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@ import { getRequiredPropertiesFromComposition } from './getRequiredPropertiesFro
99
// Fix for circular dependency
1010
export type GetModelFn = typeof getModel;
1111

12-
export function getModelComposition(openApi: OpenApi, definition: OpenApiSchema, definitions: OpenApiSchema[], type: 'one-of' | 'any-of' | 'all-of', getModel: GetModelFn): ModelComposition {
12+
export function getModelComposition(
13+
openApi: OpenApi,
14+
definition: OpenApiSchema,
15+
definitions: OpenApiSchema[],
16+
type: 'one-of' | 'any-of' | 'all-of',
17+
getModel: GetModelFn
18+
): ModelComposition {
1319
const composition: ModelComposition = {
1420
type,
1521
imports: [],
@@ -35,7 +41,12 @@ export function getModelComposition(openApi: OpenApi, definition: OpenApiSchema,
3541
});
3642

3743
if (definition.required) {
38-
const requiredProperties = getRequiredPropertiesFromComposition(openApi, definition.required, definitions, getModel);
44+
const requiredProperties = getRequiredPropertiesFromComposition(
45+
openApi,
46+
definition.required,
47+
definitions,
48+
getModel
49+
);
3950
requiredProperties.forEach(requiredProperty => {
4051
composition.imports.push(...requiredProperty.imports);
4152
composition.enums.push(...requiredProperty.enums);

0 commit comments

Comments
 (0)