Add RequestFile to typescript-node model template (#4903)

RequestFile is defined in the [api-all.mustache
template](ac4ead9e78/modules/openapi-generator/src/main/resources/typescript-node/api-all.mustache (L29)),
and it gets used [as a special
case](ac4ead9e78/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptNodeClientCodegen.java (L92))
[in the model.mustache
template](ac4ead9e78/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
```
This commit is contained in:
Ryan N Johnson 2020-01-06 09:09:56 +00:00 committed by Esteban Gehring
parent ec1e9a4c9b
commit d51354783f
13 changed files with 13 additions and 0 deletions

View File

@ -1,6 +1,7 @@
{{>licenseInfo}}
{{#models}}
{{#model}}
import { RequestFile } from '../api';
{{#tsImports}}
import { {{classname}} } from '{{filename}}';
{{/tsImports}}

View File

@ -10,6 +10,7 @@
* Do not edit the class manually.
*/
import { RequestFile } from '../api';
/**
* Describes the result of uploading an image resource

View File

@ -10,6 +10,7 @@
* Do not edit the class manually.
*/
import { RequestFile } from '../api';
/**
* A category for a pet

View File

@ -10,6 +10,7 @@
* Do not edit the class manually.
*/
import { RequestFile } from '../api';
/**
* An order for a pets from the pet store

View File

@ -10,6 +10,7 @@
* Do not edit the class manually.
*/
import { RequestFile } from '../api';
import { Category } from './category';
import { Tag } from './tag';

View File

@ -10,6 +10,7 @@
* Do not edit the class manually.
*/
import { RequestFile } from '../api';
/**
* A tag for a pet

View File

@ -10,6 +10,7 @@
* Do not edit the class manually.
*/
import { RequestFile } from '../api';
/**
* A User who is purchasing from the pet store

View File

@ -10,6 +10,7 @@
* Do not edit the class manually.
*/
import { RequestFile } from '../api';
/**
* Describes the result of uploading an image resource

View File

@ -10,6 +10,7 @@
* Do not edit the class manually.
*/
import { RequestFile } from '../api';
/**
* A category for a pet

View File

@ -10,6 +10,7 @@
* Do not edit the class manually.
*/
import { RequestFile } from '../api';
/**
* An order for a pets from the pet store

View File

@ -10,6 +10,7 @@
* Do not edit the class manually.
*/
import { RequestFile } from '../api';
import { Category } from './category';
import { Tag } from './tag';

View File

@ -10,6 +10,7 @@
* Do not edit the class manually.
*/
import { RequestFile } from '../api';
/**
* A tag for a pet

View File

@ -10,6 +10,7 @@
* Do not edit the class manually.
*/
import { RequestFile } from '../api';
/**
* A User who is purchasing from the pet store