OpenAPITools / OpenAPITools/openapi-generator
[BUG][Spring] 6.x.x generator incorrectly creating dictionaries when using $ref
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
When migrating from 3.x openapi generator to the 6.x generator, our model objects no longer serialize / deserialize properly. We are using the spring generator.
I have pinpointed the issue to how the generator creates the model objects when creating a dictionary from an external $ref.
Per swagger documentation: https://swagger.io/docs/specification/data-models/dictionaries/#:~:text=OpenAPI%20lets%20you%20define%20dictionaries,%7B, dictionaries are created via additionalProperties.
Our expectation is that when we specify additionalAttributes with named properties, the java code would generate a Map of the correct types when explicitly setting the properties. This seems to work as expected when the dictionary is defined inline to the component. However, when we include via a ref, it generates an unexpected model structure (thus breaking SerDe).
Expectation:
Main component yaml
components:
schemas:
Main:
properties:
someProperty:
$ref: "SomeFile.yaml#/components/schemas/SomeProperty"
SomeFile.yaml
components:
schemas:
SomeProperty:
type: object
additionalProperties:
type: object
properties:
name:
type: string
description: Name
value:
description: Value
type: object
Expected Java Generation
public class Main {
private Map<String, Object> someProperty;
}
Actual Java Generation
public class Main {
private Map<String, SomeProperty> someProperty;
...
}
public class SomeProperty {
private String name;
private Object value;
...
}
Which obviously represents different JSON structures.
openapi-generator version
6.5.0. Yes, this is a regression.
Related issues/PRs
Similar issue, but not quite the same: https://github.com/OpenAPITools/openapi-generator/issues/14232
Suggest a fix
Should mimic behavior as if the additional properties were specified inline.
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
Reproduce the Spring generator case from the issue using Main and the externally referenced SomeProperty schema, focusing on additionalProperties and the external $ref path. Compare the generated Java model with the inline-schema behavior. Done means the referenced dictionary produces the expected Map<String, Object> structure without an unintended SomeProperty model.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi, spring
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100