Forum Discussion

bdipasca's avatar
bdipasca
New Contributor
4 years ago
Solved

How to add a JSON example in a POST Request Body? (without a schema reference)

I came across this spec example on the OpenAPI Spec Github where there is a JSON example pasted directly into the GET response:

 

Is it possible to do something similar for the POST request body? I have tried replicating this, but receive a render error on the UI:

 

 

 

I know that I can use a schema reference to define the JSON request, but it would be very nice to be able to directly paste a JSON example into the YAML file. Note sure why this would be possible for a response body but not a request body. Any input would be appreciated!

  • Hi bdipasca,

    You can add examples for the request bodies too, but please also add a "schema":

          requestBody:
            content:
              application/json:
                schema:       # <-------
                  type: object
                examples:
                  foo:
                    value:
                      ...

     

    There's a known issue where examples cannot be rendered if "schema" isn't provided.

2 Replies

  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)

    Hi bdipasca,

    You can add examples for the request bodies too, but please also add a "schema":

          requestBody:
            content:
              application/json:
                schema:       # <-------
                  type: object
                examples:
                  foo:
                    value:
                      ...

     

    There's a known issue where examples cannot be rendered if "schema" isn't provided.