如何为嵌套对象编写swagger文档 [英] how to write swagger document for nested objects
本文介绍了如何为嵌套对象编写swagger文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
本文档准备好NodeJS Create API,如何为嵌套对象编写swagger文档。 下面是我的完整的夸张文档代码。但它不显示用户对象。帮助我解决此问题
@swagger
/api/v1/employees/add:
post:
tags:
- Employees
summary: "Create a new employee"
description:
produces:
- application/json
security:
- api_key: []
- api_token : []
parameters:
- name: body
in: body
description:
required: true
schema:
type: "object"
properties:
employee_code:
type: "string"
mobilenumber:
type: "string"
firstname:
type: "string"
lastname:
type: "string"
emailid:
type: "string"
is_login_enabled:
type: "boolean"
address_line1:
type: "string"
address_line2:
type: "string"
town:
type: "string"
city:
type: "string"
state:
type: "string"
pincode:
type: "string"
designation:
type: "string"
joining_date:
type: "string"
format: "date-time"
releiving_date:
type: "string"
format: "date-time"
is_active:
type: "boolean"
account_id:
type: "number"
user:
type: "object"
properties:
username:
type: "string"
role_id:
type: "number"
reference_object:
type: "string"
example: "employees"
password:
type: "string"
password_secret:
type: "string"
responses:
200:
description: Employee created successfully
204:
description: No data found
这是swagger用户界面的快照
推荐答案
对于嵌套对象,只需在下面使用缩进定义属性即可,因此您的路径定义将为
@swagger
/api/v1/employees/add:
put:
tags:
- Employees
summary: "Create a new employee"
description:
produces:
- application/json
security:
- api_key: []
- api_token : []
parameters:
- name: body
in: body
description:
required: true
schema:
type: "object"
properties:
employee_code:
type: "string"
mobilenumber:
type: "string"
firstname:
type: "string"
lastname:
type: "string"
emailid:
type: "string"
is_login_enabled:
type: "boolean"
address_line1:
type: "string"
address_line2:
type: "string"
town:
type: "string"
city:
type: "string"
state:
type: "string"
pincode:
type: "string"
designation:
type: "string"
joining_date:
type: "string"
format: "date-time"
releiving_date:
type: "string"
format: "date-time"
is_active:
type: "boolean"
account_id:
type: "number"
user:
type: "object"
properties:
username:
type: "string"
role_id:
type: integer
reference_object:
type: "string"
example: "employees"
password:
type: "string"
password_secret:
type: "string"
responses:
200:
description: Employee created successfully
204:
description: No data found
放置时请确保有正确的缩进。
这篇关于如何为嵌套对象编写swagger文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文