Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[gradle] Add 4 boolean properties supported by codegenConfigurator #1881

Merged
merged 2 commits into from
Jan 11, 2019
Merged
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
52 changes: 52 additions & 0 deletions modules/openapi-generator-gradle-plugin/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,26 @@ The gradle plugin is not currently published to https://plugins.gradle.org/m2/.
|None
|A map of options specific to a generator.

|logToStderr
|Boolean
|false
|To write all log messages (not just errors) to STDOUT

|enablePostProcessFile
|Boolean
|false
|To enable the file post-processing hook. This enables executing an external post-processor (usually a linter program). This only enables the post-processor. To define the post-processing command, define an environment variable such as LANG_POST_PROCESS_FILE (e.g. GO_POST_PROCESS_FILE, SCALA_POST_PROCESS_FILE). Please open an issue if your target generator does not support this functionality.

|skipValidateSpec
|Boolean
|false
|To skip spec validation. When true, we will skip the default behavior of validating a spec before generation.

|generateAliasAsModel
|Boolean
|false
|To generate alias (array, list, map) as model. When false, top-level objects defined as array, list, or map will result in those definitions generated as top-level Array-of-items, List-of-items, Map-of-items definitions. When true, A model representation either containing or extending the array,list,map (depending on specific generator implementation) will be generated.

|===

[NOTE]
Expand Down Expand Up @@ -557,3 +577,35 @@ you need a task reference or instance. One way to do this is to access it as `ta

You can run `gradle tasks --debug` to see this registration.
====

== Troubleshooting

=== Android Studio

Android Studio may experience a Windows-specific Guava dependency conflict with openapig-enerator-gradle-plugin versions greater than 3.0.0.

As a workaround, you may force exclude conflicting Guava dependencies.

```gradle
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath('org.openapitools:openapi-generator-gradle-plugin:3.3.4') {
exclude group: 'com.google.guava'
}
}
}
// …

configurations {
compile.exclude module: 'guava-jdk5'
}
// …
apply plugin: 'org.openapi.generator'
```

See https://github.com/OpenAPITools/openapi-generator/issues/1818[OpenAPITools/openapi-generator#1818] for more details.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ openApiGenerate {
systemProperties = [
modelDocs: "false"
]
skipValidateSpec = true
logToStderr = true
generateAliasAsModel = false
// set to true and set environment variable {LANG}_POST_PROCESS_FILE
// (e.g. SCALA_POST_PROCESS_FILE) to the linter/formatter to be processed.
// This command will be passed one file at a time for most supported post processors.
enablePostProcessFile = false
}

task buildGoSdk(type: org.openapitools.generator.gradle.plugin.tasks.GenerateTask){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ class OpenApiGeneratorPlugin : Plugin<Project> {
generateApiDocumentation.set(generate.generateApiDocumentation)
withXml.set(generate.withXml)
configOptions.set(generate.configOptions)
logToStderr.set(generate.logToStderr)
enablePostProcessFile.set(generate.enablePostProcessFile)
skipValidateSpec.set(generate.skipValidateSpec)
generateAliasAsModel.set(generate.generateAliasAsModel)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,31 @@ open class OpenApiGeneratorGenerateExtension(project: Project) {
*/
val withXml = project.objects.property<Boolean>()

/**
* To write all log messages (not just errors) to STDOUT
*/
val logToStderr = project.objects.property<Boolean>()

/**
* To enable the file post-processing hook. This enables executing an external post-processor (usually a linter program).
* This only enables the post-processor. To define the post-processing command, define an environment variable such as
* LANG_POST_PROCESS_FILE (e.g. GO_POST_PROCESS_FILE, SCALA_POST_PROCESS_FILE). Please open an issue if your target
* generator does not support this functionality.
*/
val enablePostProcessFile = project.objects.property<Boolean>()

/**
* To skip spec validation. When true, we will skip the default behavior of validating a spec before generation.
*/
val skipValidateSpec = project.objects.property<Boolean>()

/**
* To generate alias (array, list, map) as model. When false, top-level objects defined as array, list, or map will result in those
* definitions generated as top-level Array-of-items, List-of-items, Map-of-items definitions.
* When true, A model representation either containing or extending the array,list,map (depending on specific generator implementation) will be generated.
*/
val generateAliasAsModel = project.objects.property<Boolean>()

/**
* A map of options specific to a generator.
*/
Expand All @@ -282,5 +307,9 @@ open class OpenApiGeneratorGenerateExtension(project: Project) {
withXml.set(false)
configOptions.set(mapOf())
validateSpec.set(true)
logToStderr.set(false)
enablePostProcessFile.set(false)
skipValidateSpec.set(false)
generateAliasAsModel.set(false)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,36 @@ open class GenerateTask : DefaultTask() {
@get:Internal
val withXml = project.objects.property<Boolean>()


/**
* To write all log messages (not just errors) to STDOUT
*/
@get:Internal
val logToStderr = project.objects.property<Boolean>()

/**
* To enable the file post-processing hook. This enables executing an external post-processor (usually a linter program).
* This only enables the post-processor. To define the post-processing command, define an environment variable such as
* LANG_POST_PROCESS_FILE (e.g. GO_POST_PROCESS_FILE, SCALA_POST_PROCESS_FILE). Please open an issue if your target
* generator does not support this functionality.
*/
@get:Internal
val enablePostProcessFile = project.objects.property<Boolean>()

/**
* To skip spec validation. When true, we will skip the default behavior of validating a spec before generation.
*/
@get:Internal
val skipValidateSpec = project.objects.property<Boolean>()

/**
* To generate alias (array, list, map) as model. When false, top-level objects defined as array, list, or map will result in those
* definitions generated as top-level Array-of-items, List-of-items, Map-of-items definitions.
* When true, A model representation either containing or extending the array,list,map (depending on specific generator implementation) will be generated.
*/
@get:Internal
val generateAliasAsModel = project.objects.property<Boolean>()

/**
* A dynamic map of options specific to a generator.
*/
Expand Down Expand Up @@ -472,6 +502,22 @@ open class GenerateTask : DefaultTask() {
configurator.removeOperationIdPrefix = value!!
}

logToStderr.ifNotEmpty { value ->
configurator.logToStderr = value
}

enablePostProcessFile.ifNotEmpty { value ->
configurator.enablePostProcessFile = value
}

skipValidateSpec.ifNotEmpty { value ->
configurator.setValidateSpec(value)
}

generateAliasAsModel.ifNotEmpty { value ->
configurator.setGenerateAliasAsModel(value)
}

if (systemProperties.isPresent) {
systemProperties.get().forEach { entry ->
configurator.addSystemProperty(entry.key, entry.value)
Expand Down