Closed
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- What's the version of OpenAPI Generator used?
- Have you search for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Bounty to sponsor the fix (example)
Description
RequestFile is defined in the api-all.mustache template, and it gets used as a special case
in the model.mustache template.
When this special case is triggered and RequestFile
is used in a model file, Typescript complains that the type is not found.
client/model/inlineObject.ts:15:16 - error TS2304: Cannot find name 'RequestFile'.
15 'myFile'?: RequestFile;
~~~~~~~~~~~
openapi-generator version
4.2.3-SNAPSHOT
OpenAPI declaration file content or url
openapi: 3.0.0
paths:
'/upload-file':
post:
requestBody:
content:
multipart/form-data:
schema:
type: object
properties:
myFile:
type: string
format: binary
Command line used for generation
$ ./run-in-docker.sh generate \
-i swagger.yaml \
-g typescript-node \
-o client \
--skip-validate-spec \
--additional-properties supportsES6=true
Steps to reproduce
- Paste the above yaml into
swagger.yaml
at the root of this openapi-generator project. - Generate the Typescript client with the command above.
- Compile the client by running:
$ npm install request typescript @types/node
$ npx tsc --target ES6 --lib esnext --module commonjs client/api.ts
Suggest a fix
Import RequestFile
into the model template.
--- 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}}