AdditionalProperties behavior differences
I am not sure if these two should be different?
definitions
Foo:
type: object
additionalProperties: true
Bar:
type: object
additionalProperties:
type: object
code generated
// Foo defines model for Foo.
type Foo struct {
AdditionalProperties map[string]interface{} `json:"-"`
}
// Bar defines model for Bar.
type Bar struct {
AdditionalProperties map[string]map[string]interface{} `json:"-"`
}
Should Bar also be generated as Foo here? Thanks.
For googlers: this is tracking a bug: panic: json: cannot unmarshal string into Go struct field XXX of type map[string]interface {}.
Workaround: Rewrite the OpenAPI specification to Foo (do not use Bar style).
I've got the same issue and unable to rewrite the OpenAPI specification I am reading from. Do we know if someone is working on a fix for this? I'm happy to contribute to the project if not.
A perl did trick for me:
perl -i -pe 'BEGIN{undef $$/;} s/"additionalProperties": {\s*"type": "object"\s*}/"additionalProperties": true/g' pkg/clients/pulp/pulp_openapi.json
Just saying, it is now part of a makefile target that refreshes the OpenAPI clients.
Same. I took a note from @lzap and added this perl command to my Makefile, runs against my generated yaml:
docker run --rm -it -w /workdir -v ${PWD}:/workdir perl:latest perl -0777 -i -pe 's/ additionalProperties:\n type: object/ additionalProperties: true/g' service.yml
or without docker:
perl -0777 -i -pe 's/ additionalProperties:\n type: object/ additionalProperties: true/g' service.yml
It sucks to have to hack it, but it works for now 🤷