【问题标题】:swagger post body without schema没有架构的大摇大摆的帖子正文
【发布时间】:2016-06-08 07:06:31
【问题描述】:

我正在使用节点招摇。它工作正常。我想发布 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 数据。

【问题讨论】:

    标签: node.js swagger swagger-ui swagger-2.0


    【解决方案1】:

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

    【讨论】:

    • node-swagger模块也有问题。如果不定义模式对象属性,它不会显示 textarea。所以我将 node-swagger 与 swgger-ui 一起使用。现在它工作正常。谢谢桑帕达
    • 很高兴能帮上忙!
    【解决方案2】:

    如果您使用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
     */
    

    【讨论】:

      猜你喜欢
      • 2018-08-17
      • 1970-01-01
      • 2014-07-19
      • 2015-12-14
      • 1970-01-01
      • 2018-11-29
      • 2018-12-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多