我有几个rest-dtos,它们具有相同的字段-由CurrencyUnit (java-money)表示的货币列表
import javax.money.CurrencyUnit;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Schema;
...
@ArraySchema(schema = @Schema(type = "string"),
arraySchema = @Schema(
example = "[\"USD\",\"CAD\"]",
description = "Currencies supported by store according to ISO_4217."
))
private List<CurrencyUnit> currencies;将所有这些元数据提取到单个@CurrencyCodesList注释中以便在多个模型中重用的正确方法是什么?
发布于 2021-11-30 13:00:47
在swagger-core注释中似乎不支持这一点。如果您想重用您的注释,这是使用springdoc-openapi的直接解决方案。
级别声明自定义模式
@Bean
public OpenAPI customOpenAPI() {
String currenciesSample[] = { "USD", "ILS" };
return new OpenAPI().components(new Components()
.addSchemas("CurrencyList", new ArraySchema().type("string")
.example(currenciesSample).description("Currencies supported by store according to ISO_4217.")
));
}@Schema(ref = "CurrencyList")
private List<CurrencyUnit> currencies;https://stackoverflow.com/questions/70145258
复制相似问题