@@ -127,6 +127,26 @@ public String toApiName(String name) {
127127 }
128128
129129
130+ /**
131+ * Centralizes the handling of configuration booleans and updates additionalProperties accordingly.
132+ */
133+ private void handleConfigBooleans () {
134+ this .useClassLevelBeanValidation = convertPropertyToBoolean (USE_CLASS_LEVEL_BEAN_VALIDATION );
135+ this .addServletRequest = convertPropertyToBoolean (ADD_SERVLET_REQUEST );
136+ this .addBindingResult = convertPropertyToBoolean (ADD_BINDING_RESULT );
137+ this .useLombokAnnotations = convertPropertyToBoolean (USE_LOMBOK_ANNOTATIONS );
138+ this .useWithModifiers = convertPropertyToBoolean (USE_WITH_MODIFIERS );
139+ this .useProtectedFields = convertPropertyToBoolean (USE_PROTECTED_FIELDS );
140+
141+ this .additionalProperties .put (USE_CLASS_LEVEL_BEAN_VALIDATION , this .useClassLevelBeanValidation );
142+ this .additionalProperties .put (ADD_SERVLET_REQUEST , this .addServletRequest );
143+ this .additionalProperties .put (ADD_BINDING_RESULT , this .addBindingResult );
144+ this .additionalProperties .put (USE_LOMBOK_ANNOTATIONS , this .useLombokAnnotations );
145+ this .additionalProperties .put (USE_WITH_MODIFIERS , this .useWithModifiers );
146+ this .additionalProperties .put (USE_PROTECTED_FIELDS , this .useProtectedFields );
147+ this .additionalProperties .put ("modelFieldsVisibility" , this .useProtectedFields ? "protected" : "private" );
148+ }
149+
130150 @ Override
131151 public void processOpts () {
132152 super .processOpts ();
@@ -137,7 +157,6 @@ public void processOpts() {
137157 // <supportingFilesToGenerate>ApiUtil.java present or not</supportingFilesToGenerate>
138158 // <generateSupportingFiles>true or false</generateSupportingFiles>
139159 final String supFiles = GlobalSettings .getProperty (CodegenConstants .SUPPORTING_FILES );
140- // cleared by <generateSuportingFiles>false</generateSuportingFiles>
141160 final boolean useApiUtil = supFiles != null && (supFiles .isEmpty ()
142161 ? needApiUtil () // set to empty by <generateSuportingFiles>true</generateSuportingFiles>
143162 : supFiles .contains ("ApiUtil.java" )); // set by <supportingFilesToGenerate/>
@@ -146,37 +165,31 @@ public void processOpts() {
146165 this .supportingFiles
147166 .removeIf (sf -> "apiUtil.mustache" .equals (sf .getTemplateFile ()));
148167 }
149-
150168 writePropertyBack ("useApiUtil" , useApiUtil );
151-
152169 final var serializerTemplate = "BigDecimalCustomSerializer" ;
153170 this .supportingFiles .add (new SupportingFile (
154171 serializerTemplate + MUSTACHE_EXTENSION ,
155172 (sourceFolder + File .separator + modelPackage ).replace ("." , File .separator ),
156173 serializerTemplate + JAVA_EXTENSION
157174 ));
158-
159- // Adding Webhook related models to supporting files
160175 final var webhookResponseTemplate = "WebhookResponse" ;
161176 this .supportingFiles .add (new SupportingFile (webhookResponseTemplate + MUSTACHE_EXTENSION ,
162177 (sourceFolder + File .separator + modelPackage ).replace ("." , File .separator ),
163178 webhookResponseTemplate + JAVA_EXTENSION ));
164-
165179 final var servletContentTemplate = "ServletContent" ;
166180 this .supportingFiles .add (new SupportingFile (servletContentTemplate + MUSTACHE_EXTENSION ,
167181 (sourceFolder + File .separator + modelPackage ).replace ("." , File .separator ),
168182 servletContentTemplate + JAVA_EXTENSION ));
169-
170183 final var posthookRequestTemplate = "PosthookRequest" ;
171184 this .supportingFiles .add (new SupportingFile (posthookRequestTemplate + MUSTACHE_EXTENSION ,
172185 (sourceFolder + File .separator + modelPackage ).replace ("." , File .separator ),
173186 posthookRequestTemplate + JAVA_EXTENSION ));
174-
175187 final var prehookRequestTemplate = "PrehookRequest" ;
176188 this .supportingFiles .add (new SupportingFile (prehookRequestTemplate + MUSTACHE_EXTENSION ,
177189 (sourceFolder + File .separator + modelPackage ).replace ("." , File .separator ),
178190 prehookRequestTemplate + JAVA_EXTENSION ));
179-
191+ // Centralized config boolean handling
192+ handleConfigBooleans ();
180193 this .additionalProperties .put ("indent4" , new IndentedLambda (4 , " " , true , true ));
181194 this .additionalProperties .put ("newLine4" , new BoatSpringCodeGen .NewLineIndent (4 , " " ));
182195 this .additionalProperties .put ("indent8" , new IndentedLambda (8 , " " , true , true ));
0 commit comments