Repository navigation
[core] Resolve primitive aliases for the oneOf discriminator property type - #25227
cmuchinsky wants to merge 1 commit into
Conversation
… type When the discriminator property of all the mapped subtypes of a oneOf is a $ref to the same alias of a primitive type (e.g. a plain `type: string` schema), DefaultCodegen#getCommonSchemaType returned the name of the alias schema as the type of the discriminator getter of the oneOf interface. No model is generated for such an alias, so the generated interface did not compile (cannot find symbol), while the subtypes use the aliased type (e.g. String). Unalias the schema first, like getSingleSchemaType does for the property type of the subtypes. A $ref that is still present afterwards (enum, object, composed schema, schema mapping) keeps being used as a model name. Regression since 7.26.0 (OpenAPITools#24812). fix OpenAPITools#25226 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
How does/should this play with |
|
Good question. For aliases of primitive types there is no interaction: The change delegates to I can add a test that runs the new spec with the flag set if you'd like. |
fix #25226
When the discriminator property of all the subtypes mapped by a
oneOfis a$refto the same alias of a primitive type (e.g.ShapeKind: {type: string}),DefaultCodegen#getCommonSchemaType(added by #24812) returns the name of the alias schema as the type of the getter of the generated oneOf interface. No model is generated for such an alias, so the generated code does not compile, while the subtypes useString:The schema is now unaliased first, like
getSingleSchemaTypedoes for the property type of the subtypes. A$refthat is still present afterwards (enum, object, composed schema,schemaMappingstarget) is still used as a model name, so the behavior added by #24812 for enums is unchanged. Aliases of primitive types resolve to the aliased type (String,Integer,UUID, ...).Tests
oneOf_issue_25226.yamlwith one oneOf per case: shared string alias, integer alias,format: uuidalias, alias of an alias, alias of an enum, direct$refto an enum, one alias per subtype, alias inherited throughallOf.DefaultCodegenTest#testOneOfDiscriminatorPropertyIsRefToPrimitiveAlias(discriminator property type) andSpringCodegenTest#issue_25226(generated interfaces and models). Both fail without the change (e.g.Shape ==> expected: <String> but was: <ShapeKind>) and pass with it../mvnw -pl modules/openapi-generator -am test: 5361 tests, 0 failures (14 skipped,@Ignored upstream)../bin/generate-samples.sh ./bin/configs/*.yaml(all 827 configs) and./bin/utils/export_docs_generators.sh: no change undersamples/ordocs/.PR checklist
./mvnw -pl modules/openapi-generator-cli -am package -DskipTests, and the tests ofmodules/openapi-generatorwere run as above):@mentionthe technical committee members, so they are more likely to review the pull request. (This is a core change that affects the generators with oneOf interfaces, i.e. the Java family) cc @jpfinne @Mattias-Sehlstedt (fix(core) handle mismatching discriminatorType in oneOf interfaces #24812), @wing328 @cbornet🤖 Generated with Claude Code
Summary by cubic
Fixes #25226. When all subtypes of a
oneOfuse a$refto the same alias of a primitive type as the discriminator property, the generatedoneOfinterface now uses the aliased type (e.g.String) instead of the missing alias schema name, which previously broke compilation. The change unaliases the schema inDefaultCodegen#getCommonSchemaType; aliases to enums and composed schemas still resolve to model names, preserving the behavior introduced in #24812.Written for commit 0d42620. Summary will update on new commits.