swagger-api / swagger-api/swagger-codegen-generators
[Bug]: Broken handling of primitve types in oneOf
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 299
- Forks
- 439
- PR merge metrics
- No merged PRs in 30d
Description
Description
Since 1.0.53, the generated Java code for oneOf schemas is broken when the schema contains primitive types. Previously, the resulting property had the type Object, which works fine. Now, an empty interface with no subclasses is created, breaking existing clients.
Workaround: Remove oneOf specification to force the generator to just use Object again. If there's any other workaround, please let me know.
Version
1.0.59
Can you identify when the issue first appeared?
Since this commit: https://github.com/swagger-api/swagger-codegen-generators/commit/6d56f7e5fe025b555d22f63302cfdfd2d10c14c7
Language / Generator Affected
Java
OpenAPI/Swagger Spec
"ConstantInput" : {
"required" : [ "constant" ],
"type" : "object",
"properties" : {
"constant" : {
"type" : "object",
"oneOf" : [ {
"type" : "string"
}, {
"type" : "integer",
"format" : "int32"
}, {
"type" : "number",
"format" : "double"
}, {
"type" : "boolean"
}, {
"type" : "string",
"format" : "uuid"
} ]
},
},
},
Expected Behavior
On older versions, it generated a field like this:
public class ConstantInput {
@JsonProperty("constant")
private Object constant = null;
Actual Behavior
Now, it creates this instead:
public class ConstantInput {
@JsonProperty("constant")
private OneOfConstantInputConstant constant = null;
and this unusable interface:
@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
include = JsonTypeInfo.As.PROPERTY,
property = "")
@JsonSubTypes({
})
public interface OneOfConstantInputConstant {
}
Checklist
- I have searched the existing issues to avoid duplicates.
- I have included a minimal reproducible spec or configuration.
- I have clearly described the steps to reproduce the issue.
- [ x I have specified which generator or template is affected.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the issue with the provided OpenAPI schema in the Java generator, then compare behavior before and after commit 6d56f7e5fe025b555d22f63302cfdfd2d10c14c7. Done means primitive-only oneOf schemas generate a usable Object field rather than an empty interface.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100