openapi-typescript icon indicating copy to clipboard operation
openapi-typescript copied to clipboard

Parameter components have wrong name (?)

Open OliverJAsh opened this issue 8 months ago • 1 comments

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

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

Extra

OliverJAsh avatar Mar 02 '25 14:03 OliverJAsh

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.

duncanbeevers avatar Mar 03 '25 21:03 duncanbeevers