我正在使用 swagger 学习 API 文档(开放 API 版本 3)
我正在尝试记录邮寄路线。
这是我的 YAML 语法。
/**
* @swagger
* /home:
* post:
* summary: create a new product
* tags: [Products]
* requestBody:
* required: true
* content:
* application/json:
* schema:
* $ref: "#/components/schemas/Product"
*
* responses:
* 200:
* description: The product was inserted successfully
* content:
* application/json:
* schema:
* $ref: "#/components/schemas/Product"
* 500:
* description: Some server error
*
*/
我已经彻底浏览了这段代码。然而,我一直遇到这个错误:
Here's the report:
Error in ./routes/route.js :
YAMLSyntaxError: All collection items must start at the same column at line 3, column 6:
summary: create a new product
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^…
首先,我强烈推荐使用这个Swagger Editor。 使用它,您可能会发现您只是在
500:
中的
responses:
之前缺少缩进
将脚本更改为类似的内容应该可以解决您的问题:
responses:
200:
description: The product was inserted successfully
content:
application/json:
schema:
$ref: "#/components/schemas/Product"
500:
description: Some server error