Bug Report Checklist
Description
A multipart/form-data parameter that has no type at all ("any type") makes typescript-fetch
emit a call to a bare anyToJSON(...). The generated apis/*.ts only imports the runtime as
* as runtime, so that identifier does not exist and the generated code does not compile.
The free-form-object case is already handled — runtime.anyToJSON — but the any-type case falls through
to {{dataType}}ToJSON, and for an any-typed parameter dataType is any, so it renders as anyToJSON.
openapi-generator version
7.25.0-SNAPSHOT, built from master at commit 4aed9c1c635.
OpenAPI declaration file content or url
openapi: 3.0.3
info: { title: t, version: 1.0.0 }
paths:
/upload:
post:
operationId: upload
requestBody:
content:
multipart/form-data:
schema:
type: object
properties:
file: { type: string, format: binary }
meta: { description: can be any type } # no type -> "any type"
responses: { "200": { description: ok } }
Generation Details
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate \
-i spec.yaml -g typescript-fetch -o out
Steps to reproduce
- Save the spec above as
spec.yaml
- Run the command above
- Look at
out/apis/DefaultApi.ts
Actual output
import * as runtime from '../runtime';
...
formParams.append('meta', new Blob([JSON.stringify(anyToJSON(requestParameters['meta']))], { type: "application/json", }));
// ^^^^^^^^^ not imported, not defined
tsc fails with TS2304: Cannot find name 'anyToJSON'.
Expected output
formParams.append('meta', new Blob([JSON.stringify(runtime.anyToJSON(requestParameters['meta']))], { type: "application/json", }));
anyToJSON is exported by runtime.ts (added in #1877) and is already referenced correctly for
free-form objects; only the any-type branch is missing the namespace qualifier.
Suggest a fix
https://github.com/OpenAPITools/openapi-generator/blob/4aed9c1c635/modules/openapi-generator/src/main/resources/typescript-fetch/apis.mustache#L288
{{#isFreeFormObject}}runtime.anyToJSON{{/isFreeFormObject}}{{^isFreeFormObject}}{{{dataType}}}ToJSON{{/isFreeFormObject}}
Adding an isAnyType branch that also uses runtime.anyToJSON fixes it.
I have a patch with a regression test ready and will open a PR shortly.
Related issues/PRs
#1877 added anyToJSON and the isFreeFormObject branch. I could not find an existing report covering the
any-type case.
Bug Report Checklist
Description
A
multipart/form-dataparameter that has no type at all ("any type") makestypescript-fetchemit a call to a bare
anyToJSON(...). The generatedapis/*.tsonly imports the runtime as* as runtime, so that identifier does not exist and the generated code does not compile.The free-form-object case is already handled —
runtime.anyToJSON— but the any-type case falls throughto
{{dataType}}ToJSON, and for an any-typed parameterdataTypeisany, so it renders asanyToJSON.openapi-generator version
7.25.0-SNAPSHOT, built frommasterat commit4aed9c1c635.OpenAPI declaration file content or url
Generation Details
Steps to reproduce
spec.yamlout/apis/DefaultApi.tsActual output
tscfails withTS2304: Cannot find name 'anyToJSON'.Expected output
anyToJSONis exported byruntime.ts(added in #1877) and is already referenced correctly forfree-form objects; only the any-type branch is missing the namespace qualifier.
Suggest a fix
https://github.com/OpenAPITools/openapi-generator/blob/4aed9c1c635/modules/openapi-generator/src/main/resources/typescript-fetch/apis.mustache#L288
Adding an
isAnyTypebranch that also usesruntime.anyToJSONfixes it.I have a patch with a regression test ready and will open a PR shortly.
Related issues/PRs
#1877 added
anyToJSONand theisFreeFormObjectbranch. I could not find an existing report covering theany-type case.