Forum Discussion

tayalaru14's avatar
tayalaru14
New Contributor
4 years ago
Solved

Different request payload for different path parameter values

how to add different request payload for different path parameter values. I am using {index} in my path and want to have different request payloads for different index values ( displayed using enum )...
  • HKosova's avatar
    4 years ago

    OpenAPI doesn't have a way to vary request payload based on parameter values. What you can can do is provide multiple examples for the request body - assuming you use OpenAPI 3.0.

    openapi: 3.0.0
    
    paths:
      /something/{index}:
        post:
          parameters:
            - in: path
              name: index
              required: true
              schema:
                type: string
                enum:
                  - foo
                  - bar
          requestBody:
            required: true
            content:
              application/json:
                schema:
                  ...
                examples:   # <--------------
                  foo:
                    summary: Request body for index=foo
                    value:
                      prop1: value1
                      prop2: value2
                  bar:
                    summary: Request body for index=bar
                    value:
                      something: else