defaultValue cannot be set to empty string
when a parameter type is 'string' a defaultValue of '' (empty string) does not get passed to the final generated [ruby] code.
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:
- Leave default values without any processing at the clients side and clean up ruby templates;
- Leave things as is as we already don't have defaults processing in the generated code;
- Support processing of default values at the clients side for all languages as it's done for ruby.
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
@fehguy - your opinion?
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 @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.
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)..