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

enum support for golang in swagger-codegen #4459

Closed
jeetcontext opened this issue Dec 23, 2016 · 8 comments
Closed

enum support for golang in swagger-codegen #4459

jeetcontext opened this issue Dec 23, 2016 · 8 comments

Comments

@jeetcontext
Copy link

Description

I am trying to generate sdk for golang with respect to a json file. It is not able to generate the enum type.

Swagger-codegen version

Version 2.2.2-snapshot

Swagger declaration file content or url

"catalog_type": {
"description": "Type of the catalog",
"enum": [
"CATALOG_A",
"CATALOG_B"
],
"title": "Catalog type",
"type": "string"
}
This is part of json file.

Command line used for generation

After doing the mvn build, used

Java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli/target/swagger-codegen-cli.jar generate -i test.json -o ./gosdk

Steps to reproduce
Related issues

There is another dev going on with go-swagger which supports enum.

Suggest a Fix

May be the template file and the GoClientCodegen file needs to be updated for complex json.

@jeetcontext
Copy link
Author

I checked with petstore as well, It is not generating the enum inside pet object.

@taxpon
Copy link
Contributor

taxpon commented Jan 5, 2017

@jeetcontext @wing328 I am interested in working on this issue. go-swagger is providing Validate method and validating enum value inside it. I am now planning to implement similar methods in swagger-codegen, is it OK?

@wing328
Copy link
Contributor

wing328 commented Jan 5, 2017

@taxpon do you mean adding go-swagger as a dependency to the auto-generated Go API client?

For enum support in Go, I suggest we do it in the 2.3.0 branch in which @antihax has made a lot of enhancements to the Go API client, e.g. proper support of optional parameters.

@antihax
Copy link
Contributor

antihax commented Jan 5, 2017

Go does not support enum, so i think it is as simple as validating input is one of the enum elements as @jeetcontext suggest. But, to throw a wrench in the gears a bit...

5.20. enum
The value of this keyword MUST be an array. This array SHOULD have at least one element. Elements in the array SHOULD be unique.
Elements in the array MAY be of any type, including null.

We know Go also does not allow nil data types, so this may be better using interface{} or pointers.

@taxpon
Copy link
Contributor

taxpon commented Jan 5, 2017

@wing328 I intended not to add go-swagger as a dependency but to update mustache template in swagger-codegen so that it provides methods for validations (like go-swagger).

@wing328 wing328 modified the milestones: v2.3.0, v2.2.2 Feb 6, 2017
@vpolouchkine
Copy link
Contributor

Just ran into this. FWIW Go "enums" are typically done like this:

type MyEnum string

const (
	Foo MyEnum = "foo"
	Bar MyEnum = "bar"
)

@wing328
Copy link
Contributor

wing328 commented Mar 8, 2017

@vpolouchkine thanks for sharing.

Has anyone started working on this yet? If yes, please kindly share the progress. Thanks.

@marcusljx
Copy link
Contributor

marcusljx commented May 12, 2017

I wouldn't mind helping out with this. It seems trivial to generate enums in golang (basically a type alias). But as I'm new to swagger-codegen, could someone please let me know where I can read the logic of the swagger-spec java parser?

Specifically, I'm not sure what fields are in the hash used with the mustache templates.

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

6 participants