Forum Discussion

johndorazio's avatar
johndorazio
New Contributor
5 years ago

In a POST operation, is it possible to have multiple examples for each property in the requestBody ?

Reading over the swagger documentation, it seems to me like the `properties` in the `requestBody` of a `POST` operation are much more limited than the `parameters` of a `GET` operation.

 

In my API I am allowing users to make either a `GET` or a `POST` request using the same parameters. In a `POST` request the parameters will be in the body instead of in the path. When defining the parameters for the GET operation, I am able to give multiple examples for each parameter. However when defining the properties for the POST operation on the same path, it seems that the examples are conceived mainly for full objects. I can give multiple examples of a full JSON object, but I can't give multiple examples for each `property` within an `application/x-www-form-urlencoded` body serialization?

  • Hi johndorazio,

    Your understanding is correct.

    Multiple examples per property will be supported in the next version of the spec, OpenAPI 3.1 (which is in the RC stage now). The syntax will be as follows:

    type: object
    properties:
      id:
        type: integer
        examples:
          - 1
          - 15
      username:
        type: string
        examples:
          - guest
          - john
          - jane
  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)

    Hi johndorazio,

    Your understanding is correct.

    Multiple examples per property will be supported in the next version of the spec, OpenAPI 3.1 (which is in the RC stage now). The syntax will be as follows:

    type: object
    properties:
      id:
        type: integer
        examples:
          - 1
          - 15
      username:
        type: string
        examples:
          - guest
          - john
          - jane