From d51354783f8bac382d5e8f3f1c4ed38f5ad73af4 Mon Sep 17 00:00:00 2001 From: Ryan N Johnson Date: Mon, 6 Jan 2020 09:09:56 +0000 Subject: [PATCH] Add RequestFile to typescript-node model template (#4903) RequestFile is defined in the [api-all.mustache template](https://github.com/OpenAPITools/openapi-generator/blob/ac4ead9e7805d4dc89d791376539496a57c49df7/modules/openapi-generator/src/main/resources/typescript-node/api-all.mustache#L29), and it gets used [as a special case](https://github.com/OpenAPITools/openapi-generator/blob/ac4ead9e7805d4dc89d791376539496a57c49df7/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptNodeClientCodegen.java#L92) [in the model.mustache template](https://github.com/OpenAPITools/openapi-generator/blob/ac4ead9e7805d4dc89d791376539496a57c49df7/modules/openapi-generator/src/main/resources/typescript-node/model.mustache#L21). When this special case is triggered and `RequestFile` is used in a model file, Typescript complains that the type is not found. ``` TSError: Unable to compile TypeScript: path/to/model.ts:15:16 - error TS2304: Cannot find name 'RequestFile'. 15 'myFile'?: RequestFile; ~~~~~~~~~~~ ``` This solution is to import `RequestFile` by adding it to the model template. Here is an openapi schema that would trigger this use-case: ```yaml openapi: 3.0.0 components: schemas: IUploadMyFileBody: type: object properties: myFile: type: string format: binary ``` --- .../src/main/resources/typescript-node/model.mustache | 1 + .../client/petstore/typescript-node/default/model/apiResponse.ts | 1 + .../client/petstore/typescript-node/default/model/category.ts | 1 + samples/client/petstore/typescript-node/default/model/order.ts | 1 + samples/client/petstore/typescript-node/default/model/pet.ts | 1 + samples/client/petstore/typescript-node/default/model/tag.ts | 1 + samples/client/petstore/typescript-node/default/model/user.ts | 1 + samples/client/petstore/typescript-node/npm/model/apiResponse.ts | 1 + samples/client/petstore/typescript-node/npm/model/category.ts | 1 + samples/client/petstore/typescript-node/npm/model/order.ts | 1 + samples/client/petstore/typescript-node/npm/model/pet.ts | 1 + samples/client/petstore/typescript-node/npm/model/tag.ts | 1 + samples/client/petstore/typescript-node/npm/model/user.ts | 1 + 13 files changed, 13 insertions(+) diff --git a/modules/openapi-generator/src/main/resources/typescript-node/model.mustache b/modules/openapi-generator/src/main/resources/typescript-node/model.mustache index c3b8119ec68..521bce34d76 100644 --- a/modules/openapi-generator/src/main/resources/typescript-node/model.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-node/model.mustache @@ -1,6 +1,7 @@ {{>licenseInfo}} {{#models}} {{#model}} +import { RequestFile } from '../api'; {{#tsImports}} import { {{classname}} } from '{{filename}}'; {{/tsImports}} diff --git a/samples/client/petstore/typescript-node/default/model/apiResponse.ts b/samples/client/petstore/typescript-node/default/model/apiResponse.ts index 6db6f9b977a..ae84669a842 100644 --- a/samples/client/petstore/typescript-node/default/model/apiResponse.ts +++ b/samples/client/petstore/typescript-node/default/model/apiResponse.ts @@ -10,6 +10,7 @@ * Do not edit the class manually. */ +import { RequestFile } from '../api'; /** * Describes the result of uploading an image resource diff --git a/samples/client/petstore/typescript-node/default/model/category.ts b/samples/client/petstore/typescript-node/default/model/category.ts index 0669499c9f4..1babd0fd22e 100644 --- a/samples/client/petstore/typescript-node/default/model/category.ts +++ b/samples/client/petstore/typescript-node/default/model/category.ts @@ -10,6 +10,7 @@ * Do not edit the class manually. */ +import { RequestFile } from '../api'; /** * A category for a pet diff --git a/samples/client/petstore/typescript-node/default/model/order.ts b/samples/client/petstore/typescript-node/default/model/order.ts index 04d5cd55966..1ee3ea280c6 100644 --- a/samples/client/petstore/typescript-node/default/model/order.ts +++ b/samples/client/petstore/typescript-node/default/model/order.ts @@ -10,6 +10,7 @@ * Do not edit the class manually. */ +import { RequestFile } from '../api'; /** * An order for a pets from the pet store diff --git a/samples/client/petstore/typescript-node/default/model/pet.ts b/samples/client/petstore/typescript-node/default/model/pet.ts index e886df8d45e..141c4ebc17c 100644 --- a/samples/client/petstore/typescript-node/default/model/pet.ts +++ b/samples/client/petstore/typescript-node/default/model/pet.ts @@ -10,6 +10,7 @@ * Do not edit the class manually. */ +import { RequestFile } from '../api'; import { Category } from './category'; import { Tag } from './tag'; diff --git a/samples/client/petstore/typescript-node/default/model/tag.ts b/samples/client/petstore/typescript-node/default/model/tag.ts index 5c828c76b5b..96e644974ef 100644 --- a/samples/client/petstore/typescript-node/default/model/tag.ts +++ b/samples/client/petstore/typescript-node/default/model/tag.ts @@ -10,6 +10,7 @@ * Do not edit the class manually. */ +import { RequestFile } from '../api'; /** * A tag for a pet diff --git a/samples/client/petstore/typescript-node/default/model/user.ts b/samples/client/petstore/typescript-node/default/model/user.ts index 88d15c25f85..62b0b643689 100644 --- a/samples/client/petstore/typescript-node/default/model/user.ts +++ b/samples/client/petstore/typescript-node/default/model/user.ts @@ -10,6 +10,7 @@ * Do not edit the class manually. */ +import { RequestFile } from '../api'; /** * A User who is purchasing from the pet store diff --git a/samples/client/petstore/typescript-node/npm/model/apiResponse.ts b/samples/client/petstore/typescript-node/npm/model/apiResponse.ts index 6db6f9b977a..ae84669a842 100644 --- a/samples/client/petstore/typescript-node/npm/model/apiResponse.ts +++ b/samples/client/petstore/typescript-node/npm/model/apiResponse.ts @@ -10,6 +10,7 @@ * Do not edit the class manually. */ +import { RequestFile } from '../api'; /** * Describes the result of uploading an image resource diff --git a/samples/client/petstore/typescript-node/npm/model/category.ts b/samples/client/petstore/typescript-node/npm/model/category.ts index 0669499c9f4..1babd0fd22e 100644 --- a/samples/client/petstore/typescript-node/npm/model/category.ts +++ b/samples/client/petstore/typescript-node/npm/model/category.ts @@ -10,6 +10,7 @@ * Do not edit the class manually. */ +import { RequestFile } from '../api'; /** * A category for a pet diff --git a/samples/client/petstore/typescript-node/npm/model/order.ts b/samples/client/petstore/typescript-node/npm/model/order.ts index 04d5cd55966..1ee3ea280c6 100644 --- a/samples/client/petstore/typescript-node/npm/model/order.ts +++ b/samples/client/petstore/typescript-node/npm/model/order.ts @@ -10,6 +10,7 @@ * Do not edit the class manually. */ +import { RequestFile } from '../api'; /** * An order for a pets from the pet store diff --git a/samples/client/petstore/typescript-node/npm/model/pet.ts b/samples/client/petstore/typescript-node/npm/model/pet.ts index e886df8d45e..141c4ebc17c 100644 --- a/samples/client/petstore/typescript-node/npm/model/pet.ts +++ b/samples/client/petstore/typescript-node/npm/model/pet.ts @@ -10,6 +10,7 @@ * Do not edit the class manually. */ +import { RequestFile } from '../api'; import { Category } from './category'; import { Tag } from './tag'; diff --git a/samples/client/petstore/typescript-node/npm/model/tag.ts b/samples/client/petstore/typescript-node/npm/model/tag.ts index 5c828c76b5b..96e644974ef 100644 --- a/samples/client/petstore/typescript-node/npm/model/tag.ts +++ b/samples/client/petstore/typescript-node/npm/model/tag.ts @@ -10,6 +10,7 @@ * Do not edit the class manually. */ +import { RequestFile } from '../api'; /** * A tag for a pet diff --git a/samples/client/petstore/typescript-node/npm/model/user.ts b/samples/client/petstore/typescript-node/npm/model/user.ts index 88d15c25f85..62b0b643689 100644 --- a/samples/client/petstore/typescript-node/npm/model/user.ts +++ b/samples/client/petstore/typescript-node/npm/model/user.ts @@ -10,6 +10,7 @@ * Do not edit the class manually. */ +import { RequestFile } from '../api'; /** * A User who is purchasing from the pet store