cancel
Showing results for 
Search instead for 
Did you mean: 

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

SOLVED
Highlighted
New Contributor

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:

Screen Shot 2020-09-01 at 10.42.00 AM.png

 

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:

 

Screen Shot 2020-09-01 at 10.45.05 AM.png

 

Screen Shot 2020-09-01 at 10.47.04 AM.png

 

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Moderator

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

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.


Helen Kosova
SmartBear Documentation Team Lead
________________________
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️

View solution in original post

2 REPLIES 2
Highlighted
Moderator

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

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.


Helen Kosova
SmartBear Documentation Team Lead
________________________
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️

View solution in original post

Highlighted
New Contributor

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

thank you very much @HKosova this is what I was looking for!

New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors