Skip to content

Commit 37c949c

Browse files
committed
fix(typescript-fetch): add anyToJSON to runtime.ts
The generated API code calls anyToJSON() for any-typed properties in form data, but the function was never defined in runtime.ts, causing a ReferenceError at runtime. Fixes #1877
1 parent 4bb04c3 commit 37c949c

24 files changed

Lines changed: 153 additions & 5 deletions

File tree

modules/openapi-generator/src/main/resources/typescript-fetch/apis.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ export class {{classname}} extends runtime.BaseAPI {
279279
{{^isEnumRef}}
280280
{{^withoutRuntimeChecks}}
281281
{{^isContainer}}
282-
formParams.append('{{baseName}}', new Blob([JSON.stringify({{{dataType}}}ToJSON(requestParameters['{{paramName}}']))], { type: "application/json", }));
282+
formParams.append('{{baseName}}', new Blob([JSON.stringify({{#isFreeFormObject}}runtime.anyToJSON{{/isFreeFormObject}}{{^isFreeFormObject}}{{{dataType}}}ToJSON{{/isFreeFormObject}}(requestParameters['{{paramName}}']))], { type: "application/json", }));
283283
{{/isContainer}}
284284
{{#isContainer}}
285285
formParams.append('{{baseName}}', new Blob([JSON.stringify(requestParameters['{{paramName}}'])], { type: "application/json", }));

modules/openapi-generator/src/main/resources/typescript-fetch/runtime.mustache

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,11 @@ export function mapValues(data: any, fn: (item: any) => any) {
357357
}
358358
return result;
359359
}
360+
361+
// Pass-through serializer for `any`-typed properties in form data. See #1877.
362+
export function anyToJSON(value: any): any {
363+
return value;
364+
}
360365
{{/withoutRuntimeChecks}}
361366

362367
export function canConsumeForm(consumes: Consume[]): boolean {
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"openapi": "3.0.1",
3+
"info": {
4+
"title": "Any Type Property Test",
5+
"version": "1.0.0"
6+
},
7+
"paths": {
8+
"/upload": {
9+
"post": {
10+
"operationId": "uploadFile",
11+
"tags": ["Upload"],
12+
"requestBody": {
13+
"content": {
14+
"application/x-www-form-urlencoded": {
15+
"schema": {
16+
"type": "object",
17+
"required": ["name"],
18+
"properties": {
19+
"name": {
20+
"type": "string"
21+
},
22+
"file": {
23+
"type": "object"
24+
}
25+
}
26+
}
27+
}
28+
}
29+
},
30+
"responses": {
31+
"200": {
32+
"description": "Success"
33+
}
34+
}
35+
}
36+
}
37+
},
38+
"components": {}
39+
}

samples/client/others/typescript-fetch/additional-properties-in-multipart-issue/runtime.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,11 @@ export function mapValues(data: any, fn: (item: any) => any) {
367367
return result;
368368
}
369369

370+
// Pass-through serializer for `any`-typed properties in form data. See #1877.
371+
export function anyToJSON(value: any): any {
372+
return value;
373+
}
374+
370375
export function canConsumeForm(consumes: Consume[]): boolean {
371376
for (const consume of consumes) {
372377
if (consume.contentType?.startsWith('multipart/form-data') == true) {

samples/client/others/typescript-fetch/infinite-recursion-issue/runtime.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,11 @@ export function mapValues(data: any, fn: (item: any) => any) {
367367
return result;
368368
}
369369

370+
// Pass-through serializer for `any`-typed properties in form data. See #1877.
371+
export function anyToJSON(value: any): any {
372+
return value;
373+
}
374+
370375
export function canConsumeForm(consumes: Consume[]): boolean {
371376
for (const consume of consumes) {
372377
if (consume.contentType?.startsWith('multipart/form-data') == true) {

samples/client/others/typescript-fetch/multipart-file-array/runtime.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,11 @@ export function mapValues(data: any, fn: (item: any) => any) {
367367
return result;
368368
}
369369

370+
// Pass-through serializer for `any`-typed properties in form data. See #1877.
371+
export function anyToJSON(value: any): any {
372+
return value;
373+
}
374+
370375
export function canConsumeForm(consumes: Consume[]): boolean {
371376
for (const consume of consumes) {
372377
if (consume.contentType?.startsWith('multipart/form-data') == true) {

samples/client/others/typescript-fetch/self-import-issue/runtime.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,11 @@ export function mapValues(data: any, fn: (item: any) => any) {
367367
return result;
368368
}
369369

370+
// Pass-through serializer for `any`-typed properties in form data. See #1877.
371+
export function anyToJSON(value: any): any {
372+
return value;
373+
}
374+
370375
export function canConsumeForm(consumes: Consume[]): boolean {
371376
for (const consume of consumes) {
372377
if (consume.contentType?.startsWith('multipart/form-data') == true) {

samples/client/petstore/typescript-fetch/builds/allOf-nullable/runtime.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,11 @@ export function mapValues(data: any, fn: (item: any) => any) {
367367
return result;
368368
}
369369

370+
// Pass-through serializer for `any`-typed properties in form data. See #1877.
371+
export function anyToJSON(value: any): any {
372+
return value;
373+
}
374+
370375
export function canConsumeForm(consumes: Consume[]): boolean {
371376
for (const consume of consumes) {
372377
if (consume.contentType?.startsWith('multipart/form-data') == true) {

samples/client/petstore/typescript-fetch/builds/allOf-readonly/runtime.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,11 @@ export function mapValues(data: any, fn: (item: any) => any) {
367367
return result;
368368
}
369369

370+
// Pass-through serializer for `any`-typed properties in form data. See #1877.
371+
export function anyToJSON(value: any): any {
372+
return value;
373+
}
374+
370375
export function canConsumeForm(consumes: Consume[]): boolean {
371376
for (const consume of consumes) {
372377
if (consume.contentType?.startsWith('multipart/form-data') == true) {

samples/client/petstore/typescript-fetch/builds/default-v3.0/runtime.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,11 @@ export function mapValues(data: any, fn: (item: any) => any) {
367367
return result;
368368
}
369369

370+
// Pass-through serializer for `any`-typed properties in form data. See #1877.
371+
export function anyToJSON(value: any): any {
372+
return value;
373+
}
374+
370375
export function canConsumeForm(consumes: Consume[]): boolean {
371376
for (const consume of consumes) {
372377
if (consume.contentType?.startsWith('multipart/form-data') == true) {

0 commit comments

Comments
 (0)