我正在使用node-swagger。它工作正常。我想在没有详细定义架构的情况下发布json正文。例如下面我不想指定对象属性。有没有办法做到这一点?
/pets:
post:
description: Add new
parameters:
- name: id
in: body
description: data to post
required: true
type: object
responses:
'200':
description: A list of pets
schema:
type : string
它没有渲染textarea来发布json数据。
答案 0 :(得分:2)
试试这个YAML:
---
swagger: '2.0'
info:
version: 0.0.0
title: Simple API
paths:
/:
post:
produces:
- application/json
parameters:
- in: body
name: id
required: true
schema:
"$ref": "#/definitions/inBody"
responses:
201:
description: Added
definitions:
inBody:
type: object
答案 1 :(得分:0)
如果您使用swagger-ui-express
和swagger-jsdoc
,并且不想使用定义,则可以像这样直接在终结点上的YAML中定义。
/**
* @swagger
* /pets:
* post:
* description: Add new
* produces:
* - application/json
* parameters:
* - name: id
* description: data to post
* in: body
* required: true
* schema:
* type: object
* responses:
* 201:
* description: Pet created
*/