Skip to content

Commit e0c2b79

Browse files
committed
- Removing old useUnionTypes
- Working on fix for reusable request body
1 parent ceb1aef commit e0c2b79

16 files changed

+99
-100
lines changed

bin/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ program
1212
.option('-o, --output <value>', 'Output directory', './generated')
1313
.option('-c, --client <value>', 'HTTP client to generate [fetch, xhr]', 'fetch')
1414
.option('--useOptions', 'Use options vs arguments style functions')
15-
.option('--useUnionTypes', 'Use inclusive union types')
15+
.option('--useUnionTypes', 'Use union types instead of enums')
1616
.option('--exportCore <value>', 'Generate core', true)
1717
.option('--exportServices <value>', 'Generate services', true)
1818
.option('--exportModels <value>', 'Generate models', true)

src/index.spec.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ describe('index', () => {
66
input: './test/mock/v2/spec.json',
77
output: './test/result/v2/',
88
useOptions: true,
9-
useUnionTypes: true,
109
write: false,
1110
});
1211
});
@@ -16,7 +15,6 @@ describe('index', () => {
1615
input: './test/mock/v3/spec.json',
1716
output: './test/result/v3/',
1817
useOptions: true,
19-
useUnionTypes: true,
2018
write: false,
2119
});
2220
});

