openapi-typescript-codegen icon indicating copy to clipboard operation
openapi-typescript-codegen copied to clipboard

Method Names postfixed with Numbers

Open donkey-donkey opened this issue 1 year ago • 7 comments

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

donkey-donkey avatar Dec 23 '23 15:12 donkey-donkey

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

andreujuanc avatar Feb 18 '24 23:02 andreujuanc

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

mrlubos avatar Feb 20 '24 11:02 mrlubos

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.

andreujuanc avatar Feb 20 '24 11:02 andreujuanc

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

askvortcov avatar Feb 20 '24 12:02 askvortcov

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

mrlubos avatar Feb 20 '24 12:02 mrlubos

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.

andreujuanc avatar Feb 20 '24 14:02 andreujuanc

@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

mrlubos avatar Feb 20 '24 14:02 mrlubos