OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
[ ] [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
There is an inconsistency in type generation for object schema with additionalProperties. Specifically, when additionalProperties is set to {} (an empty object), it should be treated the same as when additionalProperties is set to true, but currently it is not, leading to incorrect type generation.
Additionally, the swaggo/swag leads to additionalProperties: {} being generated, which results in incorrect output.
// Pet struct for Pet
type Pet struct {
ConfigWrong map[string]map[string]interface{} `json:"config_wrong,omitempty"`
ConfigCorrect map[string]interface{} `json:"config_correct,omitempty"`
}
Generation Details
openapi-generator generate -g go -o pkg/api -i openapi.yaml --additional-properties=packageName=api,withGoMod=false
Steps to reproduce
openapi-generator generate -g go -o pkg/api -i openapi.yaml --additional-properties=packageName=api,withGoMod=false
Related issues/PRs
None found.
Suggest a fix
A potential fix would be to standardize the handling of additionalProperties: {} and additionalProperties: true to be treated equivalently, as both should allow for an unspecified number of additional properties. This requires a modification in the parser logic to treat empty object {} as a wildcard, similar to true.
Bug Report Checklist
Description
There is an inconsistency in type generation for object schema with additionalProperties. Specifically, when additionalProperties is set to {} (an empty object), it should be treated the same as when additionalProperties is set to true, but currently it is not, leading to incorrect type generation.
Additionally, the swaggo/swag leads to additionalProperties: {} being generated, which results in incorrect output.
openapi-generator version
7.10.0
OpenAPI declaration file content or url
yaml to reproduce the bug
and the result is
Generation Details
openapi-generator generate -g go -o pkg/api -i openapi.yaml --additional-properties=packageName=api,withGoMod=false
Steps to reproduce
openapi-generator generate -g go -o pkg/api -i openapi.yaml --additional-properties=packageName=api,withGoMod=false
Related issues/PRs
None found.
Suggest a fix
A potential fix would be to standardize the handling of additionalProperties: {} and additionalProperties: true to be treated equivalently, as both should allow for an unspecified number of additional properties. This requires a modification in the parser logic to treat empty object {} as a wildcard, similar to true.