Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG][Golang][Client] composed-OneOf become undefined #1745

Open
zigen opened this issue Dec 23, 2018 · 6 comments
Open

[BUG][Golang][Client] composed-OneOf become undefined #1745

zigen opened this issue Dec 23, 2018 · 6 comments

Comments

@zigen
Copy link
Contributor

zigen commented Dec 23, 2018

Description

composed-oneOf generates undefined type OneOfObjA.
here is generated code
this api should return one of ObjA or ObjB.
but Golang doesn't have such feature to describe TypeA | TypeB.

FYI https://developers.google.com/protocol-buffers/docs/reference/go-generated#oneof

openapi-generator version

4.0.0-SNAPSHOT 9e1cce2e7

OpenAPI declaration file content or url

https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/test/resources/3_0/composed-oneof.yaml

Command line used for generation

generate -t modules/openapi-generator/src/main/resources/go -i modules/openapi-generator/src/test/resources/3_0/composed-oneof.yaml -g go -o $GOPATH/src/github.com/zigen/go-sample-api -DpackageName=go_sample_api
https://github.com/zigen/openapi-generator-go-client-oas3-repro/blob/master/go-oneof.sh

Steps to reproduce

generate spec modules/openapi-generator/src/test/resources/3_0/composed-oneof.yam to golang and import it.

this repo includes steps to repro, generated conde and example client.
https://github.com/zigen/openapi-generator-go-client-oas3-repro

Related issues/PRs

#1360
#500

Suggest a fix
@auto-labeler
Copy link

auto-labeler bot commented Dec 23, 2018

👍 Thanks for opening this issue!
🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

@wing328
Copy link
Member

wing328 commented Dec 26, 2018

@zigen thanks for opening an issue. I wonder how Go GRPC client handles "oneOf" and potentially we can reuse similar code if the license permits so that we don't need to reinvent the wheel.

@zigen
Copy link
Contributor Author

zigen commented Dec 27, 2018

hmm, it looks here? https://github.com/golang/protobuf/blob/master/protoc-gen-go/generator/generator.go#L2246
it's complecated and they don't use template.

protoc and protoc-gen-go written in Go, so I think it's hard to reuse it in this project.
And the license is BSD-3-Clause https://github.com/golang/protobuf/blob/master/LICENSE

I will try to investigate protoc-gen-go and implement in this year end.

@zigen
Copy link
Contributor Author

zigen commented Dec 28, 2018

FYI
proto :

message Request {
  oneof length {
    int32 short = 3;
    int64 long = 4;
  }
}

part of generated output with $ protoc api.proto --go_out=./ :

type isRequest_Length interface {
	isRequest_Length()
}

type Request_Short struct {
	Short int32 `protobuf:"varint,3,opt,name=short,proto3,oneof"`
}

type Request_Long struct {
	Long int64 `protobuf:"varint,4,opt,name=long,proto3,oneof"`
}

protoc-gen-go generates with field tag oneof , and go proto lib parse it.
https://github.com/golang/protobuf/blob/master/proto/properties.go#L247
https://github.com/golang/protobuf/blob/master/proto/properties.go#L375
https://github.com/golang/protobuf/blob/master/proto/text_parser.go#L582

@geoah
Copy link

geoah commented Nov 22, 2019

I'm seeing the same issue in both 4.2.2-SNAPSHOT (70954ca) and 5.0.x (7f05cf0).
Are there any plans or ideas on how to fix this?

@emil14
Copy link

emil14 commented Oct 10, 2021

any updates on this one?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants