swagger-codegen icon indicating copy to clipboard operation
swagger-codegen copied to clipboard

defaultValue cannot be set to empty string

Open hsanjuan opened this issue 13 years ago • 6 comments

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

hsanjuan avatar Mar 27 '13 14:03 hsanjuan

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.

lugaru1234 avatar Apr 10 '15 15:04 lugaru1234

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

iushankin avatar Apr 13 '15 20:04 iushankin

@fehguy - your opinion?

webron avatar Apr 16 '15 11:04 webron

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).

xhh avatar Apr 16 '15 12:04 xhh

@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.

fehguy avatar Apr 21 '15 00:04 fehguy

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)..

hsanjuan avatar Apr 30 '15 01:04 hsanjuan