Swagger错误:ptr必须是JSON指针

问题描述 投票:0回答:1

我试图运行我的招摇文件,我不断收到此错误。

Error: ptr must be a JSON Pointer
    at pathFromPtr (/Users/salma/Desktop/swaggerIntegration/node_modules/json-refs/index.js:1128:11)
    at /Users/salma/Desktop/swaggerIntegration/node_modules/json-refs/index.js:293:45
    at process.runNextTicks [as _tickCallback] (internal/process/next_tick.js:47:5)
    at Function.Module.runMain (internal/modules/cjs/loader.js:800:11)
    at executeUserCode (internal/bootstrap/node.js:526:15)
    at startMainThreadExecution (internal/bootstrap/node.js:439:3)

这是我的招摇文件

swagger: "2.0"
info:
  version: "0.0.1"
  title: employees DB
# during dev, should point to your local machine
host: localhost:10010
# basePath prefixes all resource paths 
basePath: /
# 
schemes:
  # tip: remove http to make production-grade
  - http
  - https
# format of bodies a client can send (Content-Type)
consumes:
  - application/json
# format of the responses to the client (Accepts)
produces:
  - application/json
paths:
  /employees:
    # binds a127 app logic to a route
    x-swagger-router-controller: employees
    get:
      description: Returns 'Hello' to the caller
      # used as the method name of the controller
      operationId: index
      parameters:
        - name: name
          in: query
          description: The name of the person to whom to say hello
          required: false
          type: string
      responses:
        "200":
          description: Success
          schema:
            # a pointer to a definition
            $ref: "#/definitions/employeesListBody"
        # responses may fall through to errors
        default:
          description: Error
          schema:
            $ref: "#/definitions/ErrorResponse"
  /swagger:
    x-swagger-pipe: swagger_raw
# complex objects have schema definitions
definitions:
  employeesListBody:
    required:
      - employees
    properties:
      employees:
        type: array
        items:
          $ref: "#definitions/Employee"

  Employee:
    required:
      - name
      - email
      - position
    properties:
        name:
          type: string
        email:
          type: string
        position:
          type: string
        age:
          type: integer
          minimum: 20
          
  ErrorResponse:
    required:
      - message
    properties:
      message:
        type: string

任何想法如何解决?是否有更简单的方法来美化swagger文件?因为我得到了许多解析错误。任何人都有一个很好的例子,使用swagger与express和mongodb?非常感谢。

javascript java express swagger openapi
1个回答
0
投票

其中一个参考文献是在/之后缺少#

$ref: "#definitions/Employee"

将其更改为:

$ref: "#/definitions/Employee"
#       ^

如果将定义粘贴到http://editor.swagger.io中,则会显示错误的确切位置。

Syntax validation in Swagger Editor

© www.soinside.com 2019 - 2024. All rights reserved.