forked from loafle/openapi-generator-original
Array default value requires import of java.util.Arrays (#16246)
This commit is contained in:
parent
c3c0188bf4
commit
a9a4aa4bf8
@ -1473,6 +1473,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
|||||||
|
|
||||||
if ("array".equals(property.containerType)) {
|
if ("array".equals(property.containerType)) {
|
||||||
model.imports.add("ArrayList");
|
model.imports.add("ArrayList");
|
||||||
|
model.imports.add("Arrays");
|
||||||
} else if ("set".equals(property.containerType)) {
|
} else if ("set".equals(property.containerType)) {
|
||||||
model.imports.add("LinkedHashSet");
|
model.imports.add("LinkedHashSet");
|
||||||
boolean canNotBeWrappedToNullable = !openApiNullable || !property.isNullable;
|
boolean canNotBeWrappedToNullable = !openApiNullable || !property.isNullable;
|
||||||
|
@ -251,6 +251,33 @@ public class JavaJAXRSSpecServerCodegenTest extends JavaJaxrsBaseTest {
|
|||||||
output.deleteOnExit();
|
output.deleteOnExit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGeneratePingDefaultArrayValue() throws Exception {
|
||||||
|
Map<String, Object> properties = new HashMap<>();
|
||||||
|
|
||||||
|
File output = Files.createTempDirectory("test").toFile();
|
||||||
|
|
||||||
|
final CodegenConfigurator configurator = new CodegenConfigurator()
|
||||||
|
.setGeneratorName("jaxrs-spec")
|
||||||
|
.setAdditionalProperties(properties)
|
||||||
|
.setInputSpec("src/test/resources/3_0/ping-array-default.yaml")
|
||||||
|
.setOutputDir(output.getAbsolutePath().replace("\\", "/"));
|
||||||
|
|
||||||
|
final ClientOptInput clientOptInput = configurator.toClientOptInput();
|
||||||
|
DefaultGenerator generator = new DefaultGenerator();
|
||||||
|
List<File> files = generator.opts(clientOptInput).generate();
|
||||||
|
|
||||||
|
validateJavaSourceFiles(files);
|
||||||
|
|
||||||
|
TestUtils.ensureContainsFile(files, output, "src/main/openapi/openapi.yaml");
|
||||||
|
|
||||||
|
Path path = Paths.get(output.toPath() + "/src/gen/java/org/openapitools/model/AnArrayOfString.java");
|
||||||
|
|
||||||
|
assertFileContains(path , "\nimport java.util.Arrays;\n");
|
||||||
|
|
||||||
|
output.deleteOnExit();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGeneratePingNoSpecFile() throws Exception {
|
public void testGeneratePingNoSpecFile() throws Exception {
|
||||||
Map<String, Object> properties = new HashMap<>();
|
Map<String, Object> properties = new HashMap<>();
|
||||||
|
@ -0,0 +1,28 @@
|
|||||||
|
openapi: 3.0.1
|
||||||
|
info:
|
||||||
|
title: ping test
|
||||||
|
version: '1.0'
|
||||||
|
servers:
|
||||||
|
- url: 'http://localhost:8000/'
|
||||||
|
paths:
|
||||||
|
/ping:
|
||||||
|
get:
|
||||||
|
operationId: pingGet
|
||||||
|
responses:
|
||||||
|
'201':
|
||||||
|
description: OK
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: "#/components/schemas/AnArrayOfString"
|
||||||
|
components:
|
||||||
|
schemas:
|
||||||
|
AnArrayOfString:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
arrayWithADefaultValue:
|
||||||
|
default:
|
||||||
|
- aString
|
||||||
|
items:
|
||||||
|
type: string
|
||||||
|
type: array
|
Loading…
x
Reference in New Issue
Block a user