[英]Petstore url ( swagger default app ) not disabled in Springdoc
[英]How to change default schema of LocalDateTime in Swagger documentation using springdoc?
我們使用 Spring Boot 和https://springdoc.org/來生成 OpenApi 文檔。 我們想要更改 LocalDateTime 的默認架構,因此每次使用 LocalDateTime 時我們都沒有相同的注釋。 所以,我補充說:
static {
SpringDocUtils.getConfig().replaceWithSchema(LocalDateTime.class,
new StringSchema().example("2021-07-05T10:35:17.000").pattern("\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}[.]\\d{3}"));
}
有效。 問題是現在無法為特定字段添加自定義描述或示例:
@Schema(description = "important date")
private LocalDateTime aDate;
如您所見,Swagger-UI 中缺少以下描述:缺少描述的屏幕截圖
有沒有可能修復? 還有另一種方法可以為 LocalDateTime 設置默認的自定義架構嗎?
您可以使用 OpenAPICustomerCustomiser
@Bean
public OpenApiCustomiser openAPICustomiser() {
return openApi -> {
openApi.getComponents().getSchemas().forEach((s, schema) -> {
Map<String, Schema> properties = schema.getProperties();
if (properties == null) {
properties = Map.of();
}
for (String propertyName : properties.keySet()) {
Schema propertySchema = properties.get(propertyName);
if (propertySchema instanceof DateTimeSchema) {
properties.replace(propertyName, new StringSchema()
.example("2021-07-05T10:35:17.000")
.pattern("^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}[.]\\d{3}$")
//copies original description
.description(propertySchema.getDescription()));
}
}
});
};
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.