diff --git a/openapi-generator/src/main/java/io/micronaut/openapi/generator/AbstractMicronautJavaCodegen.java b/openapi-generator/src/main/java/io/micronaut/openapi/generator/AbstractMicronautJavaCodegen.java index e6af87665e..76cbcef7ee 100644 --- a/openapi-generator/src/main/java/io/micronaut/openapi/generator/AbstractMicronautJavaCodegen.java +++ b/openapi-generator/src/main/java/io/micronaut/openapi/generator/AbstractMicronautJavaCodegen.java @@ -879,8 +879,9 @@ public Map postProcessAllModels(Map objs) var hasParent = model.getParentModel() != null; var requiredVarsWithoutDiscriminator = new ArrayList(); var requiredParentVarsWithoutDiscriminator = new ArrayList(); + var allVars = new ArrayList(); - processParentModel(model, requiredVarsWithoutDiscriminator, requiredParentVarsWithoutDiscriminator); + processParentModel(model, requiredVarsWithoutDiscriminator, requiredParentVarsWithoutDiscriminator, allVars); var optionalVars = new ArrayList(); var requiredVars = new ArrayList(); @@ -899,6 +900,7 @@ public Map postProcessAllModels(Map objs) if (!requiredVarsWithoutDiscriminator.isEmpty()) { model.vendorExtensions.put("requiredVarsWithoutDiscriminator", requiredVarsWithoutDiscriminator); } + model.vendorExtensions.put("allVars", allVars); model.vendorExtensions.put("requiredVars", requiredVars); model.vendorExtensions.put("optionalVars", optionalVars); model.vendorExtensions.put("areRequiredVarsAndReadOnlyVars", !requiredVarsWithoutDiscriminator.isEmpty() && !model.readOnlyVars.isEmpty()); @@ -942,10 +944,14 @@ public boolean isGenerateHardNullable() { return false; } - private void processParentModel(CodegenModel model, List requiredVarsWithoutDiscriminator, List requiredParentVarsWithoutDiscriminator) { + private void processParentModel(CodegenModel model, List requiredVarsWithoutDiscriminator, + List requiredParentVarsWithoutDiscriminator, + List allVars) { var parent = model.getParentModel(); var hasParent = parent != null; + allVars.addAll(model.vars); + for (var v : model.requiredVars) { boolean isDiscriminator = isDiscriminator(v, model); if (!isDiscriminator(v, model) && !containsProp(v, requiredVarsWithoutDiscriminator)) { @@ -958,7 +964,7 @@ private void processParentModel(CodegenModel model, List requir model.parentVars = parent.allVars; } if (hasParent) { - processParentModel(parent, requiredVarsWithoutDiscriminator, requiredParentVarsWithoutDiscriminator); + processParentModel(parent, requiredVarsWithoutDiscriminator, requiredParentVarsWithoutDiscriminator, allVars); } } diff --git a/openapi-generator/src/main/resources/templates/java-micronaut/common/model/pojo.mustache b/openapi-generator/src/main/resources/templates/java-micronaut/common/model/pojo.mustache index 82f83db2fe..56dede6cd6 100644 --- a/openapi-generator/src/main/resources/templates/java-micronaut/common/model/pojo.mustache +++ b/openapi-generator/src/main/resources/templates/java-micronaut/common/model/pojo.mustache @@ -131,6 +131,11 @@ public class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{{#vendorE {{/vars}} {{#requiredPropertiesInConstructor}} + {{^micronaut_serde_jackson}} + public {{classname}}() { + } + + {{/micronaut_serde_jackson}} {{#formatNoEmptyLines}} {{#vendorExtensions.withRequiredVars}} public {{classname}}({{#vendorExtensions.requiredVarsWithoutDiscriminator}}{{#isReadOnly}}{{#vendorExtensions.isServer}}{{^-first}}, {{/-first}}{{{datatypeWithEnum}}} {{name}}{{/vendorExtensions.isServer}}{{/isReadOnly}}{{^isReadOnly}}{{^-first}}, {{/-first}}{{{datatypeWithEnum}}} {{name}}{{/isReadOnly}}{{/vendorExtensions.requiredVarsWithoutDiscriminator}}) { @@ -382,9 +387,9 @@ public class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{{#vendorE @Override public String toString() { return "{{classname}}(" - {{#allVars}} + {{#vendorExtensions.allVars}} + "{{name}}: " + {{{getter}}}(){{^-last}} + ", "{{/-last}} - {{/allVars}} + {{/vendorExtensions.allVars}} + ")"; } {{/lombok}} diff --git a/openapi-generator/src/main/resources/templates/kotlin-micronaut/common/model/pojo.mustache b/openapi-generator/src/main/resources/templates/kotlin-micronaut/common/model/pojo.mustache index 5207fb1c0c..986b402a73 100644 --- a/openapi-generator/src/main/resources/templates/kotlin-micronaut/common/model/pojo.mustache +++ b/openapi-generator/src/main/resources/templates/kotlin-micronaut/common/model/pojo.mustache @@ -91,7 +91,7 @@ } override fun toString(): String { - return "{{classname}}({{#allVars}}{{name}}='${{name}}'{{^-last}}, {{/-last}}{{/allVars}})" + return "{{classname}}({{#vendorExtensions.allVars}}{{name}}='${{name}}'{{^-last}}, {{/-last}}{{/vendorExtensions.allVars}})" } {{/vendorExtensions.withInheritance}} diff --git a/test-suite-java-server-generator/spec.yaml b/test-suite-java-server-generator/spec.yaml index 4c1778315d..3328d4fb79 100644 --- a/test-suite-java-server-generator/spec.yaml +++ b/test-suite-java-server-generator/spec.yaml @@ -43,7 +43,7 @@ paths: schema: $ref: '#/components/schemas/SendPrimitivesResponse' default: - $ref: '#/responses/Error' + $ref: '#/components/responses/Error' /sendValidatedPrimitives: get: operationId: sendValidatedPrimitives @@ -86,7 +86,7 @@ paths: schema: type: string default: - $ref: '#/responses/Error' + $ref: '#/components/responses/Error' /sendDates: get: operationId: sendDates @@ -111,7 +111,7 @@ paths: schema: $ref: '#/components/schemas/SendDatesResponse' default: - $ref: '#/responses/Error' + $ref: '#/components/responses/Error' /sendParameterEnum: get: operationId: sendParameterEnum @@ -234,7 +234,7 @@ paths: schema: $ref: '#/components/schemas/SimpleModel' default: - $ref: '#/responses/Error' + $ref: '#/components/responses/Error' /sendListOfSimpleModels: post: operationId: sendListOfSimpleModels @@ -276,7 +276,7 @@ paths: schema: $ref: '#/components/schemas/ModelWithRequiredProperties' default: - $ref: '#/responses/Error' + $ref: '#/components/responses/Error' /sendDateModel: post: operationId: sendDateModel @@ -295,7 +295,7 @@ paths: schema: $ref: '#/components/schemas/DateModel' default: - $ref: '#/responses/Error' + $ref: '#/components/responses/Error' /sendEnum: post: operationId: sendEnum @@ -315,7 +315,7 @@ paths: schema: $ref: '#/components/schemas/ColorEnum' default: - $ref: '#/responses/Error' + $ref: '#/components/responses/Error' /sendEnumList: post: operationId: sendEnumList @@ -339,7 +339,7 @@ paths: items: $ref: '#/components/schemas/ColorEnum' default: - $ref: '#/responses/Error' + $ref: '#/components/responses/Error' /sendModelWithMapProperty: post: operationId: sendModelWithMapProperty @@ -391,7 +391,7 @@ paths: schema: $ref: '#/components/schemas/NestedModel' default: - $ref: '#/responses/Error' + $ref: '#/components/responses/Error' /sendModelWithInnerEnum: post: operationId: sendModelWithInnerEnum @@ -411,7 +411,7 @@ paths: schema: $ref: '#/components/schemas/ModelWithInnerEnum' default: - $ref: '#/responses/Error' + $ref: '#/components/responses/Error' /sendModelWithEnumList: post: operationId: sendModelWithEnumList @@ -431,7 +431,7 @@ paths: schema: $ref: '#/components/schemas/ModelWithEnumList' default: - $ref: '#/responses/Error' + $ref: '#/components/responses/Error' /sendModelWithDiscriminator: put: operationId: sendModelWithDiscriminator @@ -474,7 +474,7 @@ paths: type: string format: byte default: - $ref: '#/responses/Error' + $ref: '#/components/responses/Error' /sendBytes: put: operationId: sendBytes @@ -507,7 +507,7 @@ paths: schema: $ref: '#/components/schemas/SimpleModel' default: - $ref: '#/responses/Error' + $ref: '#/components/responses/Error' /getDateTime: get: operationId: getDateTime @@ -522,7 +522,7 @@ paths: type: string format: date-time default: - $ref: '#/responses/Error' + $ref: '#/components/responses/Error' /getDateModel: get: operationId: getDateModel @@ -536,7 +536,7 @@ paths: schema: $ref: '#/components/schemas/DateModel' default: - $ref: '#/responses/Error' + $ref: '#/components/responses/Error' /getSimpleModelWithNonStandardStatus: get: operationId: getSimpleModelWithNonStandardStatus @@ -550,7 +550,7 @@ paths: schema: $ref: '#/components/schemas/SimpleModel' default: - $ref: '#/responses/Error' + $ref: '#/components/responses/Error' /getModelWithValidatedList: get: operationId: getModelWithValidatedList @@ -564,7 +564,7 @@ paths: schema: $ref: '#/components/schemas/ModelWithValidatedListProperty' default: - $ref: '#/responses/Error' + $ref: '#/components/responses/Error' /getPaginatedSimpleModel: get: operationId: getPaginatedSimpleModel @@ -623,7 +623,7 @@ paths: schema: $ref: '#/components/schemas/SimpleModel' default: - $ref: '#/responses/Error' + $ref: '#/components/responses/Error' /getDatedSimpleModelWithNonMappedHeader: get: operationId: getDatedSimpleModelWithNonMappedHeader @@ -669,7 +669,7 @@ paths: type: string format: binary default: - $ref: '#/responses/Error' + $ref: '#/components/responses/Error' components: schemas: