OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.8k stars 6.58k forks source link

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

Open krizic opened 4 years ago

krizic commented 4 years ago

Bug Report Checklist

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

auto-labeler[bot] commented 4 years ago

👍 Thanks for opening this issue! 🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.