From 328eaf4e96bb7a24566feef8f35ba95f1470d21b Mon Sep 17 00:00:00 2001 From: Marcelo Boveto Shima Date: Wed, 21 Feb 2024 14:04:00 -0300 Subject: [PATCH] add addApplicationPropertiesProperty needle --- generators/server/types.d.ts | 1 + generators/spring-boot/generator.ts | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/generators/server/types.d.ts b/generators/server/types.d.ts index e4fa9380562e..5f78ecbf4328 100644 --- a/generators/server/types.d.ts +++ b/generators/server/types.d.ts @@ -30,6 +30,7 @@ export type SpringBootSourceType = GradleSourceType & addIntegrationTestAnnotation?({ package, annotation }: { package?: string; annotation: string }): void; addAllowBlockingCallsInside?({ classPath, method }: { classPath: string; method: string }): void; addApplicationPropertiesContent?(content: ApplicationPropertiesNeedles): void; + addApplicationPropertiesProperty?({ propertyName, propertyType }: { propertyName: string; propertyType: string }): void; }; type CacheProviderApplication = OptionWithDerivedProperties< diff --git a/generators/spring-boot/generator.ts b/generators/spring-boot/generator.ts index 7673933bcab8..e9cbd2e98282 100644 --- a/generators/spring-boot/generator.ts +++ b/generators/spring-boot/generator.ts @@ -41,6 +41,7 @@ import { getPrimaryKeyValue, getSpecificationBuildForType, insertContentIntoApplicationProperties, + javaBeanCase, } from '../server/support/index.js'; import { addJavaAnnotation, generateKeyStore } from '../java/support/index.js'; import { createNeedleCallback, mutateData } from '../base/support/index.js'; @@ -216,6 +217,19 @@ export default class SpringBootGenerator extends BaseApplicationGenerator { `${application.javaPackageSrcDir}config/ApplicationProperties.java`, insertContentIntoApplicationProperties(needles), ); + source.addApplicationPropertiesProperty = ({ propertyName, propertyType }) => + source.addApplicationPropertiesContent!({ + property: `private ${propertyType} ${propertyName};`, + propertyGetter: ` +public ${propertyType} get${javaBeanCase(propertyName)}() { + return ${propertyName}; +} + +public void set${javaBeanCase(propertyName)}(${propertyType} ${propertyName}) { + this.${propertyName} = ${propertyName}; +} +`, + }); }, }); }