首页 > 解决方案 > 如何在 OAS 3.1.0 中定义要在构建中生成的具有不同名称和值的枚举?

问题描述

在 Java 中,很容易创建一个像

public enum EnumType {
    TYPE_A ("Some text for type A"),
    TYPE_B ("Some text for type B"),
    TYPE_C ("Some text for type C")
}

我希望能够使用 OpenAPI 规范创建类似的结构。

如果名称和值与 相同,这将很容易:

openapi: 3.1.0
(...)
components:
  schemas:
    EnumType:
      enum: [ TYPE_A,
              TYPE_B,
              TYPE_C
      ]

但是如何使用 OpenAPI 来做到这一点?IntelliJ 将不允许const下面片段中的属性,说它是被禁止的。

openapi: 3.1.0
(...)
components:
  schemas:
    EnumType:
      oneOf:
        - title: TYPE_A
          const: 'Some text for type A'
        - title: TYPE_B
          const: 'Some text for type B'
        - title: TYPE_C
          const: 'Some text for type C'

提前致谢,

标签: javaintellij-ideaenumsopenapi

解决方案


推荐阅读