@ApiParam type not supported to other than string
Asked Answered
M

2

6
@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]
Materi answered 26/6, 2019 at 10:14 Comment(2)
Your method parameters are Integer but the annotations say type="string". Have you tried changing the annotations to type="integer"?Hepler
Hi Helen,I tried this scenario but this, swagger-UI showing datatype is ref but i need data type is IntegerMateri
T
8

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

Tiler answered 20/11, 2019 at 11:37 Comment(1)
<3 mate, this should be the correct answer to the topic.Counterman
P
7

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
Pugging answered 8/4, 2020 at 22:38 Comment(1)
l was tried like this and helped me THANKS BroSilken

© 2022 - 2024 — McMap. All rights reserved.