Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@ApiParam type not supported to other than string

Tags:

swagger-2.0

@GetMapping(value = "/result")
    public int addition(
                    @ApiParam(value = "FirstValue", required = true, type = "string", defaultValue = "0") @RequestParam(value = "firstValue", required = true) Integer x,
                    @ApiParam(value = "SecondValue", required = true, type = "string", defaultValue = "0") @RequestParam(value = "secondValue", required = true) Integer y) {

        return x + y;
    }

while refresh the swagger UI page we are getting following error

2019-06-26 15:44:11.484  WARN 16667 --- [nio-7854-exec-3] i.s.m.p.AbstractSerializableParameter    : Illegal DefaultValue 0 for parameter type integer

java.lang.NumberFormatException: For input string: ""
    at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) ~[na:1.8.0_144]
    at java.lang.Long.parseLong(Long.java:601) ~[na:1.8.0_144]
    at java.lang.Long.valueOf(Long.java:803) ~[na:1.8.0_144]
    at io.swagger.models.parameters.AbstractSerializableParameter.getExample(AbstractSerializableParameter.java:412) ~[swagger-models-1.5.20.jar:1.5.20]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_144]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_144]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_144]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_144]
like image 511
ManikantaReddy Avatar asked Dec 18 '22 16:12

ManikantaReddy


2 Answers

That is not an error , is just a log of severity warning which can be ignored by using

logging.level.io.swagger.models.parameters.AbstractSerializableParameter=error

on application.properties.From what i saw on my own experience he will not set value 0 for an integer (i think this is because that is the default value for int type).

Regarding about type being shown as ref , that is because integer is not one of the values accepted . For java.lang.Integer or the primitive int you should use the type "int" in swagger. Other values accepted that i used are : "long" (for java.lang.Long and long) ,"bigInteger" (for java.math.BigInteger ),and of course "string" (for java.lang.String).

like image 177
Uta Alexandru Avatar answered Mar 28 '23 02:03

Uta Alexandru


Remove old swagger version (1.5.20) and add new one.

font: github issues

<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger2</artifactId>
    <version>2.9.2</version>
    <exclusions>
        <exclusion>
            <groupId>io.swagger</groupId>
            <artifactId>swagger-annotations</artifactId>
        </exclusion>
        <exclusion>
            <groupId>io.swagger</groupId>
            <artifactId>swagger-models</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger-ui</artifactId>
    <version>2.9.2</version>
</dependency>
<dependency>
    <groupId>io.swagger</groupId>
    <artifactId>swagger-annotations</artifactId>
    <version>1.5.21</version>
</dependency>
<dependency>
    <groupId>io.swagger</groupId>
    <artifactId>swagger-models</artifactId>
    <version>1.5.21</version>
</dependency>

or ignore

logging:
  io:
    swagger:
      models:
        parameters:
          AbstractSerializableParameter: error
like image 43
Aymen Avatar answered Mar 28 '23 00:03

Aymen