swagger-api / swagger-api/swagger-client

swagger-client npm module fails to resolve $ref for parameters

Open
#3,950 0 comments 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

when using the swagger-client npm module, the client fails to resolve $ref references for parameters defined in the OpenAPI specification.

For example, in the case of Open Api Contract 1, the query parameters are not being included in the URL, whereas in Open Api Contract 2, they are correctly passed.

        const response = SwaggerClient.execute({
            spec: openApiContract,
            method: '...',
            pathName: '...',
            {
               limitParam: 10,
               offsetParam: 5
            },

            securities: {...},
            attachContentTypeForEmptyPayload: true,

            requestContentType: 'application/json',
            responseContentType: 'application/json'
        });
Open Api Contract 1:
openapi: 3.0.0
info:
  title: Sample API
  version: 1.0.0
components:
  parameters:
    limitParam:
      name: limit
      in: query
      description: Limits the number of returned results
      required: false
      schema:
        type: integer
        format: int32
    offsetParam:
      name: offset
      in: query
      description: Offset from which to start returned results
      required: false
      schema:
        type: integer
        format: int32
paths:
  /items:
    get:
      summary: Get items
      parameters:
        - $ref: '#/components/parameters/limitParam'
        - $ref: '#/components/parameters/offsetParam'
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: array
                items:
                  type: object
                  properties:
                    id:
                      type: integer
                    name:
                      type: string

Open Api Contract 2:
openapi: 3.0.0
info:
  title: Sample API
  version: 1.0.0
paths:
  /items:
    get:
      summary: Get items
      parameters:
        - name: limit
          in: query
          description: Limits the number of returned results
          required: false
          schema:
            type: integer
            format: int32
        - name: offset
          in: query
          description: Offset from which to start returned results
          required: false
          schema:
            type: integer
            format: int32
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: array
                items:
                  type: object
                  properties:
                    id:
                      type: integer
                    name:
                      type: string

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 reproducing the issue with Open Api Contract 1 and Open Api Contract 2 using SwaggerClient.execute. Trace how parameter references under components.parameters are resolved before the request URL is built. Done means the referenced limit and offset parameters are included in the URL as they are for inline parameters.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.