Skip to content
Closed
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
@@ -1,2 +1,2 @@
{{#isFormParam}}
{{#isDeprecated}}@Deprecated {{/isDeprecated}}{{^isFile}}@FormParam(value = "{{baseName}}") {{{dataType}}} {{paramName}}{{/isFile}}{{#isFile}}@FormParam(value = "{{baseName}}") InputStream {{paramName}}InputStream{{/isFile}}{{/isFormParam}}
{{#isDeprecated}}@Deprecated {{/isDeprecated}}{{^isFile}}@FormParam(value = "{{baseName}}") {{{dataType}}} {{paramName}}{{/isFile}}{{#isFile}}{{^isArray}}@FormParam(value = "{{baseName}}") InputStream {{paramName}}InputStream{{/isArray}}{{#isArray}}@FormParam(value = "{{baseName}}") List<InputStream> {{paramName}}InputStream{{/isArray}}{{/isFile}}{{/isFormParam}}
Original file line number Diff line number Diff line change
Expand Up @@ -2424,4 +2424,54 @@ public void generatesEmailAnnotationOnQueryParameterWhenBeanValidationEnabled()
assertFileContains(api, "import javax.validation.constraints.*;");
assertFileContains(api, "@QueryParam(\"email\")", "@Email", "String email");
}

/**
* An array of binary form properties must keep its array dimension. Previously the array was
* collapsed onto the scalar file type, generating the same signature as a single-file upload.
*/
@Test
public void testMultipartFileArrayIsGeneratedAsList() throws IOException {
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
output.deleteOnExit();
String outputPath = output.getAbsolutePath().replace('\\', '/');

final CodegenConfigurator configurator = new CodegenConfigurator()
.setGeneratorName("jaxrs-spec")
.setInputSpec("src/test/resources/3_0/form-multipart-binary-array.yaml")
.setOutputDir(outputPath);

DefaultGenerator generator = new DefaultGenerator(false);
List<File> files = generator.opts(configurator.toClientOptInput()).generate();
validateJavaSourceFiles(files);

assertFileContains(Paths.get(outputPath + "/src/gen/java/org/openapitools/api/MultipartArrayApi.java"),
"@FormParam(value = \"files\") List<InputStream> filesInputStream");
// a single binary property is still bound to a scalar InputStream
assertFileContains(Paths.get(outputPath + "/src/gen/java/org/openapitools/api/MultipartSingleApi.java"),
"@FormParam(value = \"file\") InputStream _fileInputStream");
}

/** The array dimension is preserved for every library, including quarkus. */
@Test
public void testMultipartFileArrayIsGeneratedAsListForQuarkus() throws IOException {
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
output.deleteOnExit();
String outputPath = output.getAbsolutePath().replace('\\', '/');

final CodegenConfigurator configurator = new CodegenConfigurator()
.setGeneratorName("jaxrs-spec")
.setLibrary(QUARKUS_LIBRARY)
.setInputSpec("src/test/resources/3_0/form-multipart-binary-array.yaml")
.setOutputDir(outputPath);

DefaultGenerator generator = new DefaultGenerator(false);
List<File> files = generator.opts(configurator.toClientOptInput()).generate();
validateJavaSourceFiles(files);

assertFileContains(Paths.get(outputPath + "/src/gen/java/org/openapitools/api/MultipartArrayApi.java"),
"@FormParam(value = \"files\") List<InputStream> filesInputStream");
// a single binary property is still bound to a scalar InputStream
assertFileContains(Paths.get(outputPath + "/src/gen/java/org/openapitools/api/MultipartSingleApi.java"),
"@FormParam(value = \"file\") InputStream _fileInputStream");
}
}
Loading