Skip to content

OpenAPI parameter name of only an underscore results in missing parameter name in services.gen.ts and malformed type definition #726

Open
@Beauchaj

Description

@Beauchaj

Description

An OpenAPI Query Parameter with the name _ (or any _ within the parameter name) fails to generate the corresponding property name under services.gen.ts (Fetch client). Any instance of _ is being stripped from the resulting value (leading, trailing, or otherwise) in the translation of the snake_case OpenAPI parameter key to the camelCase property name, but if the parameter name is only _ the generated ts is broken.

Noting: If the parameter was _ the query parameter generated under services.gen.ts is:

      query: {
        _: data.,
      },

instead of

      query: {
        _: data._,
      },

Also noting: Using _ as a name or character parameter in OpenAPI queries does not break the OpenAPI specification.

Expected output

types.gen.ts

export type ReachableData = {
    /**
     * Optional parameter for avoiding caching
     */
    _?: unknown;
};

services.gen.ts

/**
 * Reachable?
 * Does nothing and returns No Content
 * @param data The data for the request.
 * @param data._ Optional parameter for avoiding caching
 * @returns void Success
 * @throws ApiError
 */
export const reachable = (data: ReachableData = {}): CancelablePromise<ReachableResponse> => { return __request(OpenAPI, {
    method: 'HEAD',
    url: '/reachable',
    query: {
        _: data._
    }
}); };

Instead got output

types.gen.ts

export type ReachableData = {
    /**
     * Optional parameter for avoiding caching
     */
    ?: unknown;
};

services.gen.ts

/**
 * Reachable?
 * Does nothing and returns No Content
 * @param data The data for the request.
 * @param data. Optional parameter for avoiding caching
 * @returns void Success
 * @throws ApiError
 */
export const reachable = (data: ReachableData = {}): CancelablePromise<ReachableResponse> => { return __request(OpenAPI, {
    method: 'HEAD',
    url: '/reachable',
    query: {
        _: data.
    }
}); };

OpenAPI specification (optional)

openapi: 3.1.0
info:
  title: Test API
  description: API for Test
  version: development
security:
  - test_auth:
      - default
paths:
  /reachable:
    head:
      summary: Reachable?
      description: Does nothing and returns No Content
      operationId: reachable
      security: []
      parameters:
        - name: _
          in: query
          description: Optional parameter for avoiding caching
          schema: {}
      responses:
        '204':
          description: Success

Configuration

Just defaults, so standard fetch client generation

npx @hey-api/openapi-ts -i path/to/openapi.yaml -o src/client

System information (optional)

  • OS: Linuxmint
  • Version
    Description: Linux Mint 21.3
    Release: 21.3
    Codename: virginia
  • Node version: v20.14.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🔥Something isn't workinghelp wanted 🙋This issue is unlikely to be prioritized, please contribute a pull request if you'd like it resolved

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions