Ask a Question

Different request payload for different path parameter values

SOLVED
tayalaru14
New Contributor

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 )

1 REPLY 1
HKosova
SmartBear Alumni (Retired)

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

 

HKosova_0-1601409077407.png


Helen Kosova
SmartBear Documentation Team Lead
________________________
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
cancel
Showing results for 
Search instead for 
Did you mean: