diff --git a/generators/java/generators/openapi-generator/README.md b/generators/java/generators/openapi-generator/README.md new file mode 100644 index 00000000000..4b6b2c343a8 --- /dev/null +++ b/generators/java/generators/openapi-generator/README.md @@ -0,0 +1,7 @@ +# java:openapi-generator sub-generator + +Generates openapi import structure that generates backend code using `src/main/resources/swagger/api.yml` openapi definition. + +[openapi-generator](https://github.com/OpenAPITools/openapi-generator/tree/master) +[openapi-generator-maven-plugin](https://github.com/OpenAPITools/openapi-generator/tree/master/modules/openapi-generator-maven-plugin) +[openapi-generator-gradle-plugin](https://github.com/OpenAPITools/openapi-generator/tree/master/modules/openapi-generator-gradle-plugin) diff --git a/generators/java/generators/openapi-generator/__snapshots__/generator.spec.ts.snap b/generators/java/generators/openapi-generator/__snapshots__/generator.spec.ts.snap new file mode 100644 index 00000000000..b14e5b37546 --- /dev/null +++ b/generators/java/generators/openapi-generator/__snapshots__/generator.spec.ts.snap @@ -0,0 +1,199 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`generator - java:openapi-generator gradle-addOpenapiGeneratorPlugin(false) should call source snapshot 1`] = ` +{ + "addJavaDependencies": [ + [ + { + "artifactId": "jackson-databind-nullable", + "groupId": "org.openapitools", + "version": "'JACKSON-DATABIND-NULLABLE-VERSION'", + }, + ], + ], +} +`; + +exports[`generator - java:openapi-generator gradle-addOpenapiGeneratorPlugin(false) should compose with generators 1`] = ` +[ + "jhipster:java:build-tool", +] +`; + +exports[`generator - java:openapi-generator gradle-addOpenapiGeneratorPlugin(false) should match files snapshot 1`] = ` +{ + ".yo-rc.json": { + "stateCleared": "modified", + }, + "README.md.jhi.openapi-generator": { + "stateCleared": "modified", + }, + "src/main/resources/swagger/api.yml": { + "stateCleared": "modified", + }, +} +`; + +exports[`generator - java:openapi-generator gradle-addOpenapiGeneratorPlugin(true) should call source snapshot 1`] = ` +{ + "addGradleBuildSrcDependencyCatalogLibraries": [ + [ + { + "libraryName": "openapi-generator", + "module": "org.openapitools:openapi-generator-gradle-plugin", + "scope": "implementation", + "version": "'GRADLE-OPENAPI-GENERATOR-VERSION'", + }, + ], + ], + "addGradlePlugin": [ + { + "id": "jhipster.openapi-generator-conventions", + }, + ], + "addJavaDependencies": [ + [ + { + "artifactId": "jackson-databind-nullable", + "groupId": "org.openapitools", + "version": "'JACKSON-DATABIND-NULLABLE-VERSION'", + }, + ], + ], +} +`; + +exports[`generator - java:openapi-generator gradle-addOpenapiGeneratorPlugin(true) should compose with generators 1`] = ` +[ + "jhipster:java:build-tool", +] +`; + +exports[`generator - java:openapi-generator gradle-addOpenapiGeneratorPlugin(true) should match files snapshot 1`] = ` +{ + ".yo-rc.json": { + "stateCleared": "modified", + }, + "README.md.jhi.openapi-generator": { + "stateCleared": "modified", + }, + "buildSrc/src/main/groovy/jhipster.openapi-generator-conventions.gradle": { + "stateCleared": "modified", + }, + "src/main/resources/swagger/api.yml": { + "stateCleared": "modified", + }, +} +`; + +exports[`generator - java:openapi-generator maven-addOpenapiGeneratorPlugin(false) should call source snapshot 1`] = ` +{ + "addJavaDependencies": [ + [ + { + "artifactId": "jackson-databind-nullable", + "groupId": "org.openapitools", + "version": "'JACKSON-DATABIND-NULLABLE-VERSION'", + }, + ], + ], +} +`; + +exports[`generator - java:openapi-generator maven-addOpenapiGeneratorPlugin(false) should compose with generators 1`] = ` +[ + "jhipster:java:build-tool", +] +`; + +exports[`generator - java:openapi-generator maven-addOpenapiGeneratorPlugin(false) should match files snapshot 1`] = ` +{ + ".yo-rc.json": { + "stateCleared": "modified", + }, + "README.md.jhi.openapi-generator": { + "stateCleared": "modified", + }, + "src/main/resources/swagger/api.yml": { + "stateCleared": "modified", + }, +} +`; + +exports[`generator - java:openapi-generator maven-addOpenapiGeneratorPlugin(true) should call source snapshot 1`] = ` +{ + "addJavaDependencies": [ + [ + { + "artifactId": "jackson-databind-nullable", + "groupId": "org.openapitools", + "version": "'JACKSON-DATABIND-NULLABLE-VERSION'", + }, + ], + ], + "addMavenDefinition": [ + { + "pluginManagement": [ + { + "additionalContent": " + + + generate + + + \${project.basedir}/src/main/resources/swagger/api.yml + spring + com.mycompany.myapp.web.api + com.mycompany.myapp.service.api.dto + ApiUtil.java + false + + true + jhipster + true + + + + +", + "artifactId": "openapi-generator-maven-plugin", + "groupId": "org.openapitools", + "version": "\${openapi-generator-maven-plugin.version}", + }, + ], + "plugins": [ + { + "artifactId": "openapi-generator-maven-plugin", + "groupId": "org.openapitools", + }, + ], + "properties": [ + { + "property": "openapi-generator-maven-plugin.version", + "value": "'OPENAPI-GENERATOR-MAVEN-PLUGIN-VERSION'", + }, + ], + }, + ], +} +`; + +exports[`generator - java:openapi-generator maven-addOpenapiGeneratorPlugin(true) should compose with generators 1`] = ` +[ + "jhipster:java:build-tool", +] +`; + +exports[`generator - java:openapi-generator maven-addOpenapiGeneratorPlugin(true) should match files snapshot 1`] = ` +{ + ".yo-rc.json": { + "stateCleared": "modified", + }, + "README.md.jhi.openapi-generator": { + "stateCleared": "modified", + }, + "src/main/resources/swagger/api.yml": { + "stateCleared": "modified", + }, +} +`; diff --git a/generators/java/generators/openapi-generator/command.ts b/generators/java/generators/openapi-generator/command.ts new file mode 100644 index 00000000000..8bc635837dc --- /dev/null +++ b/generators/java/generators/openapi-generator/command.ts @@ -0,0 +1,35 @@ +/** + * Copyright 2013-2024 the original author or authors from the JHipster project. + * + * This file is part of the JHipster project, see https://www.jhipster.tech/ + * for more information. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import type { JHipsterCommandDefinition } from '../../../base/api.js'; + +const command: JHipsterCommandDefinition = { + configs: { + addOpenapiGeneratorPlugin: { + cli: { + type: Boolean, + hide: true, + }, + default: true, + scope: 'storage', + }, + }, + import: [], +}; + +export default command; diff --git a/generators/java/generators/openapi-generator/generator.spec.ts b/generators/java/generators/openapi-generator/generator.spec.ts new file mode 100644 index 00000000000..0b4a4a5b969 --- /dev/null +++ b/generators/java/generators/openapi-generator/generator.spec.ts @@ -0,0 +1,60 @@ +/** + * Copyright 2013-2024 the original author or authors from the JHipster project. + * + * This file is part of the JHipster project, see https://www.jhipster.tech/ + * for more information. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { basename, dirname, resolve } from 'node:path'; +import { fileURLToPath } from 'node:url'; +import { before, it, describe, expect } from 'esmocha'; + +import { shouldSupportFeatures, testBlueprintSupport } from '../../../../test/support/tests.js'; +import { fromMatrix, defaultHelpers as helpers, result } from '../../../../testing/index.js'; +import Generator from './index.js'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); + +const generator = `${basename(resolve(__dirname, '../../'))}:${basename(__dirname)}`; + +describe(`generator - ${generator}`, () => { + shouldSupportFeatures(Generator); + describe('blueprint support', () => testBlueprintSupport(generator)); + + for (const [name, config] of Object.entries(fromMatrix({ buildTool: ['maven', 'gradle'], addOpenapiGeneratorPlugin: [true, false] }))) { + describe(name, () => { + before(async () => { + await helpers + .runJHipster(generator) + .withMockedJHipsterGenerators() + .withMockedSource() + .withSharedApplication({}) + .withJHipsterConfig(config); + }); + + it('should match files snapshot', () => { + expect(result.getStateSnapshot()).toMatchSnapshot(); + }); + + it('should call source snapshot', () => { + expect(result.sourceCallsArg).toMatchSnapshot(); + }); + + it('should compose with generators', () => { + expect(result.composedMockedGenerators).toMatchSnapshot(); + }); + }); + } +}); diff --git a/generators/java/generators/openapi-generator/generator.ts b/generators/java/generators/openapi-generator/generator.ts new file mode 100644 index 00000000000..05ed6c29fca --- /dev/null +++ b/generators/java/generators/openapi-generator/generator.ts @@ -0,0 +1,136 @@ +/** + * Copyright 2013-2024 the original author or authors from the JHipster project. + * + * This file is part of the JHipster project, see https://www.jhipster.tech/ + * for more information. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import BaseApplicationGenerator from '../../../base-application/index.js'; +import { GRADLE_BUILD_SRC_MAIN_DIR } from '../../../generator-constants.js'; +import { javaMainResourceTemplatesBlock } from '../../support/files.js'; + +export default class OpenapiGeneratorGenerator extends BaseApplicationGenerator { + async beforeQueue() { + if (!this.fromBlueprint) { + await this.composeWithBlueprints(); + } + + if (!this.delegateToBlueprint) { + await this.dependsOnBootstrapApplication(); + await this.dependsOnJHipster('jhipster:java:build-tool'); + } + } + + get writing() { + return this.asWritingTaskGroup({ + cleanup({ application, control }) { + control.cleanupFiles({ + '8.6.1': [[application.buildToolGradle!, 'gradle/swagger.gradle']], + }); + }, + async writing({ application }) { + await this.writeFiles({ + blocks: [ + { templates: ['README.md.jhi.openapi-generator'] }, + javaMainResourceTemplatesBlock({ templates: ['swagger/api.yml'] }), + { + condition: ctx => ctx.buildToolGradle && ctx.addOpenapiGeneratorPlugin, + templates: [`${GRADLE_BUILD_SRC_MAIN_DIR}/jhipster.openapi-generator-conventions.gradle`], + }, + ], + context: application, + }); + }, + }); + } + + get [BaseApplicationGenerator.WRITING]() { + return this.delegateTasksToBlueprint(() => this.writing); + } + + get postWriting() { + return this.asPostWritingTaskGroup({ + addDependencies({ source, application }) { + const { addOpenapiGeneratorPlugin, buildToolGradle, buildToolMaven, javaDependencies } = application; + source.addJavaDependencies!([ + { + groupId: 'org.openapitools', + artifactId: 'jackson-databind-nullable', + version: javaDependencies!['jackson-databind-nullable'], + }, + ]); + + if (addOpenapiGeneratorPlugin) { + if (buildToolMaven) { + source.addMavenDefinition!({ + properties: [ + { property: 'openapi-generator-maven-plugin.version', value: javaDependencies!['openapi-generator-maven-plugin'] }, + ], + plugins: [{ groupId: 'org.openapitools', artifactId: 'openapi-generator-maven-plugin' }], + pluginManagement: [ + { + groupId: 'org.openapitools', + artifactId: 'openapi-generator-maven-plugin', + version: '${openapi-generator-maven-plugin.version}', + additionalContent: ` + + + generate + + + \${project.basedir}/${application.srcMainResources}swagger/api.yml + spring + ${application.packageName}.web.api + ${application.packageName}.service.api.dto + ApiUtil.java + false + ${ + application.reactive + ? ` + true +` + : '' + } + true + ${application.dasherizedBaseName} + true + + + + +`, + }, + ], + }); + } + if (buildToolGradle) { + source.addGradleBuildSrcDependencyCatalogLibraries?.([ + { + libraryName: 'openapi-generator', + module: 'org.openapitools:openapi-generator-gradle-plugin', + version: javaDependencies!['gradle-openapi-generator'], + scope: 'implementation', + }, + ]); + source.addGradlePlugin?.({ id: 'jhipster.openapi-generator-conventions' }); + } + } + }, + }); + } + + get [BaseApplicationGenerator.POST_WRITING]() { + return this.delegateTasksToBlueprint(() => this.postWriting); + } +} diff --git a/generators/java/generators/openapi-generator/index.ts b/generators/java/generators/openapi-generator/index.ts new file mode 100644 index 00000000000..1cfadd692bb --- /dev/null +++ b/generators/java/generators/openapi-generator/index.ts @@ -0,0 +1,20 @@ +/** + * Copyright 2013-2024 the original author or authors from the JHipster project. + * + * This file is part of the JHipster project, see https://www.jhipster.tech/ + * for more information. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export { default } from './generator.js'; +export { default as command } from './command.js'; diff --git a/generators/java/generators/openapi-generator/templates/README.md.jhi.openapi-generator.ejs b/generators/java/generators/openapi-generator/templates/README.md.jhi.openapi-generator.ejs new file mode 100644 index 00000000000..1f1d55e5d64 --- /dev/null +++ b/generators/java/generators/openapi-generator/templates/README.md.jhi.openapi-generator.ejs @@ -0,0 +1,48 @@ +<%# + Copyright 2013-2024 the original author or authors from the JHipster project. + + This file is part of the JHipster project, see https://www.jhipster.tech/ + for more information. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + https://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +-%> +<%# + This is a fragment file, it will be merged into to root template if available. + EJS fragments will process % delimiter tags in template and & delimiter tags in the merge process. +-%> +<&_ if (fragment.developmentSection) { -&> +### Doing API-First development using openapi-generator-cli + +[OpenAPI-Generator]() is configured for this application. You can generate API code from the `src/main/resources/swagger/api.yml` definition file by running: +<%_ if (buildToolMaven) { _%> +```bash +./mvnw generate-sources +``` +<%_ } _%> +<%_ if (buildToolGradle) { _%> +```bash +./gradlew openApiGenerate +``` +<%_ } _%> +Then implements the generated delegate classes with `@Service` classes. + +To edit the `api.yml` definition file, you can use a tool such as [Swagger-Editor](). Start a local instance of the swagger-editor using docker by running: `docker compose -f src/main/docker/swagger-editor.yml up -d`. The editor will then be reachable at [http://localhost:7742](http://localhost:7742). + +Refer to [Doing API-First development][] for more details. +<&_ } -&> + +<&_ if (fragment.referenceSection) { -&> +[OpenAPI-Generator]: https://openapi-generator.tech +[Swagger-Editor]: https://editor.swagger.io +[Doing API-First development]: <%= documentationArchiveUrl %>/doing-api-first-development/ +<&_ } -&> diff --git a/generators/server/templates/gradle/swagger.gradle.ejs b/generators/java/generators/openapi-generator/templates/buildSrc/src/main/groovy/jhipster.openapi-generator-conventions.gradle.ejs similarity index 88% rename from generators/server/templates/gradle/swagger.gradle.ejs rename to generators/java/generators/openapi-generator/templates/buildSrc/src/main/groovy/jhipster.openapi-generator-conventions.gradle.ejs index 6642e7d8cd8..2a1fa86f438 100644 --- a/generators/server/templates/gradle/swagger.gradle.ejs +++ b/generators/java/generators/openapi-generator/templates/buildSrc/src/main/groovy/jhipster.openapi-generator-conventions.gradle.ejs @@ -16,11 +16,9 @@ See the License for the specific language governing permissions and limitations under the License. -%> -/* - * Plugin that provides API-first development using OpenAPI-generator to - * generate Spring-MVC endpoint stubs at compile time from an OpenAPI definition file - */ -apply plugin: "org.openapi.generator" +plugins { + id "org.openapi.generator" +} openApiGenerate { generatorName = "spring" diff --git a/generators/server/templates/src/main/resources/swagger/api.yml.ejs b/generators/java/generators/openapi-generator/templates/src/main/resources/swagger/api.yml.ejs similarity index 100% rename from generators/server/templates/src/main/resources/swagger/api.yml.ejs rename to generators/java/generators/openapi-generator/templates/src/main/resources/swagger/api.yml.ejs diff --git a/generators/java/types.d.ts b/generators/java/types.d.ts index 111c90012bf..23b21b66fac 100644 --- a/generators/java/types.d.ts +++ b/generators/java/types.d.ts @@ -63,6 +63,8 @@ export type JavaApplication = BaseApplication & prettierJava: boolean; imperativeOrReactive: string; + + addOpenapiGeneratorPlugin: boolean; }; export type JavaSourceType = { diff --git a/generators/server/templates/README.md.jhi.spring-boot.ejs b/generators/server/templates/README.md.jhi.spring-boot.ejs index c57ce3f04af..21d73153143 100644 --- a/generators/server/templates/README.md.jhi.spring-boot.ejs +++ b/generators/server/templates/README.md.jhi.spring-boot.ejs @@ -216,28 +216,6 @@ See Cypress' documentation for setting OS [environment variables](https://docs.c **Auth0 requires a user to provide authorization consent on the first login.** Consent flow is currently not handled in the Cypress test suite. To mitigate the issue, you can use a user account that has already granted consent to authorize application access via interactive login. <%_ } _%> <%_ } _%> - -<%_ if (enableSwaggerCodegen) { _%> -### Doing API-First development using openapi-generator-cli - -[OpenAPI-Generator]() is configured for this application. You can generate API code from the `src/main/resources/swagger/api.yml` definition file by running: - <%_ if (buildToolMaven) { _%> -```bash -./mvnw generate-sources -``` - <%_ } _%> - <%_ if (buildToolGradle) { _%> -```bash -./gradlew openApiGenerate -``` - <%_ } _%> -Then implements the generated delegate classes with `@Service` classes. - -To edit the `api.yml` definition file, you can use a tool such as [Swagger-Editor](). Start a local instance of the swagger-editor using docker by running: `docker compose -f src/main/docker/swagger-editor.yml up -d`. The editor will then be reachable at [http://localhost:7742](http://localhost:7742). - -Refer to [Doing API-First development][] for more details. -<%_ } _%> - <&_ } -&> <&_ if (fragment.testingSection) { -&> @@ -397,11 +375,3 @@ For more information refer to [Using Docker and Docker-Compose][], this page als To configure CI for your project, run the ci-cd sub-generator (`jhipster ci-cd`), this will let you generate configuration files for a number of Continuous Integration systems. Consult the [Setting up Continuous Integration][] page for more information. <&_ } -&> - -<&_ if (fragment.referenceSection) { -&> - <%_ if (enableSwaggerCodegen) { _%> -[OpenAPI-Generator]: https://openapi-generator.tech -[Swagger-Editor]: https://editor.swagger.io -[Doing API-First development]: <%= documentationArchiveUrl %>/doing-api-first-development/ - <%_ } _%> -<&_ } -&> diff --git a/generators/server/templates/build.gradle.ejs b/generators/server/templates/build.gradle.ejs index bd0e001d07d..1aa987efbef 100644 --- a/generators/server/templates/build.gradle.ejs +++ b/generators/server/templates/build.gradle.ejs @@ -22,9 +22,6 @@ plugins { id "idea" id "eclipse" id "com.gorylenko.gradle-git-properties" -<%_ if (enableSwaggerCodegen) { _%> - id "org.openapi.generator" -<%_ } _%> // jhipster-needle-gradle-plugins - JHipster will add additional gradle plugins here } @@ -70,9 +67,6 @@ repositories { apply plugin: 'io.spring.dependency-management' -<%_ if (enableSwaggerCodegen) { _%> -apply from: "gradle/swagger.gradle" -<%_ } _%> // jhipster-needle-gradle-apply-from - JHipster will add additional gradle scripts to be applied here if (project.hasProperty("prod")) { @@ -186,9 +180,6 @@ dependencies { <%_ } _%> annotationProcessor "org.mapstruct:mapstruct-processor:${mapstructVersion}" implementation "org.mapstruct:mapstruct:${mapstructVersion}" -<%_ if (enableSwaggerCodegen) { _%> - implementation "org.openapitools:jackson-databind-nullable:${jacksonDatabindNullableVersion}" -<%_ } _%> annotationProcessor "org.springframework.boot:spring-boot-configuration-processor" implementation "org.springframework.boot:spring-boot-loader-tools" <%_ /* This is useful for major Spring Boot migration */ diff --git a/generators/server/templates/gradle.properties.ejs b/generators/server/templates/gradle.properties.ejs index 14d33a2d56b..69b525d7c6a 100644 --- a/generators/server/templates/gradle.properties.ejs +++ b/generators/server/templates/gradle.properties.ejs @@ -22,18 +22,12 @@ profile=dev # Dependency versions mapstructVersion=<%- javaDependencies.mapstruct %> archunitJunit5Version=<%- javaDependencies['archunit-junit5'] %> -<%_ if (enableSwaggerCodegen) { _%> -jacksonDatabindNullableVersion=<%- javaDependencies['jackson-databind-nullable'] %> -<%_ } _%> <%_ if (reactive) { _%> blockhoundJunitPlatformVersion=<%- javaDependencies['blockhound-junit-platform'] %> <%_ } _%> # gradle plugin version gitPropertiesPluginVersion=<%- javaDependencies['gradle-git-properties'] %> -<%_ if (enableSwaggerCodegen) { _%> -openapiPluginVersion=<%- javaDependencies['gradle-openapi-generator'] %> -<%_ } _%> <%_ if (enableGradleEnterprise) { _%> gradleEnterprisePluginVersion=<%- javaDependencies['gradle-enterprise'] %> gradleCommonCustomUserDataPluginVersion=<%- javaDependencies['common-custom-user-data-gradle-plugin'] %> diff --git a/generators/server/templates/pom.xml.ejs b/generators/server/templates/pom.xml.ejs index 00c1627a187..9c8f7cebedd 100644 --- a/generators/server/templates/pom.xml.ejs +++ b/generators/server/templates/pom.xml.ejs @@ -64,9 +64,6 @@ <%_ } _%> <%- javaDependencies['archunit-junit5'] %> <%- javaDependencies.mapstruct %> -<%_ if (enableSwaggerCodegen) { _%> - <%- javaDependencies['jackson-databind-nullable'] %> -<%_ } _%> <%- javaDependencies['git-commit-id-maven-plugin'] %> <%- javaDependencies['lifecycle-mapping'] %> <%- javaDependencies['maven-clean-plugin'] %> @@ -79,9 +76,6 @@ <%- javaDependencies['maven-site-plugin'] %> <%- javaDependencies['maven-surefire-plugin'] %> <%- javaDependencies['maven-war-plugin'] %> -<%_ if (enableSwaggerCodegen) { _%> - <%- javaDependencies['openapi-generator-maven-plugin'] %> -<%_ } _%> @@ -161,13 +155,6 @@ ${mapstruct.version} provided -<%_ if (enableSwaggerCodegen) { _%> - - org.openapitools - jackson-databind-nullable - ${jackson-databind-nullable.version} - -<%_ } _%> org.springframework.boot spring-boot-configuration-processor @@ -350,16 +337,6 @@ org.springframework.boot spring-boot-maven-plugin -<%_ if (enableSwaggerCodegen) { _%> - - - org.openapitools - openapi-generator-maven-plugin - -<%_ } _%> @@ -515,40 +492,6 @@ maven-jar-plugin ${maven-jar-plugin.version} -<%_ if (enableSwaggerCodegen) { _%> - - - org.openapitools - openapi-generator-maven-plugin - ${openapi-generator-maven-plugin.version} - - - - generate - - - ${project.basedir}/<%= SERVER_MAIN_RES_DIR %>swagger/api.yml - spring - <%= packageName %>.web.api - <%= packageName %>.service.api.dto - ApiUtil.java - false - - <%_ if (reactive) { _%> - true - <%_ } _%> - true - <%= dasherizedBaseName %> - true - - - - - -<%_ } _%> org.springframework.boot spring-boot-maven-plugin diff --git a/generators/server/templates/settings.gradle.ejs b/generators/server/templates/settings.gradle.ejs index 1e33c93bfad..19600935eba 100644 --- a/generators/server/templates/settings.gradle.ejs +++ b/generators/server/templates/settings.gradle.ejs @@ -28,9 +28,6 @@ pluginManagement { } plugins { id 'com.gorylenko.gradle-git-properties' version "${gitPropertiesPluginVersion}" -<%_ if (enableSwaggerCodegen) { _%> - id "org.openapi.generator" version "${openapiPluginVersion}" -<%_ } _%> <%_ if (enableGradleEnterprise) { _%> id "com.gradle.enterprise" version "${gradleEnterprisePluginVersion}" id "com.gradle.common-custom-user-data-gradle-plugin" version "${gradleCommonCustomUserDataPluginVersion}" diff --git a/generators/spring-boot/files.ts b/generators/spring-boot/files.ts index ff72674215b..ddd0224cc66 100644 --- a/generators/spring-boot/files.ts +++ b/generators/spring-boot/files.ts @@ -242,14 +242,6 @@ const swaggerFiles = { renameTo: moveToJavaPackageSrcDir, templates: ['config/OpenApiConfiguration.java'], }, - { - condition: generator => generator.buildToolGradle, - templates: ['gradle/swagger.gradle'], - }, - { - path: SERVER_MAIN_RES_DIR, - templates: ['swagger/api.yml'], - }, ], }; diff --git a/generators/spring-boot/generator.ts b/generators/spring-boot/generator.ts index 6b9269ffab9..53c37d95e7a 100644 --- a/generators/spring-boot/generator.ts +++ b/generators/spring-boot/generator.ts @@ -150,6 +150,7 @@ export default class SpringBootGenerator extends BaseApplicationGenerator { clientFramework, testFrameworks, feignClient, + enableSwaggerCodegen, } = this.jhipsterConfigWithDefaults; await this.composeWithJHipster(GENERATOR_DOCKER); @@ -160,6 +161,10 @@ export default class SpringBootGenerator extends BaseApplicationGenerator { await this.composeWithJHipster('jhipster:java:node'); } + if (enableSwaggerCodegen) { + await this.composeWithJHipster('jhipster:java:openapi-generator'); + } + if (applicationType === GATEWAY) { await this.composeWithJHipster('jhipster:spring-cloud:gateway'); }