Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 28 additions & 9 deletions generators/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,8 @@ module.exports = class extends BaseGenerator {
];
this.generateMainJavaCode(configOptions, mainJavaTemplates);

const mainResTemplates = [
'application.properties',
'application-local.properties',
'logback-spring.xml'
];
const mainResTemplates = this._getResourceFileTemplates(configOptions)

this.generateMainResCode(configOptions, mainResTemplates);

const testJavaTemplates = [
Expand All @@ -214,13 +211,35 @@ module.exports = class extends BaseGenerator {
}
this.generateTestJavaCode(configOptions, testJavaTemplates);

const testResTemplates = [
'application-test.properties',
'logback-test.xml'
];
const testResTemplates = this._getResourceFileTestTemplates(configOptions)

this.generateTestResCode(configOptions, testResTemplates);
}

_getResourceFileTestTemplates(configOptions) {
let testResYamlTemplates = []

if (configOptions.propFileFormat === 'yaml') {
testResYamlTemplates = ['application-test.yml']
}
else {
testResYamlTemplates = ['application-test.properties']
}
return [...testResYamlTemplates, 'logback-test.xml']
}

_getResourceFileTemplates(configOptions) {
let mainResTemplates = []

if (configOptions.propFileFormat === 'yaml') {
mainResTemplates = ['application.yml', 'application-local.yml']
} else {
mainResTemplates = ['application.properties', 'application-local.properties']
}

return [...mainResTemplates, 'logback-spring.xml']
}

_generateDbMigrationConfig(configOptions) {
if(configOptions.dbMigrationTool === 'flywaydb') {
let vendor = configOptions.databaseType;
Expand Down
15 changes: 15 additions & 0 deletions generators/server/prompts.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,21 @@ function prompting() {
}
],
default: 'maven'
},
{
type: 'list',
name: 'propFileFormat',
message: 'which format do you want to use for configuration files?',
choices: [
{
value: 'props',
name: 'Property File'
},
{
value: 'yaml',
name: 'YAML'
}
]
}
];

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<%_ if (databaseType === 'postgresql') { _%>
spring:
datasource:
driver-class-name: org.postgresql.Driver
url: jdbc:postgresql://localhost:5432/appdb
<%_ } _%>
<%_ if (databaseType === 'mysql') { _%>
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/appdb
<%_ } _%>
<%_ if (databaseType === 'mariadb') { _%>
datasource:
driver-class-name: org.mariadb.jdbc.Driver
url: jdbc:mariadb://localhost:3306/appdb
<%_ } _%>
datasource:
username: appuser
password: secret

Comment on lines +1 to +20
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Broken YAML for non‑PostgreSQL paths; spring: missing for MySQL/MariaDB; misplaced username/password.

  • When databaseType is mysql or mariadb, spring: is not emitted, producing invalid YAML.
  • datasource.username/password are outside spring: for those branches.

Apply this consolidated structure (works for all DBs):

