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

add enums to Java Spring path, query, and header params #3198

Closed
wants to merge 1 commit into from

Conversation

thebignet
Copy link
Contributor

Enums in header, query or path parameters where not generated as enums for Java Spring.

Inline enums are used for each api operation.

@cbornet
Copy link
Contributor

cbornet commented Jun 22, 2016

Can you generate the samples ?

@thebignet
Copy link
Contributor Author

Do you have a command for generating samples ? I don't think that it is documented

@cbornet
Copy link
Contributor

cbornet commented Jun 22, 2016

bin/springboot-petstore-server.sh

@thebignet
Copy link
Contributor Author

Samples stayed the same. In samples, enums in parameters are wrapped in lists. Changes so far only generate java enum if params are enums. Could use some help to make it work for enums wrapped in lists

@wing328
Copy link
Contributor

wing328 commented Jun 22, 2016

@thebignet coincidentally I'm working on better enum support for list (or list of list) and map (or map of map). Stay tuned.

@wing328
Copy link
Contributor

wing328 commented Jun 23, 2016

UPDATE: I've filed #3199 to support array/map (any dimensions) of enum (for C# in particular)

@wing328
Copy link
Contributor

wing328 commented Jun 23, 2016

@thebignet about updating the Petstore sample or testing the change, please refer to https://github.com/swagger-api/swagger-codegen/blob/master/CONTRIBUTING.md#testing for more information.

@wing328 wing328 added this to the v2.2.0 milestone Jun 27, 2016
@radik-sabirov
Copy link

About "files changed"...
I think that it's not good idea to add inner enum to api.mustache. It will work if you have only one path in your api class. In other words you will have the same enum in this api class after each path (endpoint).
Need to add one enum model and use it in api.mustache

@wing328
Copy link
Contributor

wing328 commented Jul 8, 2016

@radik-sabirov I agree that defining the enum as model is better as it can be reused by different endpoints or model properties but that's up to the spec owner on how they define the enum (using enum model or inline)

@radik-sabirov
Copy link

@wing328
I've solved this issue and it works for me.
What I did:

model.mustache
added

{{#models}}
 {{#model}}{{#isEnum}}{{>modelEnum}}{{/isEnum}}{{^isEnum}}{{#description}}
...
{{/isEnum}}
  {{/model}}
{{/models}}

This template can create enum if it is enum...

created new modelEnum.mustache

 /**
 * {{^description}}{{{name}}}{{/description}}{{#description}}{{{description}}}{{/description}}
 */
 public enum {{#datatypeWithEnum}}{{.}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}} {
   {{#allowableValues}}{{.}}{{^-last}} , {{/-last}}{{#-last}};{{/-last}}{{/allowableValues}}
 }

About pathParams.mustache and queryParams.mustache
I've added this

...
@ApiParam(value = "{{{description}}}"{{#required}},required=true{{/required}}{{#allowableValues}}, allowableValues="{{#allowableValues}}{{#values}}{{.}}{{^-last}} , {{/-last}}{{#-last}}{{/-last}}{{/values}}{{/allowableValues}}"{{/allowableValues}} {{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}}) @PathVariable("{{paramName}}") {{#isEnum}}{{datatypeWithEnum}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}} {{paramName}}
...

service.mustache

...
ResponseEntity<{{>returnTypes}}> {{operationId}}({{#allParams}}{{#isEnum}}{{datatypeWithEnum}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}} {{paramName}}{{#hasMore}},
      {{/hasMore}}{{/allParams}});
{{/operation}}

@thebignet
Copy link
Contributor Author

Can you make a PR for this ? I'd be interested in testing it.

@wing328 wing328 modified the milestones: v2.3.0, v2.2.0 Jul 9, 2016
@wing328
Copy link
Contributor

wing328 commented Jul 20, 2016

@radik-sabirov may I know if you've cycle to submit a PR with the enhancement?

@TehBakker
Copy link

Any news on that?

@wing328 wing328 modified the milestones: v2.3.0, v2.4.0 Dec 18, 2017
@thebignet
Copy link
Contributor Author

Closed for inactivity

@thebignet thebignet closed this May 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants