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

OpenAPI parameter name of only an underscore results in missing parameter name in services.gen.ts #127

Open
Beauchaj opened this issue Jun 24, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@Beauchaj
Copy link

Beauchaj commented Jun 24, 2024

Describe the bug
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.

To Reproduce
Steps to reproduce the behavior:

Call the following openapi yaml using

yarn openapi-rq -i ./openapi.yaml

OpenAPI spec file

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

Expected behavior
A clear and concise description of what you expected to happen.

Expected output

export class DefaultService {
  /**
   * 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
   */
  public static reachable(
    data: ReachableData = {},
  ): CancelablePromise<ReachableResponse> {
    return __request(OpenAPI, {
      method: "HEAD",
      url: "/reachable",
      query: {
        _: data._,
      },
    });
  }
}

Instead got output

export class DefaultService {
    /**
     * 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
     */
    public static reachable(data: ReachableData = {}): CancelablePromise<ReachableResponse> {
        return __request(OpenAPI, {
            method: 'HEAD',
            url: '/reachable',
            query: {
                _: data.
            }
        });
    }
    
}

Screenshots
If applicable, add screenshots or logs to help explain your problem.

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

Relevant package versions:

  "devDependencies": {
    "@7nohe/openapi-react-query-codegen": "^1.4.1",
    "@tanstack/eslint-plugin-query": "^5.43.1",
    "@types/react": "^18.0.27",
    "@types/react-dom": "^18.0.10",
    "commander": "^12.1.0",
    "ts-morph": "^22.0.0",
    "typescript": "^5.1.6",
  },
  "packageManager": "[email protected]"
@Beauchaj Beauchaj changed the title Underscores stripped from parameter names in services.gen.ts OpenAPI parameter name of only an underscore results in missing parameter name in services.gen.ts Jun 25, 2024
@Beauchaj
Copy link
Author

Now raised in hey-api/openapi-ts#726

@7nohe 7nohe added the bug Something isn't working label Aug 6, 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
Projects
None yet
Development

No branches or pull requests

2 participants