cancel
Showing results for 
Search instead for 
Did you mean: 

How I can add sub node of json in requestbody

fayyaz
Visitor

How I can add sub node of json in requestbody

Hi All, 

openapi: 3.0.0

I am completly new to swagger, I am creating a swagger resource to share, I need to pass requestbody  as shown below for  a post method.

 

 

 

{
    "field1": {
        "field1_sub1": "3233"
    }
}

 

 

 

 

How I am doing but not able to add sub node

 

 

 

 

content:
  application/json:
   schema:
     type: object
     properties:
         field1:
         type: string
              

 

 

 

 

My question how I can add the sub node in requestBody, so my request is in node->sub node format?

 

Kind Regards

1 REPLY 1
HKosova
Moderator

Re: How I can add sub node of json in requestbody

You are almost there. Nested objects are defined like this:

content:
  application/json:
    schema:
      type: object
      properties:
        field1:
          type: object
          properties:
            field1_sub1:
              type: string
              example: '3233'

Check out these links for more examples:

Nested Objects

How to have a property reference a model in OpenAPI (i.e. nest the models)? 


Helen Kosova
SmartBear Documentation Team Lead
________________________
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
New Here?
Join us and watch the welcome video: