招摇 post body 没有架构

swagger post body without schema

我正在使用 node-swagger。它工作正常。我想 post json body 而不详细定义模式。例如下面我不想指定 object 属性。有什么办法吗?

/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

它没有将文本区域呈现为 post json 数据。

试试这个 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

如果您正在使用 swagger-ui-expressswagger-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
 */