-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add java:openapi-generator generator
- Loading branch information
Showing
16 changed files
with
416 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
119 changes: 119 additions & 0 deletions
119
generators/java/generators/openapi-generator/__snapshots__/generator.spec.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`generator - java:openapi-generator gradle 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 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 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 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", | ||
}, | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** | ||
* 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: {}, | ||
import: [], | ||
}; | ||
|
||
export default command; |
60 changes: 60 additions & 0 deletions
60
generators/java/generators/openapi-generator/generator.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'] }))) { | ||
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).toMatchInlineSnapshot('[]'); | ||
}); | ||
}); | ||
} | ||
}); |
128 changes: 128 additions & 0 deletions
128
generators/java/generators/openapi-generator/generator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
/** | ||
* 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(); | ||
} | ||
} | ||
|
||
get writing() { | ||
return this.asWritingTaskGroup({ | ||
async writing({ application }) { | ||
await this.writeFiles({ | ||
blocks: [ | ||
{ templates: ['README.md.jhi.openapi-generator'] }, | ||
javaMainResourceTemplatesBlock({ templates: ['swagger/api.yml'] }), | ||
{ | ||
condition: ctx => ctx.buildToolGradle, | ||
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 { buildToolGradle, buildToolMaven, javaDependencies } = application; | ||
source.addJavaDependencies!([ | ||
{ | ||
groupId: 'org.openapitools', | ||
artifactId: 'jackson-databind-nullable', | ||
version: javaDependencies!['jackson-databind-nullable'], | ||
}, | ||
]); | ||
|
||
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: ` <executions> | ||
<execution> | ||
<goals> | ||
<goal>generate</goal> | ||
</goals> | ||
<configuration> | ||
<inputSpec>\${project.basedir}/${application.srcMainResources}swagger/api.yml</inputSpec> | ||
<generatorName>spring</generatorName> | ||
<apiPackage>${application.packageName}.web.api</apiPackage> | ||
<modelPackage>${application.packageName}.service.api.dto</modelPackage> | ||
<supportingFilesToGenerate>ApiUtil.java</supportingFilesToGenerate> | ||
<skipValidateSpec>false</skipValidateSpec> | ||
<configOptions>${ | ||
application.reactive | ||
? ` | ||
<reactive>true</reactive> | ||
` | ||
: '' | ||
} | ||
<delegatePattern>true</delegatePattern> | ||
<title>${application.dasherizedBaseName}</title> | ||
<useSpringBoot3>true</useSpringBoot3> | ||
</configOptions> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
`, | ||
}, | ||
], | ||
}); | ||
} | ||
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'; |
Oops, something went wrong.