Skip to content

lb4 openapi generator produces invalid TypeScript code when OpenAPI parameters contain hyphens #11887

Open

Description

@aaqilniz

Bug Description

When generating server controllers or services using the lb4 openapi generator from an OpenAPI specification containing query or path parameters with hyphens (kebab-case, like limit-number or status-code), the code generator incorrectly emits literal code containing hyphens (e.g., limit-number, status-code) directly inside the TypeScript method body call arguments instead of sanitizing/camelCasing them into valid TypeScript identifiers (limitNumber, statusCode).

This causes immediate compilation/syntax errors.

Steps to Reproduce

Create an OpenAPI 3.0 specification JSON file (openapi.json) with an endpoint having hyphenated query parameters:

{
  "openapi": "3.0.3",
  "info": {
    "title": "Hyphenated Bug API",
    "version": "1.0.0"
  },
  "paths": {
    "/customers": {
      "get": {
        "operationId": "getCustomers",
        "parameters": [
          {
            "name": "limit-number",
            "in": "query",
            "schema": { "type": "integer" }
          },
          {
            "name": "status-code",
            "in": "query",
            "schema": { "type": "string" }
          }
        ],
        "responses": {
          "200": { "description": "OK" }
        }
      }
    }
  }
}
  1. Run the LoopBack OpenAPI generator command pointing to this spec: lb4 openapi openapi.json
  2. Inspect the generated Controller file.

Current Output (Buggy Code)

The controller method tries to pass raw hyphenated strings as variable names into the service layer call:

 async getCustomers(
    @param({
      name: 'limit-number',
      in: 'query',
      // ...
    }) limitNumber: number | undefined, 
    @param({
      name: 'status-code',
      in: 'query',
      // ...
    }) statusCode: string | undefined
  ): Promise<any[]> {
       // BUG: TypeScript treats 'limit-number' and 'status-code' as invalid mathematical subtraction expressions
       return this.openApiService.getCustomers(limit-number, status-code);  
  }

Expected Output

The generated controller should correctly use the sanitized camelCase parameter identifiers (limitNumber, statusCode) inside the implementation body:

async getCustomers(...): Promise<any[]> {
       return this.openApiService.getCustomers(limitNumber, statusCode);  
  }

Activity

  1. aaqilniz commented on Nov 8, 2026

    @aaqilniz
    ContributorAuthor

    Here is a PR #10427 to address this issue.

    The fix updates the OpenAPI generator logic to ensure parameter names are properly sanitized into camelCase identifiers (argName) before emitting method body invocation arguments, resolving the invalid TypeScript syntax when handling hyphenated parameters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions