Skip to content

Commit

Permalink
Fix typescript-node generation when only models are generated (#7127)
Browse files Browse the repository at this point in the history
* 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 <esteban.gehring@gmail.com>

* removes stale files from samples (no longer generated)

* updates samples

Co-authored-by: Esteban Gehring <esteban.gehring@gmail.com>
  • Loading branch information
sarumont and macjohnny authored Aug 28, 2020
1 parent 1f95199 commit f681016
Show file tree
Hide file tree
Showing 19 changed files with 64 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { {{ classname }} } from './{{ classFilename }}';
export * from './{{ classFilename }}Interface'
{{/withInterfaces}}
{{/apis}}
import * as fs from 'fs';
import * as http from 'http';

export class HttpError extends Error {
Expand All @@ -18,15 +17,7 @@ export class HttpError extends Error {
}
}

export interface RequestDetailedFile {
value: Buffer;
options?: {
filename?: string;
contentType?: string;
}
}

export type RequestFile = string | Buffer | fs.ReadStream | RequestDetailedFile;
export { RequestFile } from '../model/models';

export const APIS = [{{#apis}}{{#operations}}{{ classname }}{{/operations}}{{^-last}}, {{/-last}}{{/apis}}];
{{/apiInfo}}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{>licenseInfo}}
{{#models}}
{{#model}}
import { RequestFile } from '../api';
import { RequestFile } from './models';
{{#tsImports}}
import { {{classname}} } from '{{filename}}';
{{/tsImports}}
Expand Down Expand Up @@ -78,4 +78,4 @@ export enum {{classname}} {
}
{{/isEnum}}
{{/model}}
{{/models}}
{{/models}}
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
{{#generateApis}}
import localVarRequest from 'request';
{{/generateApis}}

{{#models}}
{{#model}}
export * from '{{{ classFilename }}}';
{{/model}}
{{/models}}

import localVarRequest from 'request';
import * as fs from 'fs';

export interface RequestDetailedFile {
value: Buffer;
options?: {
filename?: string;
contentType?: string;
}
}

export type RequestFile = string | Buffer | fs.ReadStream | RequestDetailedFile;

{{! Object serialization only relevant if generating APIs, too }}
{{#generateApis}}

{{#models}}
{{#model}}
Expand Down Expand Up @@ -235,3 +252,4 @@ export class VoidAuth implements Authentication {
}
export type Interceptor = (requestOptions: localVarRequest.Options) => (Promise<void> | void);
{{/generateApis}}
11 changes: 1 addition & 10 deletions samples/client/petstore/typescript-node/default/api/apis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ export * from './storeApi';
import { StoreApi } from './storeApi';
export * from './userApi';
import { UserApi } from './userApi';
import * as fs from 'fs';
import * as http from 'http';

export class HttpError extends Error {
Expand All @@ -14,14 +13,6 @@ export class HttpError extends Error {
}
}

export interface RequestDetailedFile {
value: Buffer;
options?: {
filename?: string;
contentType?: string;
}
}

export type RequestFile = string | Buffer | fs.ReadStream | RequestDetailedFile;
export { RequestFile } from '../model/models';

export const APIS = [PetApi, StoreApi, UserApi];
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Do not edit the class manually.
*/

import { RequestFile } from '../api';
import { RequestFile } from './models';

/**
* Describes the result of uploading an image resource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Do not edit the class manually.
*/

import { RequestFile } from '../api';
import { RequestFile } from './models';

/**
* A category for a pet
Expand Down
15 changes: 14 additions & 1 deletion samples/client/petstore/typescript-node/default/model/models.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
import localVarRequest from 'request';

export * from './apiResponse';
export * from './category';
export * from './order';
export * from './pet';
export * from './tag';
export * from './user';

import localVarRequest from 'request';
import * as fs from 'fs';

export interface RequestDetailedFile {
value: Buffer;
options?: {
filename?: string;
contentType?: string;
}
}

export type RequestFile = string | Buffer | fs.ReadStream | RequestDetailedFile;


import { ApiResponse } from './apiResponse';
import { Category } from './category';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Do not edit the class manually.
*/

import { RequestFile } from '../api';
import { RequestFile } from './models';

/**
* An order for a pets from the pet store
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Do not edit the class manually.
*/

import { RequestFile } from '../api';
import { RequestFile } from './models';
import { Category } from './category';
import { Tag } from './tag';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Do not edit the class manually.
*/

import { RequestFile } from '../api';
import { RequestFile } from './models';

/**
* A tag for a pet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Do not edit the class manually.
*/

import { RequestFile } from '../api';
import { RequestFile } from './models';

/**
* A User who is purchasing from the pet store
Expand Down
11 changes: 1 addition & 10 deletions samples/client/petstore/typescript-node/npm/api/apis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ export * from './storeApi';
import { StoreApi } from './storeApi';
export * from './userApi';
import { UserApi } from './userApi';
import * as fs from 'fs';
import * as http from 'http';

export class HttpError extends Error {
Expand All @@ -14,14 +13,6 @@ export class HttpError extends Error {
}
}

export interface RequestDetailedFile {
value: Buffer;
options?: {
filename?: string;
contentType?: string;
}
}

export type RequestFile = string | Buffer | fs.ReadStream | RequestDetailedFile;
export { RequestFile } from '../model/models';

export const APIS = [PetApi, StoreApi, UserApi];
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Do not edit the class manually.
*/

import { RequestFile } from '../api';
import { RequestFile } from './models';

/**
* Describes the result of uploading an image resource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Do not edit the class manually.
*/

import { RequestFile } from '../api';
import { RequestFile } from './models';

/**
* A category for a pet
Expand Down
15 changes: 14 additions & 1 deletion samples/client/petstore/typescript-node/npm/model/models.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
import localVarRequest from 'request';

export * from './apiResponse';
export * from './category';
export * from './order';
export * from './pet';
export * from './tag';
export * from './user';

import localVarRequest from 'request';
import * as fs from 'fs';

export interface RequestDetailedFile {
value: Buffer;
options?: {
filename?: string;
contentType?: string;
}
}

export type RequestFile = string | Buffer | fs.ReadStream | RequestDetailedFile;


import { ApiResponse } from './apiResponse';
import { Category } from './category';
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/typescript-node/npm/model/order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Do not edit the class manually.
*/

import { RequestFile } from '../api';
import { RequestFile } from './models';

/**
* An order for a pets from the pet store
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/typescript-node/npm/model/pet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Do not edit the class manually.
*/

import { RequestFile } from '../api';
import { RequestFile } from './models';
import { Category } from './category';
import { Tag } from './tag';

Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/typescript-node/npm/model/tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Do not edit the class manually.
*/

import { RequestFile } from '../api';
import { RequestFile } from './models';

/**
* A tag for a pet
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/typescript-node/npm/model/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Do not edit the class manually.
*/

import { RequestFile } from '../api';
import { RequestFile } from './models';

/**
* A User who is purchasing from the pet store
Expand Down

0 comments on commit f681016

Please sign in to comment.