cancel
Showing results for 
Search instead for 
Did you mean: 

How do i define a nested class json body in a swagger file version 3.0.1

SOLVED
Highlighted
New Contributor

How do i define a nested class json body in a swagger file version 3.0.1

Sample of a response body

Response body
{ "admn_user_id": 55, "admindetails": { "userdetail_id": 02, "firstname": "example1", "lastname": "example2", "contact_phone": "7777788888", "admn_partner_id": 12, "updated_on": "2020-01-20T10:54:51Z", "email_id": "abc@foo.com", "admn_user": 55, "region": 2, "region_name": "At02" }, "user_type": 2, "username": "sou1", "user_status": 3, "role_id": 2, "role_name": "ABC", "user_status_name": "Active" },

How do I design a swagger components/schema for the above response body for a post method.
Give me any link to understand the problem.
Can I pass a schema model inside another using $ref?

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Moderator

Re: How do i define a nested class json body in a swagger file version 3.0.1


@KinnarChowdhury wrote:

Can I pass a schema model inside another using $ref?


Yes! Here's how:

components:
  schemas:
ParentSchema: type: object properties: admn_user_id: type: object example: 55 admindetails: $ref: '#/components/schemas/AdminDetails' # <------- ...
AdminDetails: type: object properties: userdetail_id: type: integer example: 2 firstname: type: string ...

Helen Kosova
SmartBear Technical Writer
________________________

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 do i define a nested class json body in a swagger file version 3.0.1


@KinnarChowdhury wrote:

Can I pass a schema model inside another using $ref?


Yes! Here's how:

components:
  schemas:
ParentSchema: type: object properties: admn_user_id: type: object example: 55 admindetails: $ref: '#/components/schemas/AdminDetails' # <------- ...
AdminDetails: type: object properties: userdetail_id: type: integer example: 2 firstname: type: string ...

Helen Kosova
SmartBear Technical Writer
________________________

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 do i define a nested class json body in a swagger file version 3.0.1

Thanks for the solution, I understood the logic in this case. I appreciate your help.

New Here?
Join us and watch the welcome video: