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.75k stars 6.56k forks source link

[Question for help] How to modify Java code generated by OpenAPI? #16813

Open KaitaoQiu opened 1 year ago

KaitaoQiu commented 1 year ago

Hello, It is not a bug or feature requirement, just ask for help...

I am new to OpenAPI and I have a question about how to modify the Java code generated by OpenAPI. I have generated some SDK code using OpenAPI generator, but I want to change some things like the constructor to match the core-api (which is also generated by OpenAPI). Is there any way to do that?

Or is there any simple open-api generator docker sample that I can follow? I find this project a bit complex and I can't find a suitable doc. Any blog/stackoverflow/everthing about java generator on docker is very helpful for me ; (

Any suggestions would be greatly appreciated. Thank you very much.

wojciechkl commented 1 year ago

It's your lucky day - I just had to change some generated code because default templates does not handle response encodings well.

There is quite good documentation describing template customization here: https://openapi-generator.tech/docs/templating.

Generally changing generated code is as easy/as hard as providing your own mustache template (https://www.baeldung.com/mustache) for file that you want to override. Default templates for java can be found here:

https://github.com/OpenAPITools/openapi-generator/tree/master/modules/openapi-generator/src/main/resources/Java