Skip to content
Merged
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 @@ -1174,14 +1174,13 @@ public Map<String, ModelsMap> postProcessAllModels(Map<String, ModelsMap> objs)
codegenModel.getImports().add(imp);
}
}

if (property.required) {
codegenModel.parentRequiredVars.add(parentVar.clone());
}
}
}
parentCodegenModel = parentCodegenModel.getParentModel();
}
if (codegenModel.getParentModel() != null) {
codegenModel.parentRequiredVars = new ArrayList<>(codegenModel.getParentModel().requiredVars);
}
// There must be a better way ...
for (String imp: inheritedImports) {
String qimp = importMapping().get(imp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@
import io.swagger.v3.oas.models.servers.Server;
import io.swagger.v3.parser.core.models.ParseOptions;
import org.openapitools.codegen.*;
import org.openapitools.codegen.config.CodegenConfigurator;
import org.openapitools.codegen.config.GlobalSettings;
import org.openapitools.codegen.java.assertions.JavaFileAssert;
import org.openapitools.codegen.languages.AbstractJavaCodegen;
import org.openapitools.codegen.languages.JavaClientCodegen;
import org.openapitools.codegen.languages.SpringCodegen;
import org.openapitools.codegen.languages.features.BeanValidationFeatures;
import org.openapitools.codegen.languages.features.CXFServerFeatures;
Expand Down Expand Up @@ -388,6 +390,46 @@ public void shouldGenerateRequestParamForRefParams_3248_RegressionDates() throws
.containsWithNameAndAttributes("DateTimeFormat", ImmutableMap.of("iso", "DateTimeFormat.ISO.DATE_TIME"));
}

@Test
public void testJavaClientCorrectConstructorOrderForRequiredFields_issue15825() throws IOException {
Map<String, Object> properties = new HashMap<>();
properties.put(JavaClientCodegen.MICROPROFILE_REST_CLIENT_VERSION, "3.0");

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

final CodegenConfigurator configurator = new CodegenConfigurator()
.setAdditionalProperties(properties)
.setGeneratorName("spring")
.setLibrary(SPRING_BOOT)
.setInputSpec("src/test/resources/bugs/issue_constructor-required-values-with-multiple-inheritance.yaml")
.setOutputDir(output.getAbsolutePath().replace("\\", "/"));

final ClientOptInput clientOptInput = configurator.toClientOptInput();
DefaultGenerator generator = new DefaultGenerator();
Map<String, File> files = generator.opts(clientOptInput).generate().stream()
.collect(Collectors.toMap(File::getName, Function.identity()));

JavaFileAssert.assertThat(files.get("SubType.java"))
.assertConstructor("TypeEnum", "SchemaVersion", "UUID", "Boolean", "Boolean", "SomeEnum")
.bodyContainsLines("super(someBoolean, someEnum, schemaVersion, id, oneBoolean);",
"this.type = type;");
JavaFileAssert.assertThat(files.get("IntermediateSubType.java"))
.assertConstructor("Boolean", "SomeEnum", "SchemaVersion", "UUID", "Boolean")
.bodyContainsLines("super(oneBoolean, schemaVersion, id);",
"this.someBoolean = someBoolean;",
"this.someEnum = someEnum");
JavaFileAssert.assertThat(files.get("IntermediateType.java"))
.assertConstructor("Boolean", "SchemaVersion", "UUID")
.bodyContainsLines("super(schemaVersion, id);",
"this.oneBoolean = oneBoolean;");
JavaFileAssert.assertThat(files.get("BaseType.java"))
.assertConstructor("SchemaVersion", "UUID")
.bodyContainsLines(
"this.schemaVersion = schemaVersion;",
"this.id = id;");
}

@Test
public void springcloudWithAsyncAndJava8HasResponseWrapperCompletableFuture() {
final SpringCodegen codegen = new SpringCodegen();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
---
openapi: 3.0.2
info:
version: 0.0.0
title: Wrong Constructor

paths: {}

components:

schemas:
BaseType:
type: object
required:
- schemaVersion
- id
properties:
schemaVersion:
$ref: "#/components/schemas/SchemaVersion"
id:
type: string
format: "uuid"
freeTextField:
type: array
default: [ ]
minItems: 0
maxItems: 6
items:
type: string
maxLength: 255
discriminator:
propertyName: type
mapping:
SubType: "#/components/schemas/SubType"


IntermediateType:
allOf:
- $ref: "#/components/schemas/BaseType"
- type: object
required:
- OneBoolean
properties:
OneBoolean:
type: boolean
default: false
OneOptionalBoolean:
type: boolean
default: false

IntermediateSubType:
allOf:
- $ref: "#/components/schemas/IntermediateType"
- type: object
required:
- someBoolean
- someEnum
properties:
someBoolean:
type: boolean
default: false
someEnum:
$ref: "#/components/schemas/SomeEnum"

SubType:
allOf:
- $ref: "#/components/schemas/IntermediateSubType"
- type: object
properties:
type:
type: string
default: "SubType"
enum: [ "SubType" ]
required:
- type


SomeEnum:
type: string
enum:
- LIT1
- LIT2
x-enum-varnames:
- Literal1
- Literal2


SchemaVersion:
type: string
default: "1.0.0"
x-enum-varnames:
- CURRENT
enum:
- "1.0.0"