Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ export class {{classname}} extends runtime.BaseAPI {
{{^isEnumRef}}
{{^withoutRuntimeChecks}}
{{^isContainer}}
formParams.append('{{baseName}}', new Blob([JSON.stringify({{#isFreeFormObject}}runtime.anyToJSON{{/isFreeFormObject}}{{^isFreeFormObject}}{{{dataType}}}ToJSON{{/isFreeFormObject}}(requestParameters['{{paramName}}']))], { type: "application/json", }));
formParams.append('{{baseName}}', new Blob([JSON.stringify({{#isFreeFormObject}}runtime.anyToJSON{{/isFreeFormObject}}{{^isFreeFormObject}}{{#isAnyType}}runtime.anyToJSON{{/isAnyType}}{{^isAnyType}}{{{dataType}}}ToJSON{{/isAnyType}}{{/isFreeFormObject}}(requestParameters['{{paramName}}']))], { type: "application/json", }));
{{/isContainer}}
{{#isContainer}}
formParams.append('{{baseName}}', new Blob([JSON.stringify(requestParameters['{{paramName}}'])], { type: "application/json", }));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,32 @@ public void testOptionalResponseImports() {
Assert.assertEquals(operation.isResponseOptional, true);
}

@Test
public void testAnyTypeFormParamUsesQualifiedAnyToJSON() throws IOException {
// A form parameter with no type at all is "any type", not a free-form object. dataType is
// `any`, so `{{dataType}}ToJSON` renders as a bare `anyToJSON` -- but apis.ts only imports
// the runtime as `* as runtime`, so that identifier does not exist and the output does not
// compile. anyToJSON has to be referenced through the runtime namespace, the same way the
// free-form object case already does.
final String specPath = "src/test/resources/3_0/typescript-fetch/any-type-form-param.yaml";

File output = Files.createTempDirectory("test").toFile();
output.deleteOnExit();

final CodegenConfigurator configurator = new CodegenConfigurator()
.setGeneratorName("typescript-fetch")
.setInputSpec(specPath)
.setOutputDir(output.getAbsolutePath().replace("\\", "/"));

Generator generator = new DefaultGenerator();
List<File> files = generator.opts(configurator.toClientOptInput()).generate();
files.forEach(File::deleteOnExit);

Path api = Paths.get(output + "/apis/DefaultApi.ts");
TestUtils.assertFileContains(api, "runtime.anyToJSON(requestParameters['meta'])");
TestUtils.assertFileNotContains(api, "JSON.stringify(anyToJSON(");
}

@Test
public void testModelsWithoutPaths() throws IOException {
final String specPath = "src/test/resources/3_1/reusable-components-without-paths.yaml";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
openapi: 3.0.3
info:
title: any-typed multipart form parameter
version: 1.0.0
paths:
/upload:
post:
operationId: upload
requestBody:
content:
multipart/form-data:
schema:
type: object
properties:
file:
type: string
format: binary
# no type at all -> "any type", not a free-form object
meta:
description: can be any type
responses:
"200":
description: ok
Loading