Skip to content
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

Parameter components have wrong name (?) #2187

Open
2 tasks done
OliverJAsh opened this issue Mar 2, 2025 · 1 comment
Open
2 tasks done

Parameter components have wrong name (?) #2187

OliverJAsh opened this issue Mar 2, 2025 · 1 comment
Labels
bug Something isn't working openapi-ts Relevant to the openapi-typescript library

Comments

@OliverJAsh
Copy link

openapi-typescript version

7.4.4

Node.js version

22.13.1

OS + version

macOS

Description

I expected the generated types to use the name of the parameter, but they don't. Is this intended?

Reproduction

packages/domain/specs/unsplash.json:

{
  "openapi": "3.0.0",
  "components": {
    "parameters": {
      "perPageParam": {
        "name": "per_page",
        "in": "query",
        "schema": {
          "type": "integer",
          "minimum": 1,
          "default": 10
        }
      }
    }
  }
}

Expected result

Result:

packages/domain/src/gen/unsplash.ts:

/**
 * This file was auto-generated by openapi-typescript.
 * Do not make direct changes to the file.
 */

export type paths = Record<string, never>;
export type webhooks = Record<string, never>;
export interface components {
    schemas: never;
    responses: never;
    parameters: {
        readonly perPageParam: number;
    };
    requestBodies: never;
    headers: never;
    pathItems: never;
}
export type $defs = Record<string, never>;
export type operations = Record<string, never>;

I was hoping for this instead:

     parameters: {
-        readonly perPageParam: number;
+        readonly per_page: number;
     };

Required

  • My OpenAPI schema is valid and passes the Redocly validator (npx @redocly/cli@latest lint)

Extra

@OliverJAsh OliverJAsh added bug Something isn't working openapi-ts Relevant to the openapi-typescript library labels Mar 2, 2025
@duncanbeevers
Copy link
Contributor

This is related to the way that $refs are handled in a very naive way.
This PR is a step towards aligning the meaning of the JSON Pointer with the intended referenced into the generated types.
I'll ensure the test validate that the parameter's name is used, and not its pointed-to location within the OpenAPI document.

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