-<%_ if (databaseType === 'postgresql') { _%>
-spring:
-  datasource:
-    driver-class-name: org.postgresql.Driver
-    url: jdbc:postgresql://localhost:5432/appdb
-<%_ } _%>
-<%_ if (databaseType === 'mysql') { _%>
-  datasource:
-    driver-class-name: com.mysql.jdbc.Driver
-    url: jdbc:mysql://localhost:3306/appdb
-<%_ } _%>
-<%_ if (databaseType === 'mariadb') { _%>
-  datasource:
-    driver-class-name: org.mariadb.jdbc.Driver
-    url: jdbc:mariadb://localhost:3306/appdb
-<%_ } _%>
-  datasource:
-    username: appuser
-    password: secret
+spring:
+  datasource:
+    <%_ if (databaseType === 'postgresql') { _%>
+    driver-class-name: org.postgresql.Driver
+    url: jdbc:postgresql://localhost:5432/appdb
+    <%_ } _%>
+    <%_ if (databaseType === 'mysql') { _%>
+    driver-class-name: com.mysql.cj.jdbc.Driver
+    url: jdbc:mysql://localhost:3306/appdb
+    <%_ } _%>
+    <%_ if (databaseType === 'mariadb') { _%>
+    driver-class-name: org.mariadb.jdbc.Driver
+    url: jdbc:mariadb://localhost:3306/appdb
+    <%_ } _%>
+    username: appuser
+    password: secret
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<%_ if (databaseType === 'postgresql') { _%>
spring:
datasource:
driver-class-name: org.postgresql.Driver
url: jdbc:postgresql://localhost:5432/appdb
<%_ } _%>
<%_ if (databaseType === 'mysql') { _%>
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/appdb
<%_ } _%>
<%_ if (databaseType === 'mariadb') { _%>
datasource:
driver-class-name: org.mariadb.jdbc.Driver
url: jdbc:mariadb://localhost:3306/appdb
<%_ } _%>
datasource:
username: appuser
password: secret
spring:
datasource:
<%_ if (databaseType === 'postgresql') { _%>
driver-class-name: org.postgresql.Driver
url: jdbc:postgresql://localhost:5432/appdb
<%_ } _%>
<%_ if (databaseType === 'mysql') { _%>
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/appdb
<%_ } _%>
<%_ if (databaseType === 'mariadb') { _%>
driver-class-name: org.mariadb.jdbc.Driver
url: jdbc:mariadb://localhost:3306/appdb
<%_ } _%>
username: appuser
password: secret
🧰 Tools
🪛 YAMLlint (1.37.1)

[error] 2-2: syntax error: mapping values are not allowed here

(syntax)

🤖 Prompt for AI Agents
In generators/server/templates/app/src/main/resources/application-local.yml
around lines 1 to 20, the template emits a top-level spring: only for the
PostgreSQL branch causing invalid YAML for mysql/mariadb and leaves
username/password outside spring.datasource; restructure the template so there
is a single spring: block with one datasource: key (always emitted) and move
datasource.username and datasource.password under it, then inside the datasource
block conditionally set only driver-class-name and url per databaseType
(postgresql/mysql/mariadb) to avoid duplicated datasource keys and incorrect
indentation.

<%_ if (features.includes('localstack')) { _%>
###AWS
cloud:
aws:
region:
static: us-east-1
credentials:
secret-key: noop
access-key: noop
endpoint: http://localhost:4566
<%_ } _%>
Comment on lines +21 to +31
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

❓ Verification inconclusive

Nest LocalStack config under spring.cloud.aws; verify endpoint keys per version.

  • Current block is not under spring: causing invalid YAML if the DB branch didn’t emit spring: above.
  • Endpoint scoping may need service‑specific keys.

Minimal safe nesting:

