oas在属性上忽略@schema(必需= false),如果标记为@notnull
我的模型具有我不需要的字段的模型:
import io.swagger.v3.oas.annotations.media.Schema;
import javax.validation.constraints.NotNull;
public class Model {
@NotNull
@Schema(required = false)
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
但是SpringDoc自动形式将其标记为需要(我知道这是@notnull注释的原因),
"schemas": {
"Model": {
"required": [
"name"
],
"type": "object",
"properties": {
"name": {
"type": "string"
}
}
},
因此我如何在生成的文档中不需要字段并留下两个注释,我的意思是@notnull和@schema?
使用的依赖性:
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.6.7</version>
</dependency>
I have model with field i want to make not required:
import io.swagger.v3.oas.annotations.media.Schema;
import javax.validation.constraints.NotNull;
public class Model {
@NotNull
@Schema(required = false)
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
but springdoc automaticaly marks it as required(i know that it's cause of @NotNull annotation)
"schemas": {
"Model": {
"required": [
"name"
],
"type": "object",
"properties": {
"name": {
"type": "string"
}
}
},
So how i can make field not required in generated documentation and leave both annotations i mean @NotNull and @Schema?
Used dependencies:
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.6.7</version>
</dependency>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
parametercustomizer
覆盖@notnull
这样的注释:You can override the
@NotNull
annotation usingParameterCustomizer
like this: