Skip to content

Types missing for parameters with duplicate names but different locations #1498

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
2 tasks done
JohannCooper opened this issue Jan 2, 2024 · 1 comment
Closed
2 tasks done
Labels
bug Something isn't working openapi-ts Relevant to the openapi-typescript library

Comments

@JohannCooper
Copy link

JohannCooper commented Jan 2, 2024

Description

If an operation contains two parameters with the same name but different locations (in), types will only be generated for one of the parameters. According the OpenAPI Specification v3.0.3, "a unique parameter is defined by a combination of a name and location" (source).

Name Version
openapi-typescript 6.7.3
Node.js 18.16.1
OS + version Ubuntu 23.10

Reproduction

Using the schema below, you will see that a parameter type is only generated for the parameter with in: path.

openapi: 3.1.0
info:
  title: Sample API
  version: 0.1.9
  license:
    {
      "name": "Sample License",
      "identifier": "Sample-License",
      "url": "https://license.foobar.com",
    }
servers:
  - url: http://api.foobar.com/v1
paths:
  /users/{userId}:
    get:
      security:
        - {}
      operationId: retrieveUser
      summary: Returns a user by ID.
      parameters:
        - name: userId
          in: query
          required: true
          description: The ID of the user to return.
          schema:
            type: integer
            format: int64
            minimum: 1
        - name: userId
          in: path
          required: true
          description: The ID of the user to return.
          schema:
            type: integer
            format: int64
            minimum: 1
      responses:
        "200":
          description: A user object.
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: integer
                    format: int64
                    example: 4
                  name:
                    type: string
                    example: Jessica Smith
        "400":
          description: The specified user ID is invalid (not a number).
        "404":
          description: A user with the specified ID was not found.
        default:
          description: Unexpected error

Expected result

A type is generated for BOTH parameters, despite their non-unique names.

Checklist

@JohannCooper JohannCooper added bug Something isn't working openapi-ts Relevant to the openapi-typescript library labels Jan 2, 2024
@drwpow drwpow mentioned this issue Jan 19, 2024
3 tasks
drwpow added a commit that referenced this issue Jan 19, 2024
Fix missing parameters (#1498)
@drwpow
Copy link
Contributor

drwpow commented Jan 19, 2024

Fixed and released in 6.7.4!

@drwpow drwpow closed this as completed Jan 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working openapi-ts Relevant to the openapi-typescript library
Projects
None yet
Development

No branches or pull requests

2 participants