0

In Java, it is quite easy to create an Enum like

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

I want to be able to create a similar structure with the OpenAPI specification.

This would be easy enough if the names and values are the same with :

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

But how can I do it with OpenAPI? IntelliJ will not allow the const property in the snippet below, saying it is prohibited.

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'

Thanks in advance,

4
  • 1
    Your spec is OpenAPI 3.1 - does IntelliJ (or whatever OpenAPI editor plugin you use in IntelliJ) actually support 3.1? It might be complaining because it does not recognize the const keyword which is new in 3.1. Commented Aug 4, 2021 at 18:03
  • Likely not. Apparently, there is no IntelliJ support so far for OAS 3.1.0 - be it native or via plugins. As long as the code gets generated, I don't mind designing the API in a third party tool. Any suggestions on that? Commented Aug 4, 2021 at 22:03
  • 1
    So far there's almost no tooling support for OAS 3.1. You may want to stick with 3.0 and use enum with x- extensions (like here) and customize the code generator to understand those extensions (assuming your codegen supports such customizations). Commented Aug 5, 2021 at 6:52
  • 2
    The schema is correct. The problem is with the tooling. Commented Aug 5, 2021 at 7:10

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.