我正在使用Swagger编辑器为简单的Web服务生成代码,如果缺少必填字段,则应该给我一个错误。即使使用了注释@ApiModelProperty(required = true)
,当必填字段丢失时也无法产生错误。我正在使用 jaxrs 实现。以下是我正在使用的注释和依赖项:
<properties>
<java.version>1.7</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<swagger-core-version>1.5.15</swagger-core-version>
<jetty-version>9.2.9.v20150224</jetty-version>
<jersey2-version>2.22.2</jersey2-version>
<jackson-version>2.8.9</jackson-version>
<junit-version>4.12</junit-version>
<logback-version>1.1.7</logback-version>
<servlet-api-version>2.5</servlet-api-version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
package io.swagger.model;
import javax.validation.constraints.*;
import javax.validation.Valid;
import io.swagger.annotations.*;
import java.util.Objects;
import com.fasterxml.jackson.annotation.JsonProperty;
@ApiModel
public class Example1 {
private @Valid String var1 = null;
private @Valid String var2 = null;
private @Valid String var3 = null;
private @Valid String var4 = null;
public Example1 var1(String var1) {
this.var1 = var1;
return this;
}
@ApiModelProperty(required = true)
@JsonProperty("var1")
@NotNull
public String getVar1() {
return var1;
}
public void setVar1(String var1) {
this.var1 = var1;
}
感谢您的帮助。
亲切的问候, 阿贾伊