Skip to content
GitLab
    • Explore Projects Groups Snippets
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Merge requests
  • !12062

Configure apiNameSuffix via plugins

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Oleh Kurpiak requested to merge github/fork/borsch/configure-apiNameSuffix-via-plugins into master 3 years ago
  • Overview 0
  • Commits 1
  • Pipelines 0
  • Changes 9

Add apiNameSuffix parameter to maven & gradle plugins. Fix for https://github.com/OpenAPITools/openapi-generator/issues/12055

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh
    ./bin/utils/export_docs_generators.sh
    Commit all changed files. This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master. These must match the expectations made by your contribution. You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*. For Windows users, please run the script in Git BASH.
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.
Compare
  • master (base)

and
  • latest version
    189b11c2
    1 commit, 2 years ago

9 files
+ 85
- 0

    Preferences

    File browser
    Compare changes
mod‎ules‎
openapi-generat‎or-gradle-plugin‎
s‎rc‎
main/kotlin/org/‎…/…/gradle/plugin‎
exten‎sions‎
OpenApiGeneratorGe‎nerateExtension.kt‎ +6 -0
ta‎sks‎
Generat‎eTask.kt‎ +11 -0
OpenApiGener‎atorPlugin.kt‎ +1 -0
test/‎kotlin‎
GenerateTas‎kDslTest.kt‎ +49 -0
READM‎E.adoc‎ +5 -0
openapi-generat‎or-maven-plugin‎
s‎rc‎
main/java/org/…‎/codegen/plugin‎
CodeGenM‎ojo.java‎ +10 -0
te‎st‎
java/org/openapito‎ols/codegen/plugin‎
CodeGenMoj‎oTest.java‎ +1 -0
resource‎s/default‎
pom‎.xml‎ +1 -0
READ‎ME.md‎ +1 -0
modules/openapi-generator-gradle-plugin/src/main/kotlin/org/openapitools/generator/gradle/plugin/extensions/OpenApiGeneratorGenerateExtension.kt
+ 6
- 0
  • View file @ 189b11c2

  • Edit in single-file editor

  • Open in Web IDE


@@ -106,6 +106,11 @@ open class OpenApiGeneratorGenerateExtension(project: Project) {
*/
val modelNameSuffix = project.objects.property<String>()
/**
* Suffix that will be appended to all api names. Default is the empty string.
*/
val apiNameSuffix = project.objects.property<String>()
/**
* Sets instantiation type mappings.
*/
@@ -326,6 +331,7 @@ open class OpenApiGeneratorGenerateExtension(project: Project) {
releaseNote.set("Minor update")
modelNamePrefix.set("")
modelNameSuffix.set("")
apiNameSuffix.set("")
generateModelTests.set(true)
generateModelDocumentation.set(true)
generateApiTests.set(true)
modules/openapi-generator-gradle-plugin/src/main/kotlin/org/openapitools/generator/gradle/plugin/tasks/GenerateTask.kt
+ 11
- 0
  • View file @ 189b11c2

  • Edit in single-file editor

  • Open in Web IDE


@@ -168,6 +168,13 @@ open class GenerateTask : DefaultTask() {
@Input
val modelNameSuffix = project.objects.property<String>()
/**
* Suffix that will be appended to all api names. Default is the empty string.
*/
@Optional
@Input
val apiNameSuffix = project.objects.property<String>()
/**
* Sets instantiation type mappings.
*/
@@ -573,6 +580,10 @@ open class GenerateTask : DefaultTask() {
configurator.setModelNameSuffix(value)
}
apiNameSuffix.ifNotEmpty { value ->
configurator.setApiNameSuffix(value)
}
invokerPackage.ifNotEmpty { value ->
configurator.setInvokerPackage(value)
}
modules/openapi-generator-gradle-plugin/src/main/kotlin/org/openapitools/generator/gradle/plugin/OpenApiGeneratorPlugin.kt
+ 1
- 0
  • View file @ 189b11c2

  • Edit in single-file editor

  • Open in Web IDE


@@ -106,6 +106,7 @@ class OpenApiGeneratorPlugin : Plugin<Project> {
modelPackage.set(generate.modelPackage)
modelNamePrefix.set(generate.modelNamePrefix)
modelNameSuffix.set(generate.modelNameSuffix)
apiNameSuffix.set(generate.apiNameSuffix)
instantiationTypes.set(generate.instantiationTypes)
typeMappings.set(generate.typeMappings)
additionalProperties.set(generate.additionalProperties)
modules/openapi-generator-gradle-plugin/src/test/kotlin/GenerateTaskDslTest.kt
+ 49
- 0
  • View file @ 189b11c2

  • Edit in single-file editor

  • Open in Web IDE


@@ -68,6 +68,55 @@ class GenerateTaskDslTest : TestBase() {
"Expected a successful run, but found ${result.task(":openApiGenerate")?.outcome}")
}
@Test
fun `should apply prefix & suffix config parameters`() {
// Arrange
val projectFiles = mapOf(
"spec.yaml" to javaClass.classLoader.getResourceAsStream("specs/petstore-v3.0.yaml")
)
withProject("""
plugins {
id 'org.openapi.generator'
}
openApiGenerate {
generatorName = "java"
inputSpec = file("spec.yaml").absolutePath
outputDir = file("build/java").absolutePath
apiPackage = "org.openapitools.example.api"
invokerPackage = "org.openapitools.example.invoker"
modelPackage = "org.openapitools.example.model"
modelNamePrefix = "ModelPref"
modelNameSuffix = "Suff"
apiNameSuffix = "ApiClassSuffix"
configOptions = [
dateLibrary: "java8"
]
}
""".trimIndent(), projectFiles)
// Act
val result = GradleRunner.create()
.withProjectDir(temp)
.withArguments("openApiGenerate")
.withPluginClasspath()
.build()
// Assert
assertTrue(result.output.contains("Successfully generated code to"), "User friendly generate notice is missing.")
listOf(
"build/java/src/main/java/org/openapitools/example/model/ModelPrefPetSuff.java",
"build/java/src/main/java/org/openapitools/example/model/ModelPrefErrorSuff.java",
"build/java/src/main/java/org/openapitools/example/api/PetsApiClassSuffix.java"
).map {
val f = File(temp, it)
assertTrue(f.exists() && f.isFile, "An expected file was not generated when invoking the generation. - " + f)
}
assertEquals(TaskOutcome.SUCCESS, result.task(":openApiGenerate")?.outcome,
"Expected a successful run, but found ${result.task(":openApiGenerate")?.outcome}")
}
@Test
fun `openApiGenerate should used up-to-date instead of regenerate`() {
// Arrange
modules/openapi-generator-gradle-plugin/README.adoc
+ 5
- 0
  • View file @ 189b11c2

  • Edit in single-file editor

  • Open in Web IDE


@@ -204,6 +204,11 @@ apply plugin: 'org.openapi.generator'
|None
|Suffix that will be appended to all model names.
|apiNameSuffix
|String
|None
|Suffix that will be appended to all api names.
|instantiationTypes
|Map(String,String)
|None
0 Assignees
None
Assign to
0 Reviewers
None
Request review from
Labels
2
Enhancement: General Server: Spring
2
Enhancement: General Server: Spring
    Assign labels
  • Manage project labels

Milestone
4.0.0
4.0.0 (expired)
None
Time tracking
No estimate or time spent
Lock merge request
Unlocked
0
0 participants
Reference: OpenAPITools/openapi-generator!1725
Source branch: github/fork/borsch/configure-apiNameSuffix-via-plugins

Menu

Explore Projects Groups Snippets