apigee-127 / swagger-node-runner

The heart of Swagger-Node
MIT License
102 stars 124 forks source link

Path param of type array[integer] always fails on length 1 #83

Open dan-kez opened 7 years ago

dan-kez commented 7 years ago

Swagger YAML Def:

/Permission:
    x-swagger-router-controller: permission
    get:
      tags: ['Permissions']
      description: Get either all permissions or a permission with a specific id
      operationId: getPermissions
      parameters:
        - $ref: "#/parameters/NodeIDs"
      responses:
        "200":
          description: Success
          schema:
            type: array
            items:
              $ref: "#/definitions/Permission"
        default:
          description: Error
          schema:
            $ref: "#/definitions/ErrorResponse"

parameters:
   NodeIDs:
    name: ids
    in: query
    description: A list of node ids (integers).
    type: array
    items:
      type: integer

Example command: curl -k https://0.0.0.0:3000/Permission?ids=123

Error:

{"message":"Validation errors","errors":[{"code":"INVALID_REQUEST_PARAMETER","errors":[{"code":"INVALID_TYPE","params":["array","integer"],"message":"Expected type array but found type integer","path":[],"description":"A list of node ids (integers)."}],"in":"query","message":"Invalid parameter (ids): Value failed JSON Schema validation","name":"ids","path":["paths","/Permission","get","parameters","1"]}]}

However the following works: curl -k https://0.0.0.0:3000/Permission?ids=1231,1231

The following behavior does not hold true when the yaml def changes to the following:

parameters:
   NodeIDs:
    name: ids
    in: query
    description: A list of node ids (integers).
    type: array
    items:
      type: string

However, I receive an error when I try to put an integer 1231 into a string.

I'd really love for a resolution to this.

Best, Dan

theganyo commented 7 years ago

Hi Dan,

Thanks for your report! I agree, that looks like a real issue. Unfortunately, this project doesn't handle OpenAPI validation. It will have to be addressed in this underlying library: https://github.com/apigee-127/sway.

Best, Scott

Celadora commented 7 years ago

The sway library has a PR that will fix this issue, but it hasn't been merged yet. If you want to take advantage of it you can use npm and install it using the following command:

 npm install https://github.com/apigee-127/sway.git#918b22e --save

Cheers!