OpenAPITools / OpenAPITools/openapi-generator

[REQ][typescript-angular] Query param case should be independent of generated field names

Open
#5,785 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement: Feature
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Is your feature request related to a problem? Please describe.

I would like to be able to use kebab-case field names as URL query params, while using camelCase in typescript code.

This is related to #4065 and #4748.

I have the following OpenAPI spec:

openapi: 3.0.1
info:
  title: Example spec
  version: v0.0.1
paths:
  /:
    get:
      operationId: doThing
      parameters:
        - name: myInstance
          in: query
          required: true
          schema:
            $ref: '#/components/schemas/MyClass'
      responses:
        '200':
          description: ""
          content:
            text/plain:
                schema:
                  type: string
components:
  schemas:
    MyClass:
      required:
        - some-field
      type: object
      properties:
        some-field:
          type: string

Using the typescript-angular generator creates classes like this in typescript (here written by hand for demo purposes):

export interface MyClass { 
    some_field: string;
}

export class SomeService {
  public doThing(myInstance: MyClass, /* ... */) {
    // ...
  }
}

Assuming:

let someService = new SomeService(...);
let myInstance = {
  some_field: "abc"
};

I would expect that calling someService.doThing(myInstance) would call:
http://localhost:8080?some-field=abc
Instead, it calls:
http://localhost:8080?some_field=abc

Obviously, the client does not recognize some_field and the whole thing breaks apart.

Describe the solution you'd like

I would like to be able to specify what case the model fields should be and the case of the query params should be decided based on the OpenAPI spec field names.

Describe alternatives you've considered

The only alternative I can think of is to not use kebab-case in URLs at all. That, however, does not solve the issue (even if it was a good idea) because I would still like to be able to decide that typescript code should (e.g.) use snake_case and URL should use PascalCase (or any other combinations).

Additional context

A feature like this would help maintain code standards across a repository. It's jarring when all of my code uses camelCase for fields, while the auto-generated part uses snake_case. Even if I made the auto-generated code use camelCase, that would make the URLs worse for SEO purposes and would violate the general consensus that URL params should be hyphenated.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the typescript-angular generator logic for model field naming and query-parameter serialization. Read related issues #4065 and #4748, then define regression coverage showing that generated TypeScript names can use one case while query keys preserve the OpenAPI field names; done when the example emits some-field=abc.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, openapi, typescript
Domain
api, tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.