Skip to content

Commit

Permalink
Merge pull request #26694 from mshima/openapi-generator
Browse files Browse the repository at this point in the history
add java:openapi-generator generator
  • Loading branch information
DanielFran authored Jul 11, 2024
2 parents 49b0ea5 + b7d4be5 commit a8d9007
Show file tree
Hide file tree
Showing 17 changed files with 515 additions and 118 deletions.
7 changes: 7 additions & 0 deletions generators/java/generators/openapi-generator/README.md
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -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": " <executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>\${project.basedir}/src/main/resources/swagger/api.yml</inputSpec>
<generatorName>spring</generatorName>
<apiPackage>com.mycompany.myapp.web.api</apiPackage>
<modelPackage>com.mycompany.myapp.service.api.dto</modelPackage>
<supportingFilesToGenerate>ApiUtil.java</supportingFilesToGenerate>
<skipValidateSpec>false</skipValidateSpec>
<configOptions>
<delegatePattern>true</delegatePattern>
<title>jhipster</title>
<useSpringBoot3>true</useSpringBoot3>
</configOptions>
</configuration>
</execution>
</executions>
",
"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",
},
}
`;
35 changes: 35 additions & 0 deletions generators/java/generators/openapi-generator/command.ts
Original file line number Diff line number Diff line change
@@ -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;
60 changes: 60 additions & 0 deletions generators/java/generators/openapi-generator/generator.spec.ts
Original file line number Diff line number Diff line change
@@ -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();
});
});
}
});
Loading

0 comments on commit a8d9007

Please sign in to comment.