0

我正在使用 swaggerJs 将我的文档编写为文档字符串。以下是文档的代码。我想通过不提及整个架构及其示例来整理我的路由文件夹,因此我试图引用同一文件夹目录中存在的文件。我尝试过遵循 swagger 编辑器方法,但它返回“字符串”,如下所示

/**
* @swagger
* /api/poll:
*  summary : Creates a new poll
*  post:
*    description: Creates a poll and stores it in the database based on the request object. User must be an admin to access this route
*    parameters:
*       - in: body
*         description : Request body to be sent to the api route
*         required: true
*         type: string 
*         schema:
*           $ref: "partial.json#/definitions/Pet"
*    responses:
*      200:
*        description: Returns the created poll object
*      400:
*        description : Unauthorized when bearer token isnt present , Route requires admin login
*      404:
*        description : Poll doesnt exist in the database 
*/
pollRouter
    .route('/')
    .post(mustBeAdmin, validateSchemaDynamic(pollCreateSchema), async (req: Request, res: Response) => {
        try{
            const poll: Poll = await pollManager.createGameEntity(req.body, req.user as Admin)
            return getFormattedSuccessResponse(poll, res)
        } catch (err) {
            return getFormattedErrorResponse(err, res)
        }
    })

JSON文件:

{
    "definitions": {
      "Pet": {
        "type": "object",
        "required": [
          "name",
          "photoUrls"
        ],
        "properties": {
          "id": {
            "type": "integer",
            "format": "int64"
          },
          "name": {
            "type": "string",
            "example": "doggie"
          },
          "photoUrls": {
            "type": "array",
            "xml": {
              "name": "photoUrl",
              "wrapped": true
            },
            "items": {
              "type": "string"
            }
          },
          "tags": {
            "type": "array",
            "xml": {
              "name": "tag",
              "wrapped": true
            }
          }
        }
      }
    }
  }


它不是引用 JSON 中的示例,而是返回“字符串”,如图所示 错误

我应该得到类似于 swagger 编辑器的响应如下 所示正确的

我认为这可能对应于自 2017 年以来 api 中的这个未解决问题,如果有人可以确认它给出了与提到的相同的错误 图像

https://github.com/swagger-api/swagger-editor/issues/1409

4

0 回答 0