src/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,18 @@ export async function generate({
6161
switch (openApiVersion) {
6262
case OpenApiVersion.V2: {
6363
const client = parseV2(openApi);
64-
const clientFinal = postProcessClient(client, useUnionTypes);
64+
const clientFinal = postProcessClient(client);
6565
if (write) {
66-
await writeClient(clientFinal, templates, output, httpClient, useOptions, exportCore, exportServices, exportModels, exportSchemas);
66+
await writeClient(clientFinal, templates, output, httpClient, useOptions, useUnionTypes, exportCore, exportServices, exportModels, exportSchemas);
6767
}
6868
break;
6969
}
7070

7171
case OpenApiVersion.V3: {
7272
const client = parseV3(openApi);
73-
const clientFinal = postProcessClient(client, useUnionTypes);
73+
const clientFinal = postProcessClient(client);
7474
if (write) {
75-
await writeClient(clientFinal, templates, output, httpClient, useOptions, exportCore, exportServices, exportModels, exportSchemas);
75+
await writeClient(clientFinal, templates, output, httpClient, useOptions, useUnionTypes, exportCore, exportServices, exportModels, exportSchemas);
7676
}
7777
break;
7878
}

src/templates/core/request.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
/* tslint:disable */
33
/* eslint-disable */
44

5-
import {getFormData} from './getFormData';
6-
import {getQueryString} from './getQueryString';
7-
import {OpenAPI} from './OpenAPI';
8-
import {RequestOptions} from './RequestOptions';
9-
import {requestUsingFetch} from './requestUsingFetch';
10-
import {requestUsingXHR} from './requestUsingXHR';
11-
import {Result} from './Result';
5+
import { getFormData } from './getFormData';
6+
import { getQueryString } from './getQueryString';
7+
import { OpenAPI } from './OpenAPI';
8+
import { RequestOptions } from './RequestOptions';
9+
import { requestUsingFetch } from './requestUsingFetch';
10+
import { requestUsingXHR } from './requestUsingXHR';
11+
import { Result } from './Result';
1212

1313
/**
1414
* Create the request.

src/utils/getExtendedByList.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { unique } from './unique';
55

66
/**
77
* Get the full list of models that are extended by the given model.
8-
* This list is used when we have the flag "useUnionTypes" enabled.
98
* @param model
109
* @param client
1110
*/

src/utils/getExtendedFromList.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { unique } from './unique';
55

66
/**
77
* Get the full list of models that are extended from the given model.
8-
* This list is used when we have the flag "useUnionTypes" enabled.
98
* @param model
109
* @param client
1110
*/

src/utils/postProcessClient.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@ import { postProcessService } from './postProcessService';
55
/**
66
* Post process client
77
* @param client Client object with all the models, services, etc.
8-
* @param useUnionTypes Use inclusive union types.
98
*/
10-
export function postProcessClient(client: Client, useUnionTypes: boolean): Client {
9+
export function postProcessClient(client: Client): Client {
1110
return {
1211
...client,
13-
models: client.models.map(model => postProcessModel(model, client, useUnionTypes)),
14-
services: client.services.map(service => postProcessService(service, client, useUnionTypes)),
12+
models: client.models.map(model => postProcessModel(model)),
13+
services: client.services.map(service => postProcessService(service)),
1514
};
1615
}

src/utils/postProcessModel.ts

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,18 @@
1-
import { Client } from '../client/interfaces/Client';
21
import { Model } from '../client/interfaces/Model';
32
import { postProcessModelEnum } from './postProcessModelEnum';
43
import { postProcessModelEnums } from './postProcessModelEnums';
54
import { postProcessModelImports } from './postProcessModelImports';
6-
import { postProcessUnionTypes } from './postProcessUnionTypes';
75

86
/**
9-
* Post process the model. If needed this will convert types to union types,
10-
* see the "useUnionTypes" flag in the documentation. Plus this will cleanup
11-
* any double imports or enum values.
7+
* Post process the model.
8+
* This will cleanup any double imports or enum values.
129
* @param model
13-
* @param client
14-
* @param useUnionTypes
1510
*/
16-
export function postProcessModel(model: Model, client: Client, useUnionTypes: boolean): Model {
17-
const clone = postProcessUnionTypes(model, client, useUnionTypes);
11+
export function postProcessModel(model: Model): Model {
1812
return {
19-
...clone,
20-
imports: postProcessModelImports(clone),
21-
enums: postProcessModelEnums(clone),
22-
enum: postProcessModelEnum(clone),
13+
...model,
14+
imports: postProcessModelImports(model),
15+
enums: postProcessModelEnums(model),
16+
enum: postProcessModelEnum(model),
2317
};
2418
}

src/utils/postProcessService.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import { Client } from '../client/interfaces/Client';
21
import { Service } from '../client/interfaces/Service';
32
import { postProcessServiceImports } from './postProcessServiceImports';
43
import { postProcessServiceOperations } from './postProcessServiceOperations';
54

6-
export function postProcessService(service: Service, client: Client, useUnionTypes: boolean): Service {
5+
export function postProcessService(service: Service): Service {
76
const clone = { ...service };
8-
clone.operations = postProcessServiceOperations(clone, client, useUnionTypes);
7+
clone.operations = postProcessServiceOperations(clone);
98
clone.operations.forEach(operation => {
109
clone.imports.push(...operation.imports);
1110
});

src/utils/postProcessServiceOperations.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
1-
import { Client } from '../client/interfaces/Client';
21
import { Operation } from '../client/interfaces/Operation';
32
import { Service } from '../client/interfaces/Service';
43
import { flatMap } from './flatMap';
5-
import { postProcessUnionTypes } from './postProcessUnionTypes';
64

7-
export function postProcessServiceOperations(service: Service, client: Client, useUnionTypes: boolean = false): Operation[] {
5+
export function postProcessServiceOperations(service: Service): Operation[] {
86
const names = new Map<string, number>();
97

108
return service.operations.map(operation => {
119
const clone = { ...operation };
1210

1311
// Parse the service parameters and results, very similar to how we parse
1412
// properties of models. These methods will extend the type if needed.
15-
clone.parameters = clone.parameters.map(parameter => postProcessUnionTypes(parameter, client, useUnionTypes));
16-
clone.results = clone.results.map(result => postProcessUnionTypes(result, client, useUnionTypes));
1713
clone.imports.push(...flatMap(clone.parameters, parameter => parameter.imports));
1814
clone.imports.push(...flatMap(clone.results, result => result.imports));
1915

0 commit comments

Comments
 (0)