Version
4.1.1
Command line used for generation
openapi-generator generate -i swagger.yaml -g go-o ./
Spec
swagger: "2.0"
info:
title: Foo
version: v1
paths:
/foo:
post:
operationId: fooPost
parameters:
-
in: body
name: body
required: false
schema:
$ref: "#/definitions/Foo"
responses:
200:
description: "successful operation"
definitions:
Foo:
type: object
Description
Generated Foo model is:
type FooPostOpts struct {
Body optional.Map[string]interface{}
}
which does not compile as optional.Map does not exist.
I would expect this model definition instead:
type FooPostOpts struct {
Body map[string]interface{}
}
I can reproduce this issue with any object without properties.
cc @antihax (2017/11) @bvwells (2017/12) @grokify (2018/07) @kemokemo (2018/09) @bkabrda (2019/07)
@wing328
It seems that an empty object is tagged as isBinary=false. This cause that the generation automatically capitalize the first letter of the type and adds the optional. prefix to id, hopping that antihax/optional has that type implemented, which in this case it does not.
@antihax I麓m not sure if map[interface]string could be implemented in your package, or even if it makes sense. WHat do you think?
Another solution could be to handle this type as a special case, as we already do in AbstractGoCodegen.java#L405 and map it to optional.Interface or tag it as isBinary=true.
Looks like the mapping is correct:
but the reference (alias) is not resolved correctly somehow.
There's another PR trying to map "object" to just interface: https://github.com/OpenAPITools/openapi-generator/pull/3878
Please review that PR when you've time.
Any update on the PR guys?
Most helpful comment
Looks like the mapping is correct:
https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractGoCodegen.java#L110
but the reference (alias) is not resolved correctly somehow.
There's another PR trying to map "object" to just interface: https://github.com/OpenAPITools/openapi-generator/pull/3878
Please review that PR when you've time.