Tag Archives: swagger Docmentation Access Error

[Solved] swagger Docmentation Access Error: Illegal DefaultValue 1024 for parameter type integer, java.lang.NumberFormatException

Background error reporting problem log

2021-12-30 15:41:24.675  WARN [nio-9008-exec-1] [] i.s.m.p.AbstractSerializableParameter    [421] : Illegal DefaultValue 1024 for parameter type integer

java.lang.NumberFormatException: For input string: ""
	at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
	at java.lang.Long.parseLong(Long.java:601)
	at java.lang.Long.valueOf(Long.java:803)
	at io.swagger.models.parameters.AbstractSerializableParameter.getExample(AbstractSerializableParameter.java:412)
	at sun.reflect.GeneratedMethodAccessor149.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:689)
	at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:755)

Troubleshooting

In abstractserializableparameter.getexample (abstractserializableparameter.java:412) break point debugging. You can find that the value of example is an empty string and execute long Valueof (this.example) will throw ‘Java.lang.numberformatexception’ exception

Solution:

1. modify source code

2. Download the source code and change the if (this.example = = null) judgment to if (this.example = = null | example.isempty())

3. adjust dependency (recommended)

4. Exclude swagger models of swagger2 and add swagger models with version 1.5.21

<!--  Illegal DefaultValue null for parameter type integer  -->
        <dependency>
            <groupId>io.swagger</groupId>
            <artifactId>swagger-models</artifactId>
            <version>1.5.21</version>
        </dependency>

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.10.5</version>
            <scope>compile</scope>
            <exclusions>
                <exclusion>
                    <groupId>io.swagger</groupId>
                    <artifactId>swagger-models</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

After adjustment, you can see that the new version has modified the decision logic

after the above operations, no error will be reported when accessing the swagger document address.