【问题标题】:How to reuse @ArraySchema description in SpringDoc如何在 SpringDoc 中重用 @ArraySchema 描述
【发布时间】:2021-11-30 21:00:46
【问题描述】:

我有几个具有相同字段的 rest-dto - 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 注释以跨多个模型重用的正确方法是什么?

【问题讨论】:

    标签: java spring swagger openapi springdoc


    【解决方案1】:

    swagger-core 注释似乎不支持此功能。 如果您想重用您的注释,这是使用springdoc-openapi 的直接解决方案。

    1. 在 OpenAPI bean 级别声明您的自定义架构
    @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.")
                            ));
    }
    
    1. 在您的课程中引用此架构:
    @Schema(ref = "CurrencyList")
    private List<CurrencyUnit> currencies;
    

    【讨论】:

      猜你喜欢
      • 2020-10-29
      • 2022-10-25
      • 2021-04-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多