Salma Zaghloul
Salma Zaghloul

Reputation: 35

Swagger error :ptr must be a JSON Pointer

I am trying to run my swagger file and i keep getting this error.

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)

and here is my swagger file

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

any idea how to solve that ? is there an easier way to prettify the swagger file? because i get many parsing erros. also does any one have a good example of using swagger with express and mongodb ? many thanks.

Upvotes: 0

Views: 1624

Answers (1)

Helen
Helen

Reputation: 97982

One of the references is missing a / after #:

$ref: "#definitions/Employee"

Change it to:

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


If you paste your definition into http://editor.swagger.io, it shows where exactly the error is.

Syntax validation in Swagger Editor

Upvotes: 1

Related Questions