swagger-api / swagger-api/swagger-client

Mandatory custom header fails validation

Open
#1,422 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
2.7k
Forks
765
Avg merge
1d 1h
Merged PRs (30d)
6

Description

Q&A (please complete the following information)
  • OS: WIn10
  • Environment: Node.js v10.8.0
  • Method of installation: npm
  • Swagger-Client version: 3.8.23
  • Swagger/OpenAPI version: Swagger 2.0
Content & configuration

Swagger-Client usage:

const Swagger  = require('swagger-client');
const jsYaml = require('@kyleshockey/js-yaml')

const spec = `
swagger: "2.0"
info:
  title: Sample API
  description: API description in Markdown.
  version: 1.0.0
host: api.example.com
schemes:
- https
paths:
  /ping:
    get:
      summary: Checks if the server is alive
      parameters:
      - in: header
        name: X-Request-ID
        schema:
          type: string
          format: uuid
        required: true
`;

const json = jsYaml.safeLoad(spec);

Swagger({ spec: json } ).then(client => {
    client.apis.default.get_ping({}, { headers: { "X-Request-ID" : "012345678-CODE-F00D-0A1E-CAFE00C0FFEE" } })})
        .then(result => {
            console.log( result )
        })
        .catch(err => {
            console.log(err);
        })
        .catch(err => {
            console.log("Got error: " + err);
        });
Describe the bug you're encountering

When the script is run. The following error will get thrown

Error: Required parameter X-Request-ID is not provided 

This is provided in the header, I've tried with request interceptors as well. If I replicate the 'header' in the parameters the validation passes but is sending the data in an incorrect part of the spec.

To reproduce...

Run the attached js snippet

Expected behavior

Request is processed

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the attached JavaScript snippet with the stated Swagger 2.0 document and Node.js environment, then trace the required-parameter validation for the X-Request-ID header. Confirm whether the header supplied through the request options is recognized, and verify that the request is processed without reporting the required parameter as missing.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.