OpenAPITools / OpenAPITools/openapi-generator

AbstractTypeScriptClientCodegen.java@223 returns empty string in case name = "="

Open
#4,925 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: TypeScript Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

When generating properties with a name of "=" into any of Typescript options that property disappears from generated code

Diving deeper into the code I realized its AbstractTypeScriptClientCodegen to blame and more specifically line 223 where after passing "=" to sanitizeName function, it returns an empty string. This results in the whole public String toParamName(String name) function returns empty string too, which I believe is bad behaviour.

Resulting code is invalid due to syntax issue for example:
someFunction(one: string, two: string, :string)

For pure unblocking purposes I introduced, but I believe there is a better solution to that instead

        if ("=".equals(name)) {
            name = "equals";
        }
openapi-generator version

4.2.3-SNAPSHOT (master)

OpenAPI declaration file content or url

https://gist.github.com/krizic/98db135224e4a84d07ab9ac58d91b720

Command line used for generation

java -jar openapi-generator-cli.jar generate -i full_documentation.json -g typescript-fetch -o temp
java -jar openapi-generator-cli.jar generate -i full_documentation.json -g typescript-axios -o temp

Steps to reproduce

After generating please open any of the generated APIs, typescript should already highlit all the function with invalid syntax (please ignore other errors)

Suggest a fix

AbstractTypeScriptClientCodegen.toParamName should in no case result with empty string.
Internal sanitizeName call should be changed/replaced to not turn "=" into ""

I agree that "=" seems like a poor convention for naming parameters, however, it is in this case being used by https://strapi.io/
Screenshot from 2020-01-04 21-57-12

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 in AbstractTypeScriptClientCodegen.java around line 223, then trace toParamName and its sanitizeName call. Reproduce with the provided OpenAPI declaration and the typescript-fetch or typescript-axios generation commands. Done means a property named "=" no longer disappears and the generated TypeScript has no empty parameter name or resulting syntax error.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi, typescript
Domain
api, tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.