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

defaultValue cannot be set to empty string #43

Closed
hsanjuan opened this issue Mar 27, 2013 · 6 comments
Closed

defaultValue cannot be set to empty string #43

hsanjuan opened this issue Mar 27, 2013 · 6 comments

Comments

@hsanjuan
Copy link

when a parameter type is 'string' a defaultValue of '' (empty string) does not get passed to the final generated [ruby] code.

@fehguy fehguy added this to the v2.1.0-M2 milestone Dec 24, 2014
@fehguy fehguy added the P1 label Mar 12, 2015
@lugaru1234
Copy link
Contributor

I believe 'default' values should not be used in the client at all, since 'default' is more of a way to tell the client - "if you don't provide the information
, this is what's going to be used", so it ends up being redundant.
In any way we can do one of the following things:

  1. Leave default values without any processing at the clients side and clean up ruby templates;
  2. Leave things as is as we already don't have defaults processing in the generated code;
  3. Support processing of default values at the clients side for all languages as it's done for ruby.

@iushankin
Copy link
Contributor

By the way in the core code annotation with empty default is simply ignored:

          if(!param.defaultValue().isEmpty()){
            defaultValue = param.defaultValue();
          }

Please see https://github.com/swagger-api/swagger-core/blob/develop_2.0/modules/swagger-jaxrs/src/main/java/com/wordnik/swagger/jaxrs/ParameterProcessor.java

@webron
Copy link
Contributor

webron commented Apr 16, 2015

@fehguy - your opinion?

@xhh
Copy link
Contributor

xhh commented Apr 16, 2015

I agree with lugaru1234, default value should be for documentation purpose only, to simply the API client and let the API server handle it.

BTW, the current ruby codegen does not handle defaultValue at all, I think this issue is not relevant anymore. And please have a loot at PR #649 for a solution of skipping an optional parameter (using default value for it).

@fehguy
Copy link
Contributor

fehguy commented Apr 21, 2015

@xhh @lugaru1234 Yes, ideally the default value should be applied by the server. The codegen should probably not assume that the default value be passed if not supplied.

@hsanjuan
Copy link
Author

Comments above are right. It's ugly and wrong to support defaultValue.

Either fully remove defaultValue from the swagger spec, or if it stays, then don't discriminate default values like empty strings or null... the whole point with default values is they came in handy with the default ruby-generated-code as they became optional method parameters.

Anyway, default Ruby code used to suck in many other places, so I guess its users' responsibility to take the example and fix it to avoid duplication and support optional parameters without default values (for example this issue can be addressed passing parameters in an opts Hash instead of separately)..

@webron webron modified the milestones: v2.1.0, v2.1.0-M2 May 3, 2015
@wing328 wing328 closed this as completed Mar 17, 2016
soggier pushed a commit to abacusresearch/swagger-codegen that referenced this issue Mar 29, 2018
Allow some values to be use in 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

7 participants