fix(core) discriminatorType in oneOf interfaces - #24812
Conversation
merge master
There was a problem hiding this comment.
1 issue found across 7 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/DiscriminatorUtils.java">
<violation number="1" location="modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/DiscriminatorUtils.java:343">
P2: When the discriminator is inherited through `allOf`, this check misses the parent mapping because the child has no direct discriminator. Traverse referenced/allOf parents to locate the inherited discriminator before collecting mapped schemas.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
|
|
||
|
|
||
| public static List<Schema> getMappedSchemas(OpenAPI openAPI, Schema schema) { | ||
| if (schema.getDiscriminator() != null && schema.getDiscriminator().getMapping() != null) { |
There was a problem hiding this comment.
P2: When the discriminator is inherited through allOf, this check misses the parent mapping because the child has no direct discriminator. Traverse referenced/allOf parents to locate the inherited discriminator before collecting mapped schemas.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/DiscriminatorUtils.java, line 343:
<comment>When the discriminator is inherited through `allOf`, this check misses the parent mapping because the child has no direct discriminator. Traverse referenced/allOf parents to locate the inherited discriminator before collecting mapped schemas.</comment>
<file context>
@@ -322,6 +323,60 @@ private static CodegenProperty getDiscriminatorCodegenProperty(OpenAPI openAPI,
+
+
+ public static List<Schema> getMappedSchemas(OpenAPI openAPI, Schema schema) {
+ if (schema.getDiscriminator() != null && schema.getDiscriminator().getMapping() != null) {
+ return schema.getDiscriminator().getMapping().values().stream()
+ .map(ref -> ModelUtils.getSchema(openAPI, ModelUtils.getSimpleRef(ref)))
</file context>
…en/utils/DiscriminatorUtils.java Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
…en/DefaultCodegen.java Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
…en/DefaultCodegen.java Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
There was a problem hiding this comment.
All reported issues were addressed across 2 files (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
| * @param openAPI | ||
| * @param schema The Schema that may contain the discriminator | ||
| * @param discPropName The String that is the discriminator propertyName in the schema | ||
| * @return "enum", "string" or "object |
There was a problem hiding this comment.
The docstring here is not correct anymore it seems since it returns Schema rather than a simple type (which I assume was just String earlier)?
| Map<String, Schema> properties = schema.getProperties(); | ||
| if (properties != null) { | ||
| Schema property = properties.get(propertyName); | ||
| // Schema property = ModelUtils.getReferencedSchema(openAPI, ); |
There was a problem hiding this comment.
Should this commented line be removed?
|
Could you add #19194 as an issue being fixed as well by this? Edit: it seem that one needs to have the full syntax to get proper linking for |
There was a problem hiding this comment.
All reported issues were addressed across 1 file (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
There was a problem hiding this comment.
All reported issues were addressed across 4 files (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
There was a problem hiding this comment.
All reported issues were addressed across 4 files (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
There was a problem hiding this comment.
All reported issues were addressed across 3 files (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
There was a problem hiding this comment.
All reported issues were addressed across 2 files (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
There was a problem hiding this comment.
1 issue found across 2 files (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/DiscriminatorUtils.java">
<violation number="1" location="modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/DiscriminatorUtils.java:336">
P3: The new local variable `properties` is dead code: it is computed but never read anywhere in `getDistinctTypes`. It also forces a second full run of the recursive `findProperty` over every mapped schema (the same work the `return` statement repeats) and ends with a stray double semicolon. Drop the line entirely.</violation>
</file>
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
| public static List<Schema> getDistinctTypes(OpenAPI openAPI, Schema schema, String discPropName) { | ||
| List<Schema> mappedSchemas = getMappedSchemas(openAPI, schema); | ||
|
|
||
| List<Schema> properties = mappedSchemas.stream().map(sc -> findProperty(openAPI, sc, discPropName, new HashSet<>())).collect(Collectors.toList());; |
There was a problem hiding this comment.
P3: The new local variable properties is dead code: it is computed but never read anywhere in getDistinctTypes. It also forces a second full run of the recursive findProperty over every mapped schema (the same work the return statement repeats) and ends with a stray double semicolon. Drop the line entirely.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/DiscriminatorUtils.java, line 336:
<comment>The new local variable `properties` is dead code: it is computed but never read anywhere in `getDistinctTypes`. It also forces a second full run of the recursive `findProperty` over every mapped schema (the same work the `return` statement repeats) and ends with a stray double semicolon. Drop the line entirely.</comment>
<file context>
@@ -332,6 +332,8 @@ private static CodegenProperty getDiscriminatorCodegenProperty(OpenAPI openAPI,
public static List<Schema> getDistinctTypes(OpenAPI openAPI, Schema schema, String discPropName) {
List<Schema> mappedSchemas = getMappedSchemas(openAPI, schema);
+
+ List<Schema> properties = mappedSchemas.stream().map(sc -> findProperty(openAPI, sc, discPropName, new HashSet<>())).collect(Collectors.toList());;
return mappedSchemas.stream().map(sc -> findProperty(openAPI, sc, discPropName, new HashSet<>()))
.filter(Objects::nonNull)
</file context>
fix #24769, fix #19194
Improve resolution of
DefaultCodegen.getDiscriminatorTypeby resolving the best common type in all mapped discriminators.Matching $ref types are used. Otherwise the types
enum,integer,string,objectare used.PR checklist
Commit all changed files.
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
Summary by cubic
Fixes #24769 and #19194 by inferring Java
oneOfdiscriminator getter types from all mapped schemas instead of defaulting toObject. Constant string discriminators now generateEnumgetters, while Kotlin keeps its existing string behavior.$refandallOfschemas.StringorObjectfallbacks when no common type exists; Java gains anenummapping toEnum.Written for commit 97909e8. Summary will update on new commits.