kroegerama / openapi-kgen

Generate modern API Clients in Kotlin from OpenAPI specifications. Supports OpenAPI >= 3.0.0.
Apache License 2.0
22 stars 4 forks source link

Better generated names. #5

Closed ArjixWasTaken closed 1 year ago

ArjixWasTaken commented 1 year ago

My API methods are already fluently named, so the generated names suck.

Original API image

Generated client: AuthApi.postApiAuthLogin, AuthApi.postApiAuthLogout, AuthApi.postApiAuthRefresh

would be nicer is they were just named AuthApi.Login, AuthApi.Logout, AuthApi.Refresh

ArjixWasTaken commented 1 year ago

maybe add a naming template in the plugin params? that way we can have whatever naming scheme we want

kroegerama commented 1 year ago

Hi there, thanks for the suggestion! Unfortunately, this feature would require a lot of rework. I use this generator for a lot of projects and am actually quite happy with the current state. But you are right, the auto-generated names are not really nice to read or use.

Can't you just use the operationId property for each operation in your spec? That's what we use in all our specs.

For example:

/my_endpoint_name_sucks:
  get:
    operationId: hello
    ...

Would generate MyApi.hello()

ArjixWasTaken commented 1 year ago

That is exactly what I needed! Thank you so much!!

I am not really that knowledgeable about OpenAPI, it is auto generated by swagger for me, so I didn't know that was an option. This issue has been resolved.

ArjixWasTaken commented 1 year ago

Commenting here instead of opening a new issue since this ain't an issue

On another note, the spacing of the generated code is odd image

kroegerama commented 1 year ago

Yeah, that's because of the library I use for the Kotlin code generation: Kotlin Poet.

You could run a code formatter on the generated code, if you care enough. Something like: Ktlint