-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG][KOTLIN-SPRING] Constructor call generated for interface supertypes if using inheritance/discriminator #8366
Comments
Thank you for the workaround! 🥳
|
The problem with the fix is that it doesn't seem to work for when openapi.json {
"openapi": "3.0.3",
"info": {
"title": "Hyperledger Cactus Plugin - Connector Corda",
"description": "Can perform basic tasks on a Corda ledger",
"version": "v2.0.0-alpha.2",
"license": {
"name": "Apache-2.0",
"url": "https://www.apache.org/licenses/LICENSE-2.0.html"
}
},
"paths": {},
"components": {
"schemas": {
"JarFile": {
"type": "object",
"required": ["filename", "contentBase64", "hasDbMigrations"],
"additionalProperties": true,
"properties": {
"filename": {
"type": "string",
"nullable": false,
"minLength": 1,
"maxLength": 255
},
"hasDbMigrations": {
"description": "Indicates whether the cordapp jar in question contains any embedded migrations that Cactus can/should execute between copying the jar into the cordapp directory and starting the node back up.",
"type": "boolean",
"nullable": false
},
"contentBase64": {
"type": "string",
"format": "base64",
"nullable": false,
"minLength": 1,
"maxLength": 1073741824
}
}
}
}
}
} JarFile.kt package org.hyperledger.cactus.plugin.ledger.connector.corda.server.model
import java.util.Objects
import com.fasterxml.jackson.annotation.JsonProperty
import javax.validation.constraints.DecimalMax
import javax.validation.constraints.DecimalMin
import javax.validation.constraints.Email
import javax.validation.constraints.Max
import javax.validation.constraints.Min
import javax.validation.constraints.NotNull
import javax.validation.constraints.Pattern
import javax.validation.constraints.Size
import javax.validation.Valid
import io.swagger.v3.oas.annotations.media.Schema
/**
*
* @param filename
* @param hasDbMigrations Indicates whether the cordapp jar in question contains any embedded migrations that Cactus can/should execute between copying the jar into the cordapp directory and starting the node back up.
* @param contentBase64
*/
data class JarFile(
@get:Size(min=1,max=255)
@Schema(example = "null", required = true, description = "")
@get:JsonProperty("filename", required = true) val filename: kotlin.String,
@Schema(example = "null", required = true, description = "Indicates whether the cordapp jar in question contains any embedded migrations that Cactus can/should execute between copying the jar into the cordapp directory and starting the node back up.")
@get:JsonProperty("hasDbMigrations", required = true) val hasDbMigrations: kotlin.Boolean,
@get:Size(min=1,max=1073741824)
@Schema(example = "null", required = true, description = "")
@get:JsonProperty("contentBase64", required = true) val contentBase64: kotlin.String
) : kotlin.collections.HashMap<String, kotlin.Any>{
} Resulting compiler error
I'm not an expert in the generator's internals. My naive idea for a more robust solution is to have an additional context variable added by the generator before the template rendering happens. Something that could be called |
The new parentCtorCallNeeded property can be used by the template to determine if there should be a constructor invocation on the parent type. Right now its value is computed in a way that could probably use some improvement because it is language specifically checking if the base type is a kotlin map or not. This might seem overly brittle, but was the only way I could differentiate between the two different edge cases that are present in the repro spec. This was the previous commit that changed the default behavior from one edge case to the other (both are wrong because we can only know for sure at generation time whether a constructor call will be necessary or not). OpenAPITools@0bb08a7 Below is a yaml OpenAPI spec document that can be used to test/verify the currently known edge cases (which were also mentioned in the GH issue tracker's comments) ```yaml openapi: 3.0.3 info: version: "1.0.0" title: "" paths: /documents/v1: get: responses: 200: description: lorem content: application/json: schema: type: array items: $ref: "#/components/schemas/ParentSchema" components: schemas: JarFiles: type: array items: $ref: "#/components/schemas/JarFile" JarFile: type: object required: - filename - contentBase64 - hasDbMigrations additionalProperties: true properties: filename: type: string nullable: false minLength: 1 maxLength: 255 hasDbMigrations: description: Indicates whether the cordapp jar in question contains any embedded migrations that Cactus can/should execute between copying the jar into the cordapp directory and starting the node back up. type: boolean nullable: false contentBase64: type: string format: base64 nullable: false minLength: 1 maxLength: 1073741824 ParentSchema: type: object properties: id: type: string type: $ref: "#/components/schemas/DiscriminatingType" required: - id - type discriminator: propertyName: type mapping: subtypeA: "#/components/schemas/SubtypeA" subtypeB: "#/components/schemas/SubtypeB" subtypeC: "#/components/schemas/SubtypeC" SubtypeA: type: object allOf: - $ref: '#/components/schemas/ParentSchema' - type: object properties: subtypeAproperty: type: integer SubtypeB: type: object allOf: - $ref: '#/components/schemas/ParentSchema' - type: object properties: subtypeBproperty: type: string SubtypeC: type: object additionalProperties: true allOf: - $ref: '#/components/schemas/ParentSchema' - type: object properties: subtypeAproperty: type: integer DiscriminatingType: type: string enum: - subtypeA - subtypeB - subtypeC ``` Fixes OpenAPITools#8366 Signed-off-by: Peter Somogyvari <[email protected]>
…ler errors 1. Started overriding a specific template (dataClass.mustache) in the main-server sub-package of the corda connector because of issues that are further explained here [1] and here [2]. 2. Also had to update generator configuration to specifically exclude spring-doc generation because it seems to be broken within the template as well: it does not provide updated dependencies for the grandle and maven manifests and so the `io.swagger.core.v3:swagger-annotations` package was missing and failing the build in a second way. 3. The example value for the return array of `ListFlowsV1Response` in the openapi.json spec file of the corda connector was containing dollar signs ($) which ended up being appended to the kotlin code's annotations as documentation, but the dollar signs have a special meaning in kotlin and lead to syntax errors. Updating the examples to not have dollar signs in the openapi.json specification document resulted in fixing this issue. 4. Also updated the artifact version in the openapi generator configuration file. This is just a temporary fix, what we really need is scripts bumping this up as part of the automated release process. [1] OpenAPITools/openapi-generator#8366 (comment) [2] OpenAPITools/openapi-generator#17008 Fixes hyperledger-cacti#2662 Signed-off-by: Peter Somogyvari <[email protected]>
…ler errors 1. Started overriding a specific template (dataClass.mustache) in the main-server sub-package of the corda connector because of issues that are further explained here [1] and here [2]. 2. Also had to update generator configuration to specifically exclude spring-doc generation because it seems to be broken within the template as well: it does not provide updated dependencies for the grandle and maven manifests and so the `io.swagger.core.v3:swagger-annotations` package was missing and failing the build in a second way. 3. The example value for the return array of `ListFlowsV1Response` in the openapi.json spec file of the corda connector was containing dollar signs ($) which ended up being appended to the kotlin code's annotations as documentation, but the dollar signs have a special meaning in kotlin and lead to syntax errors. Updating the examples to not have dollar signs in the openapi.json specification document resulted in fixing this issue. 4. Also updated the artifact version in the openapi generator configuration file. This is just a temporary fix, what we really need is scripts bumping this up as part of the automated release process. [1] OpenAPITools/openapi-generator#8366 (comment) [2] OpenAPITools/openapi-generator#17008 Fixes hyperledger-cacti#2662 Signed-off-by: Peter Somogyvari <[email protected]>
…ler errors 1. Started overriding a specific template (dataClass.mustache) in the main-server sub-package of the corda connector because of issues that are further explained here [1] and here [2]. 2. Also had to update generator configuration to specifically exclude spring-doc generation because it seems to be broken within the template as well: it does not provide updated dependencies for the grandle and maven manifests and so the `io.swagger.core.v3:swagger-annotations` package was missing and failing the build in a second way. 3. The example value for the return array of `ListFlowsV1Response` in the openapi.json spec file of the corda connector was containing dollar signs ($) which ended up being appended to the kotlin code's annotations as documentation, but the dollar signs have a special meaning in kotlin and lead to syntax errors. Updating the examples to not have dollar signs in the openapi.json specification document resulted in fixing this issue. 4. Also updated the artifact version in the openapi generator configuration file. This is just a temporary fix, what we really need is scripts bumping this up as part of the automated release process. [1] OpenAPITools/openapi-generator#8366 (comment) [2] OpenAPITools/openapi-generator#17008 Fixes hyperledger-cacti#2662 Signed-off-by: Peter Somogyvari <[email protected]> (cherry picked from commit 99ec2ff)
…ler errors 1. Started overriding a specific template (dataClass.mustache) in the main-server sub-package of the corda connector because of issues that are further explained here [1] and here [2]. 2. Also had to update generator configuration to specifically exclude spring-doc generation because it seems to be broken within the template as well: it does not provide updated dependencies for the grandle and maven manifests and so the `io.swagger.core.v3:swagger-annotations` package was missing and failing the build in a second way. 3. The example value for the return array of `ListFlowsV1Response` in the openapi.json spec file of the corda connector was containing dollar signs ($) which ended up being appended to the kotlin code's annotations as documentation, but the dollar signs have a special meaning in kotlin and lead to syntax errors. Updating the examples to not have dollar signs in the openapi.json specification document resulted in fixing this issue. 4. Also updated the artifact version in the openapi generator configuration file. This is just a temporary fix, what we really need is scripts bumping this up as part of the automated release process. [1] OpenAPITools/openapi-generator#8366 (comment) [2] OpenAPITools/openapi-generator#17008 Fixes hyperledger-cacti#2662 Signed-off-by: Peter Somogyvari <[email protected]>
…ler errors 1. Started overriding a specific template (dataClass.mustache) in the main-server sub-package of the corda connector because of issues that are further explained here [1] and here [2]. 2. Also had to update generator configuration to specifically exclude spring-doc generation because it seems to be broken within the template as well: it does not provide updated dependencies for the grandle and maven manifests and so the `io.swagger.core.v3:swagger-annotations` package was missing and failing the build in a second way. 3. The example value for the return array of `ListFlowsV1Response` in the openapi.json spec file of the corda connector was containing dollar signs ($) which ended up being appended to the kotlin code's annotations as documentation, but the dollar signs have a special meaning in kotlin and lead to syntax errors. Updating the examples to not have dollar signs in the openapi.json specification document resulted in fixing this issue. 4. Also updated the artifact version in the openapi generator configuration file. This is just a temporary fix, what we really need is scripts bumping this up as part of the automated release process. [1] OpenAPITools/openapi-generator#8366 (comment) [2] OpenAPITools/openapi-generator#17008 Fixes #2662 Signed-off-by: Peter Somogyvari <[email protected]>
…ler errors 1. Started overriding a specific template (dataClass.mustache) in the main-server sub-package of the corda connector because of issues that are further explained here [1] and here [2]. 2. Also had to update generator configuration to specifically exclude spring-doc generation because it seems to be broken within the template as well: it does not provide updated dependencies for the grandle and maven manifests and so the `io.swagger.core.v3:swagger-annotations` package was missing and failing the build in a second way. 3. The example value for the return array of `ListFlowsV1Response` in the openapi.json spec file of the corda connector was containing dollar signs ($) which ended up being appended to the kotlin code's annotations as documentation, but the dollar signs have a special meaning in kotlin and lead to syntax errors. Updating the examples to not have dollar signs in the openapi.json specification document resulted in fixing this issue. 4. Also updated the artifact version in the openapi generator configuration file. This is just a temporary fix, what we really need is scripts bumping this up as part of the automated release process. [1] OpenAPITools/openapi-generator#8366 (comment) [2] OpenAPITools/openapi-generator#17008 Fixes hyperledger-cacti#2662 Signed-off-by: Peter Somogyvari <[email protected]>
This is still an issue with incorrectly generated constructor , would it be fixed someday? |
@timurgen Oh wait this is a different PR that is not mine, nvm. :-) |
Bug Report Checklist
Description
If the parent of a type is generated as interface the subtype is generated with a constructor call to the parent interface which doesn't compile:
Note:
ParentSchema()
. The()
prevent compilationopenapi-generator version
openapi-generator-maven-plugin:5.0.0
OpenAPI declaration file content or url
Sample spec
Related issues/PRs
Similar: #3587
Suggest a fix
I worked around it by removing the
()
fromdataClass.mustache
. This wouldn't work if the parent is a class.The text was updated successfully, but these errors were encountered: