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.42k stars 6.48k forks source link

[BUG][Java][Spring] Spring generator generates invalid class names that start with numbers #13888

Open LarsWigger opened 1 year ago

LarsWigger commented 1 year ago

Bug Report Checklist

Description

I downloaded the .jar on Windows and used it to generate a spring boot project. To my surprise, this project does not even compile (generation itself is successful). The reason is an edge case in the api definition: Some of the api urls start with a number (2faDevices, for example). The generated controller interface is then called 2faDevicesApiController, which is not a valid name for a class because it starts with a number. This should not be the default behaviour.

openapi-generator version

Version 6.2.1

Reproduction

I cannot provide concrete data to reproduce the issue, but anyone familiar with the tool should be able to easily reproduce it themselves.

Suggest a fix

There are two possible solutions:

Mintas commented 1 year ago

I dont think, this is a good point for implementing in generator itself. Is it possible to edit spec and add tags to paths? https://swagger.io/docs/specification/grouping-operations-with-tags/ Try to combine with useTags = true configOption and set the name You like. https://openapi-generator.tech/docs/generators/spring/#:~:text=true-,useTags,-use%20tags%20for

LarsWigger commented 1 year ago

I do not understand what you mean. Other parts of the code were already generated the second way I describe it (Twofa), it was missing in just a few places, not all of them. I also do not see why this would be anything but a straightforward fix.

If the generator requires me to change the spec even though the generator could just deal with this, the generator failed its purpose. Given that most people likely just have basic requirements, this should be handled by default if possible (which it is).

Also: I am not looking for a fix since I no longer need this, I just reported it so it can be fixed for other users.