Skip to content

Commit f681016

Browse files
sarumontmacjohnny
andauthored
Fix typescript-node generation when only models are generated (#7127)
* add model/index.ts - move export of all models to model/index.ts - move RequestFile definition to model/index.ts This fixes #7126 * update samples * Back out models/index.ts Make this backwards-compatible: - move `RequestFile` definition to `model/models.ts` - remove `model/index.ts` - re-export `RequestFile` from `api/apis.ts` - make generation of `ObjectSerializer` conditional * for some reason, Symfony isn't up to date * reverts changes to php-symfony sample * moves comment to mustache comment rather than TS comment Co-authored-by: Esteban Gehring <[email protected]> * removes stale files from samples (no longer generated) * updates samples Co-authored-by: Esteban Gehring <[email protected]>
1 parent 1f95199 commit f681016

19 files changed

Lines changed: 64 additions & 47 deletions

File tree

modules/openapi-generator/src/main/resources/typescript-node/api-all.mustache

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { {{ classname }} } from './{{ classFilename }}';
88
export * from './{{ classFilename }}Interface'
99
{{/withInterfaces}}
1010
{{/apis}}
11-
import * as fs from 'fs';
1211
import * as http from 'http';
1312

1413
export class HttpError extends Error {
@@ -18,15 +17,7 @@ export class HttpError extends Error {
1817
}
1918
}
2019

21-
export interface RequestDetailedFile {
22-
value: Buffer;
23-
options?: {
24-
filename?: string;
25-
contentType?: string;
26-
}
27-
}
28-
29-
export type RequestFile = string | Buffer | fs.ReadStream | RequestDetailedFile;
20+
export { RequestFile } from '../model/models';
3021

3122
export const APIS = [{{#apis}}{{#operations}}{{ classname }}{{/operations}}{{^-last}}, {{/-last}}{{/apis}}];
3223
{{/apiInfo}}

modules/openapi-generator/src/main/resources/typescript-node/model.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{{>licenseInfo}}
22
{{#models}}
33
{{#model}}
4-
import { RequestFile } from '../api';
4+
import { RequestFile } from './models';
55
{{#tsImports}}
66
import { {{classname}} } from '{{filename}}';
77
{{/tsImports}}
@@ -78,4 +78,4 @@ export enum {{classname}} {
7878
}
7979
{{/isEnum}}
8080
{{/model}}
81-
{{/models}}
81+
{{/models}}

modules/openapi-generator/src/main/resources/typescript-node/models.mustache

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,27 @@
1+
{{#generateApis}}
2+
import localVarRequest from 'request';
3+
{{/generateApis}}
4+
15
{{#models}}
26
{{#model}}
37
export * from '{{{ classFilename }}}';
48
{{/model}}
59
{{/models}}
610

7-
import localVarRequest from 'request';
11+
import * as fs from 'fs';
12+
13+
export interface RequestDetailedFile {
14+
value: Buffer;
15+
options?: {
16+
filename?: string;
17+
contentType?: string;
18+
}
19+
}
20+
21+
export type RequestFile = string | Buffer | fs.ReadStream | RequestDetailedFile;
22+
23+
{{! Object serialization only relevant if generating APIs, too }}
24+
{{#generateApis}}
825

926
{{#models}}
1027
{{#model}}
@@ -235,3 +252,4 @@ export class VoidAuth implements Authentication {
235252
}
236253
237254
export type Interceptor = (requestOptions: localVarRequest.Options) => (Promise<void> | void);
255+
{{/generateApis}}

samples/client/petstore/typescript-node/default/api/apis.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ export * from './storeApi';
44
import { StoreApi } from './storeApi';
55
export * from './userApi';
66
import { UserApi } from './userApi';
7-
import * as fs from 'fs';
87
import * as http from 'http';
98

109
export class HttpError extends Error {
@@ -14,14 +13,6 @@ export class HttpError extends Error {
1413
}
1514
}
1615

17-
export interface RequestDetailedFile {
18-
value: Buffer;
19-
options?: {
20-
filename?: string;
21-
contentType?: string;
22-
}
23-
}
24-
25-
export type RequestFile = string | Buffer | fs.ReadStream | RequestDetailedFile;
16+
export { RequestFile } from '../model/models';
2617

2718
export const APIS = [PetApi, StoreApi, UserApi];

samples/client/petstore/typescript-node/default/model/apiResponse.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Do not edit the class manually.
1111
*/
1212

13-
import { RequestFile } from '../api';
13+
import { RequestFile } from './models';
1414

1515
/**
1616
* Describes the result of uploading an image resource

samples/client/petstore/typescript-node/default/model/category.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Do not edit the class manually.
1111
*/
1212

13-
import { RequestFile } from '../api';
13+
import { RequestFile } from './models';
1414

1515
/**
1616
* A category for a pet

samples/client/petstore/typescript-node/default/model/models.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
1+
import localVarRequest from 'request';
2+
13
export * from './apiResponse';
24
export * from './category';
35
export * from './order';
46
export * from './pet';
57
export * from './tag';
68
export * from './user';
79

8-
import localVarRequest from 'request';
10+
import * as fs from 'fs';
11+
12+
export interface RequestDetailedFile {
13+
value: Buffer;
14+
options?: {
15+
filename?: string;
16+
contentType?: string;
17+
}
18+
}
19+
20+
export type RequestFile = string | Buffer | fs.ReadStream | RequestDetailedFile;
21+
922

1023
import { ApiResponse } from './apiResponse';
1124
import { Category } from './category';

samples/client/petstore/typescript-node/default/model/order.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Do not edit the class manually.
1111
*/
1212

13-
import { RequestFile } from '../api';
13+
import { RequestFile } from './models';
1414

1515
/**
1616
* An order for a pets from the pet store

samples/client/petstore/typescript-node/default/model/pet.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Do not edit the class manually.
1111
*/
1212

13-
import { RequestFile } from '../api';
13+
import { RequestFile } from './models';
1414
import { Category } from './category';
1515
import { Tag } from './tag';
1616

samples/client/petstore/typescript-node/default/model/tag.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Do not edit the class manually.
1111
*/
1212

13-
import { RequestFile } from '../api';
13+
import { RequestFile } from './models';
1414

1515
/**
1616
* A tag for a pet

0 commit comments

Comments
 (0)