Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@ApiParam annotation NumberFormatException bug #2979

Closed
haochencheng opened this issue Oct 15, 2018 · 2 comments
Closed

@ApiParam annotation NumberFormatException bug #2979

haochencheng opened this issue Oct 15, 2018 · 2 comments

Comments

@haochencheng
Copy link

when i use @ApiParam with an int param but without use example .

like that :
@ApiParam(value = "1 ios 2 android") Integer channel

it will thorw NumberFormatException
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.NativeMethodAccessorImpl.invoke0(Native Method)
i saw the source code is
`
@JsonProperty("x-example")
public Object getExample() {
if (this.example == null) {
return null;
} else {
try {
if ("integer".equals(this.type)) {
return Long.valueOf(this.example);
}

and the default example value is "" .
public @interface ApiParam {
boolean required() default false;
String example() default "";
}
`

should it return 0 when the param type is int ?

@ly641921791
Copy link

I also encountered the same problem, I found that swagger-models-1.5.21.jar has solved this problem, like this

    @JsonProperty("x-example")
    public Object getExample() {
        if (example == null || example.isEmpty()) {
            return example;
        }
        ....
    }

So you can exclude the 1.5.20 version of the jar and import the 1.5.21 version of the jar, like this

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

But I have not tried this method because I don't know if there will be version compatibility issues. So I fork this code and modify this line of code to compile it. I think you can do the same to solve the problem.

@Simon3
Copy link

Simon3 commented Jun 21, 2019

See springfox/springfox#2265 for more info.

gazbert added a commit to gazbert/bxbot that referenced this issue Apr 4, 2020
See: swagger-api/swagger-core#2979 and
springfox/springfox#2265

Upgrading to swagger-models 1.5.21 is the long term fix.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants