Forum Discussion

MythosAPI's avatar
MythosAPI
New Contributor
4 years ago

OAS 3.0.3 request schema for an empty JSON body

I am attempting to create an OAS schema for an empty JSON body:

 

 

{ }

 

 

I am trying to get the documentation to show an empty JSON body, and have that autogenerated.

The API defines this as a POST (yes, it ought to be a GET, the design of the API is in some respects sub-optimal) request, and expects the open/close bracket, and nothing else. I've tried

 

 

  …
  content:
    application/json: { }
  …

 

but that doesn't work (it just shows nothing in the request body), and everything else I've tried is invalid. Would appreciate any assistance on this. I have not been able to find any examples or even similar questions (maybe I’m looking in the wrong place?).

Any assistance would be greatly appreciated!

  • Solved.

          requestBody:
            required: true
            content:
              application/json:
                schema:
                  $ref: '#/components/schemas/EmptyBody'
    
    # # # # # # 
    
         EmptyBody:
              type: object
              nullable: true
    

     

  • MythosAPI's avatar
    MythosAPI
    New Contributor

    Solved.

          requestBody:
            required: true
            content:
              application/json:
                schema:
                  $ref: '#/components/schemas/EmptyBody'
    
    # # # # # # 
    
         EmptyBody:
              type: object
              nullable: true
    

     

    • Devil's avatar
      Devil
      Occasional Visitor

      How can I give empty JSON as an "example" at components/schemas of swagger JSON?

       

      I tried this

      "components": {
      "schemas": {  
      "APIname":{
      "type": "object",
      "properties": {},
      "example": {}
      }
      }

       

      But this example is not executed when I use schemathesis to run test cases.