swagger-api / swagger-api/swagger-codegen

How to prevent changing model fields naming (swagger-codegen-cli.jar generate)

Open
#12,204 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Hello, swagger-codegen Team,

I am investigating swagger-codegen API generation and using such script:
java -jar ./swagger-codegen-cli.jar generate -i ./.openapi3.json -l typescript-angular -o ./generated

As a result of the generation I am getting ApplicationUser model with a such field in camelCase - firstName:
image

But in our backend it is called first_name in snaked_case:
image

The trouble is that we are using typescript-angular and when the backend response is:
image

I cannot declare the field in a such way, because of the typescript
image

So it is not feasible to use the lib, because the generated models were changed, but the generated APIs returns the data in the same way how it is stored in the backend. Is it possible to prevent changing of the field names?

Best Regards

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 with the shown swagger-codegen-cli.jar generate command, using ./.openapi3.json and the typescript-angular generator, and inspect the generated ApplicationUser model. Compare its firstName field with the backend's first_name response and determine whether generation can preserve the source name. Done means the generated model accepts the backend response without changing the field name.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.