ferdikoomen / openapi-typescript-codegen

NodeJS library that generates Typescript or Javascript clients based on the OpenAPI specification
MIT License
2.88k stars 520 forks source link

Method Names postfixed with Numbers #1952

Open donkey-donkey opened 8 months ago

donkey-donkey commented 8 months ago

When we use a get /apples/:id and a get all /apples/ the second one listed in the schema will turn into apples1 function in the generated code.

isnt the openapi spec to have the endpoints both named apples? but then we get silly apples1 function name? am i missing something?

thanks

andreujuanc commented 6 months ago

I think it's because both are under the same Tag? I'm currently looking for a way to set an operationId on my spec to set the method name to something better.

EDIT: See https://github.com/ferdikoomen/openapi-typescript-codegen/issues/314

mrlubos commented 6 months ago

@donkey-donkey @andreujuanc can you try our fork if that works as you'd expect?

andreujuanc commented 6 months ago

Can't at the moment. But just for the record, the current lib will use the operationId for naming, so that should be good enough if you have control over the spec.

EDIT: Gave it a star. Will check as soon as I can.

askvortcov commented 6 months ago

As @mrlubos pointed out, this might be resolved by https://github.com/ferdikoomen/openapi-typescript-codegen/pull/2043.

mrlubos commented 6 months ago

You'll want to set the new --useOperationId flag to false to try the alternative method name generator. It's available in the latest release, please let us know whether it worked if you try it

andreujuanc commented 6 months ago

I think OP was asking "why the number suffix", and the answer is because I believe there is no operationId on their spec, and the paths are both on the same Tags. Ignoring the operationId would yield no change to the generated methods.

mrlubos commented 6 months ago

@andreujuanc the pull request also changes the replacement pattern so I'd expect a different result for their use case, but will need them to try it since I can't see their OpenAPI spec