Skip to content

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

@TzelaDayan

Description

@TzelaDayan

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions