in jaxrs mode, required default to false, if primitive type not annotated by @DefaultValue, should generated defaultValue to swagger in springmvc mode, not support standard jaxrs behavior, so we no need to process it. (if not consider compatible to standard springmvc, i feel that standard jaxrs behavior is better)
2018-07-27 10:40 GMT+08:00 bismy <[email protected]>: > @zzzwjm > > > For this: > ``quot > for primitive type, even there is no @DefaultValue annotation, should > have it's default value > `` > > > Do we need to consider required = true? Why we should give default value > to primitive types even when required = true? > > > As I know, JAX-RS do not have an annotations to specify required property, > and it's implementation some like required=false, and give primitive types > the java default value. > And Spring MVC(spring boot implementation) defaults to required=true, if > primitive types not given, will throw Bad Param exception. > ------------------ 原始邮件 ------------------ > 发件人: "zzzwjm"<[email protected]>; > 发送时间: 2018年7月26日(星期四) 晚上10:00 > 收件人: "dev"<[email protected]>; > > 主题: Re: [DISCUSS] Swagger parameter default values while > generatingtheschema file > > > > " e. when generating swagger, generate defalutValue only when explicitly > specified." > > add another point: > for primitive type, even there is no @DefaultValue annotation, should have > it's default value > > 2018-07-26 19:42 GMT+08:00 bismy <[email protected]>: > > > My suggestions are as follows > > 1. Encourage providers to specify required & defalutValue explicitly. > > a. when required=true and defaultValue is given, if consumers do not > > give a value, use default value; > > b. when required=true and defaultValue is not given, if consumers do > > not give a value, throw a BadParam exception. > > c. when required=false and defaultValue is given, if consumers do not > > give a value, use default value; > > d. when required=false and defaultValue is not given, give default > > values to parameter according to java conventions. e.g. integer is 0 and > > object is null. > > e. when generating swagger, generate defalutValue only when explicitly > > specified. > > > > > > 2. As I know from PR[2], JAX-RS do not have annotations to specify > > required, required is always false. This is different from Spring MVC, > > which required defaults to true. > > a. JAX-RS defaults: required=false and defalutValue not specified > > b. Spring MVC default: required=true adefalutValue not specifiednd > > > > > > > > > > This suggestion seems equals to your Solution 1, the difference seems you > > take JAX-RS defaults required=true > > > > > > [1] https://docs.jboss.org/resteasy/2.0.0.GA/javadocs/ > > javax/ws/rs/DefaultValue.html > > [2] https://issues.apache.org/jira/browse/SCB-709 > > [3] Spring MVC: RequestParam annotation: boolean required() default true; > > > > > > ------------------ Original ------------------ > > From: "mahesh somalaraju"<[email protected]>; > > Date: Thu, Jul 26, 2018 03:23 PM > > To: "[email protected]"<[email protected]>; > > Cc: "Vinay Murudi"<[email protected]>; "Sukesh A C"<[email protected] > >; > > "Mohammad Asif Siddiqui"<[email protected]>; > > Subject: [DISCUSS] Swagger parameter default values while generating > > theschema file > > > > > > > > Hi All, > > > > Currently we are handling the issue related to swagger parameter default > > values while generating the swagger content. > > > > Default value annotation(@DefaultValue) we can provide for PathParam, > > QueryParam, MatrixParam, CookieParam, FormParam and HeaderParam. > > > > The query is when to consider default value for swagger parameter. > > > > Solution:1 [parameter value required case] > > While generating the swagger content: > > > > 1) consider default value(@DefaultValue) if and only the parameter > > configured required is false(required=false). > > > > 2) If default value(@DefaultValue) is not available then consider > > JAVA primitive default values only when the parameter configured required > > is false(required=false). > > > > The default values as follows: > > > > Object types --> null > > > > collection for List, Set or SortedSet --> Empty list > > > > primitive types: > > > > int, long --> 0 > > > > float, double --> 0.0 > > > > boolean --> false etc.. > > > > 3) When the user not provided value in request(meta-data) and the > > parameter is configured with required is true(required=true) then throw > > exception by saying that "Invalid parameter". > > > > Solution:2 [General case] > > While generating the swagger content: > > > > 1) consider default value(@DefaultValue) without checking whether it > > is required or not(required=true or required=false) > > > > 2) If default value(@DefaultValue) is not available then consider > > JAVA primitive default values without checking whether it is required or > > not(required=true or required=false) > > > > The default values as follows: > > > > Object types --> null > > > > collection for List, Set or SortedSet --> Empty list > > > > primitive types: > > > > int, long --> 0 > > > > float, double --> 0.0 > > > > boolean --> false etc.. > > > > 3) When the user not provided value in request(meta-data) , first it > > will check annotated default value field and then it will check JAVA > > primitive default values. > > > > Always some default values will be there for parameters and If user not > > given any values in request then it will consider the default values > > presented in schema content. > > > > > > Any thoughts on this? > > Please suggest which solution is best for handling the swagger parameter > > default values. Thank you in advance ! > > > > > > Thanks & Regards > > Mahesh Raju Somalaraju > > Github(id: maheshrajus) > > >