-<%_ if (features.includes('localstack')) { _%>
-###AWS
-  cloud:
-    aws:
+<%_ if (features.includes('localstack')) { _%>
+  cloud:
+    aws:
       region:
         static: us-east-1
       credentials:
         secret-key: noop
         access-key: noop
-      endpoint: http://localhost:4566
+      endpoint: http://localhost:4566
+      # If using Spring Cloud AWS 3.x+, prefer service-specific endpoints:
+      # sqs:
+      #   endpoint: http://localhost:4566
+      # sns:
+      #   endpoint: http://localhost:4566
+      # s3:
+      #   endpoint: http://localhost:4566
 <%_ } _%>

Nest LocalStack config under spring.cloud.aws; prefer service-specific endpoints for SC-AWS 3.x.

Move the LocalStack block in generators/server/templates/app/src/main/resources/application-local.yml so its properties are under spring: cloud: aws: — Spring Cloud AWS 3.x migrated cloud.aws.*spring.cloud.aws.*. (docs.awspring.io)

Prefer service-specific endpoints (e.g. spring.cloud.aws.sqs.endpoint, spring.cloud.aws.sns.endpoint, spring.cloud.aws.s3.endpoint) or the global spring.cloud.aws.endpoint for auto-configured clients; docs show both patterns. (github.com)

If the project intentionally targets SC-AWS 2.x, keep cloud.aws.* or ensure the template emits a top-level spring: block to avoid invalid YAML. (docs.awspring.io)

🤖 Prompt for AI Agents
In generators/server/templates/app/src/main/resources/application-local.yml
around lines 21 to 31, the LocalStack properties are currently under top-level
`cloud.aws` which is invalid for Spring Cloud AWS 3.x; move these properties
under `spring.cloud.aws:` (or emit a top-level `spring:` block if the template
architecture requires it) and prefer service-specific endpoint keys such as
`spring.cloud.aws.sqs.endpoint`, `spring.cloud.aws.sns.endpoint`, and
`spring.cloud.aws.s3.endpoint` (or use `spring.cloud.aws.endpoint` for a global
override) while keeping credentials/region under
`spring.cloud.aws.credentials`/`spring.cloud.aws.region`; if the project
intentionally targets SC-AWS 2.x, preserve `cloud.aws.*` or ensure the YAML
still emits a top-level `spring:` to avoid invalid configuration.

66 changes: 66 additions & 0 deletions generators/server/templates/app/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
spring:
application:
name: <%= appName %>
main:
allow-bean-definition-overriding: 'true'
jmx:
enabled: 'false'
mvc:
Comment on lines +1 to +8
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Duplicate top‑level spring: key; must be a single mapping.

YAML disallows duplicate keys. Merge all spring.* blocks under one spring:.

Apply this consolidation (also fixes quoted booleans/ints):

 spring:
   application:
     name: <%= appName %>
   main:
-    allow-bean-definition-overriding: 'true'
+    allow-bean-definition-overriding: true
   jmx:
-    enabled: 'false'
+    enabled: false
   mvc:
     problemdetails:
-      enabled: 'true'
+      enabled: true
-# (second spring: removed; merge sections below into this one)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
spring:
application:
name: <%= appName %>
main:
allow-bean-definition-overriding: 'true'
jmx:
enabled: 'false'
mvc:
spring:
application:
name: <%= appName %>
main:
allow-bean-definition-overriding: true
jmx:
enabled: false
mvc:
problemdetails:
enabled: true
🤖 Prompt for AI Agents
In generators/server/templates/app/src/main/resources/application.yml around
lines 1 to 8, there are duplicate top-level "spring:" mappings; consolidate all
spring.* entries into a single "spring:" mapping (merge application.name,
main.allow-bean-definition-overriding, jmx.enabled, mvc) under one "spring:" key
with correct indentation, and convert quoted booleans/ints to native YAML
booleans/numbers (e.g., true/false without quotes).

problemdetails:
enabled: 'true'
server:
port: '8080'
shutdown: graceful

################ Actuator #####################
management:
endpoints:
web:
exposure:
include: configprops,env,health,info,logfile,loggers,metrics,prometheus
endpoint:
health:
show-details: always

################### Database ###################
spring:
jpa:
open-in-view: 'false'
show-sql: 'false'
hibernate:
ddl-auto: none
properties:
hibernate:
jdbc:
time_zone: UTC
batch_size: '25'
lob:
non_contextual_creation: 'true'
query:
fail_on_pagination_over_collection_fetch: 'true'
plan_cache_max_size: '4096'
in_clause_parameter_padding: 'true'
generate_statistics: 'false'
order_inserts: 'true'
connection:
provider_disables_autocommit: 'true'
order_updates: 'true'
datasource:
hikari:
data-source-properties:
ApplicationName: ${spring.application.name}
auto-commit: 'false'
data:
jpa:
repositories:
bootstrap-mode: deferred

Comment on lines +25 to +57
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Move JPA/datasource under the single spring:; unquote numeric/boolean values.

-################### Database ###################
-spring:
+################### Database ###################
   jpa:
-    open-in-view: 'false'
-    show-sql: 'false'
+    open-in-view: false
+    show-sql: false
     hibernate:
       ddl-auto: none
     properties:
       hibernate:
         jdbc:
           time_zone: UTC
-          batch_size: '25'
+          batch_size: 25
           lob:
-            non_contextual_creation: 'true'
+            non_contextual_creation: true
         query:
-          fail_on_pagination_over_collection_fetch: 'true'
-          plan_cache_max_size: '4096'
-          in_clause_parameter_padding: 'true'
-        generate_statistics: 'false'
-        order_inserts: 'true'
+          fail_on_pagination_over_collection_fetch: true
+          plan_cache_max_size: 4096
+          in_clause_parameter_padding: true
+        generate_statistics: false
+        order_inserts: true
         connection:
-          provider_disables_autocommit: 'true'
-        order_updates: 'true'
+          provider_disables_autocommit: true
+        order_updates: true
   datasource:
     hikari:
       data-source-properties:
         ApplicationName: ${spring.application.name}
-      auto-commit: 'false'
+      auto-commit: false
   data:
     jpa:
       repositories:
         bootstrap-mode: deferred
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
################### Database ###################
spring:
jpa:
open-in-view: 'false'
show-sql: 'false'
hibernate:
ddl-auto: none
properties:
hibernate:
jdbc:
time_zone: UTC
batch_size: '25'
lob:
non_contextual_creation: 'true'
query:
fail_on_pagination_over_collection_fetch: 'true'
plan_cache_max_size: '4096'
in_clause_parameter_padding: 'true'
generate_statistics: 'false'
order_inserts: 'true'
connection:
provider_disables_autocommit: 'true'
order_updates: 'true'
datasource:
hikari:
data-source-properties:
ApplicationName: ${spring.application.name}
auto-commit: 'false'
data:
jpa:
repositories:
bootstrap-mode: deferred
################### Database ###################
jpa:
open-in-view: false
show-sql: false
hibernate:
ddl-auto: none
properties:
hibernate:
jdbc:
time_zone: UTC
batch_size: 25
lob:
non_contextual_creation: true
query:
fail_on_pagination_over_collection_fetch: true
plan_cache_max_size: 4096
in_clause_parameter_padding: true
generate_statistics: false
order_inserts: true
connection:
provider_disables_autocommit: true
order_updates: true
datasource:
hikari:
data-source-properties:
ApplicationName: ${spring.application.name}
auto-commit: false
data:
jpa:
repositories:
bootstrap-mode: deferred
🧰 Tools
🪛 YAMLlint (1.37.1)

[error] 26-26: duplication of key "spring" in mapping

(key-duplicates)

🤖 Prompt for AI Agents
generators/server/templates/app/src/main/resources/application.yml around lines
25 to 57: JPA and datasource sections should be nested under the single
top-level spring: key (remove any duplicate spring: blocks) and all
numeric/boolean scalar values must be unquoted; update indentation so spring:
contains jpa:, datasource:, and data: as children, and replace quoted values
like 'false', 'true', '25', '4096' with unquoted booleans/numbers (false, true,
25, 4096) while preserving property names (e.g., ApplicationName:
${spring.application.name}) and existing nested structure.

<%_ if (dbMigrationTool === 'flywaydb') { _%>
flyway:
locations: classpath:/db/migration/{vendor}
<%_ } _%>

Comment on lines +58 to +62
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Scope Flyway under spring.flyway; fix indentation.

Top‑level flyway won’t bind. Use spring.flyway.

-<%_ if (dbMigrationTool === 'flywaydb') { _%>
-  flyway:
-    locations: classpath:/db/migration/{vendor}     
-<%_ } _%>
+<%_ if (dbMigrationTool === 'flywaydb') { _%>
+  flyway:
+    locations: classpath:/db/migration/{vendor}
+<%_ } _%>

(Note: This block is now under the single spring: above.)

Committable suggestion skipped: line range outside the PR's diff.

🧰 Tools
🪛 YAMLlint (1.37.1)

[error] 59-59: syntax error: could not find expected ':'

(syntax)

🤖 Prompt for AI Agents
In generators/server/templates/app/src/main/resources/application.yml around
lines 58 to 62, the Flyway config is declared at top level as "flyway:" which
will not bind; move it under the existing "spring:" key as "spring.flyway:"
(i.e. nest the flyway block under spring) and fix indentation so the "locations:
classpath:/db/migration/{vendor}" line is indented accordingly, preserving the
conditional templating logic.

<%_ if (features.includes('elk')) { _%>
application:
logstash-host: localhost
<%_ } _%>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<%_ if (features.includes('localstack')) { _%>
spring:
cloud:
aws:
region:
static: us-east-1
credentials:
secret-key: noop
access-key: noop
endpoint: http://localhost:4566
<%_ } _%>