0

I'd like to be able to use this ENUM definition:

  goalStatus:
    type: string
    enum:
      - ACTIVE
      - COMPLETED
      - FULFILLED
      - DELETED

... inside of parameter definitions, however, I continue getting errors:

get:
  description: Returns all goals for a customer
  operationId: listGoals
  parameters:
    - name: status
      in: query
      description: filter by goal status
      required: false
      schema:
        $ref: "#/definitions/goalStatus"

The error:

Swagger Error: Not a valid parameter definition

1

1 Answer 1

2

Unfortunately, OpenAPI 2.0 (fka. Swagger) does not define query parameters with a schema object. Therefore you cannot use a reference to your goalStatus definition (It would work for a body parameter).

What you can do is define a reusable parameter, but if you wanted to reuse this enum in some other definition, you will have to define it twice (once in definitions once in parameters). The upcoming OpenAPI 3.0 version solve this problem by allowing to define all parameters types with a schema.

Here's an example of Version 2.0 using a reusable parameter:

swagger: '2.0'

info:
  version: 1.0.0
  title: Parameter with enum example

paths:
  /goals:
    get:
      description: Returns all goals for a customer
      operationId: listGoals
      parameters:
        - $ref: "#/parameters/goalFilter"
      responses:
        200:
          description: OK

parameters:
  goalFilter:
    name: status
    in: query
    description: filter by goal status
    required: false
    type: string
    enum:
      - ACTIVE
      - COMPLETED
      - FULFILLED
      - DELETED
Sign up to request clarification or add additional context in comments.

Comments

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.