Ask a Question

Rest api requires "enum" word at the end of the enum

ahtahkr
New Member

Rest api requires "enum" word at the end of the enum

Hi,

I updated my swagger to use enum, with sample code I found in swagger website.

components:

  1. schemas:
    1. Color:
      1. type: string
      2. enum:
        1. - black
        2. - white
        3. - red
        4. - green
        5. - blue

Unfortunately, everytime I make a call to the endpoint ("/color/black"), it requires me to use "blackenum" instead of "black". I want to use "black". Is there something I can do to use "black", instead of "blackenum".

 

Thank You.

1 REPLY 1
ponelat
Staff

Re: Rest api requires "enum" word at the end of the enum

Hi @ahtahkr 

 

You should be able to use `black` and not `blackenum`, it sounds like a typo.

 

Here is a minimal example, see if it helps...

openapi: 3.0.0
info:
  title: Test API
  version: 1.0.0

paths:
  /color/{color}:
    get:
      description: Get the hex of a color
      parameters:
      - name: color
        schema:
          $ref: '#/components/schemas/Color'
        required: true
        in: path
      responses:
        default:
          description: Hex code of a color.
          content:
            application/json:
              schema:
                type: string
                example: '#112233'
            
components:
  schemas:
    Color:
      type: string
      enum:
      - black
      - brown
      - red
      - blue

 

ponelat_0-1632927482947.png

 

cancel
Showing results for 
Search instead for 
Did you mean: