Forum Discussion

adcf81t's avatar
adcf81t
Frequent Visitor
4 years ago

Develop Custom code generator in Java 11

Hello Gurus,

We want to create CodeGen+, a stand-alone utility software (or IDE plugin) in Java to automatically generate boiler-plate Java source code (preferably in Java 11) to eliminate much of API developer's routine coding tasks to add logging, role-based authorization access code, basic metric feature using Spring Actuator, Oracle database store procedure call and resultset object mapping using MyBatis etc. This CodeGen+ tool will be used in-house for any new greenfield API development as a starting point.

 

We identified there may be two options as detailed below :
Option1 : Template driven custom code generator in Java 11, just like SwaggerHub Code generator. This option is dependent on enhancing the template (HandleBars, Moustache ?) capabilities to add more functionality as listed below. It takes Open API Spec file in JSON/YAML as input. Is this a feasible option ?

 

Option2: Uses the generated Java code from SwaggerHub portal and extend that code to add additional capabilities as listed below. Is this a feasible option ?

 

• Uses property file as input for Oracle JDBC connection and store proc signatures.
• Uses property file as input for MyBatis SQL mapping input to map store proc result set to a POJO
• Uses XML configuration for role-based authorization for URL endpoint;
• Uses common config : AppId etc (static list), target package name, versioning config – fed from property file
• Uses property file as input for logging feature using logback
• Uses property file as input (if needed) for Spring Actuator basic Metrics.

 

Generated Java 11 code should contain basic metric features following Spring Actuator Metrics, logging feature, role-based authorization access code, Oracle database store procedure call and resultset object mapping using MyBatis etc.


Looking for help and further direction in terms of feasibility of this initiative. 
Any help or pointer is highly appreciated.
Thanks in advance !

  • Hi asadc 

     

    It can be exciting to develop code generators, and it sounds like you want to build a template more than an engine.

    Either option you suggest can be fine, as it'll depend on which is easier for you folks to maintain.

    SwaggerHub's code generating features are based on the open source SwaggerCodegen project, which is a good place to start exploring.

    There are already a few Java templates to start from, you can find them over here.