forked from loafle/openapi-generator-original
This commit is contained in:
parent
2db7b0b177
commit
05b9a899e4
@ -418,6 +418,12 @@ apply plugin: 'org.openapi.generator'
|
||||
|Boolean
|
||||
|false
|
||||
|Defines whether the output directory should be cleaned up before generating the output.
|
||||
|
||||
|dryRun
|
||||
|Boolean
|
||||
|false
|
||||
|Defines whether the generator should run in dry-run mode. In dry-run mode no files are written and a summary about
|
||||
file states is output.
|
||||
|===
|
||||
|
||||
[NOTE]
|
||||
|
@ -149,6 +149,7 @@ class OpenApiGeneratorPlugin : Plugin<Project> {
|
||||
generateAliasAsModel.set(generate.generateAliasAsModel)
|
||||
engine.set(generate.engine)
|
||||
cleanupOutput.set(generate.cleanupOutput)
|
||||
dryRun.set(generate.dryRun)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -359,6 +359,11 @@ open class OpenApiGeneratorGenerateExtension(project: Project) {
|
||||
*/
|
||||
val cleanupOutput = project.objects.property<Boolean>()
|
||||
|
||||
/**
|
||||
* Defines whether the generator should run in dry-run mode.
|
||||
*/
|
||||
val dryRun = project.objects.property<Boolean>()
|
||||
|
||||
init {
|
||||
applyDefaults()
|
||||
}
|
||||
@ -381,5 +386,6 @@ open class OpenApiGeneratorGenerateExtension(project: Project) {
|
||||
skipValidateSpec.set(false)
|
||||
generateAliasAsModel.set(false)
|
||||
cleanupOutput.set(false)
|
||||
dryRun.set(false)
|
||||
}
|
||||
}
|
||||
|
@ -521,6 +521,13 @@ open class GenerateTask : DefaultTask() {
|
||||
@Input
|
||||
val cleanupOutput = project.objects.property<Boolean>()
|
||||
|
||||
/**
|
||||
* Defines whether the generator should run in dry-run mode.
|
||||
*/
|
||||
@Optional
|
||||
@Input
|
||||
val dryRun = project.objects.property<Boolean>()
|
||||
|
||||
private fun <T : Any?> Property<T>.ifNotEmpty(block: Property<T>.(T) -> Unit) {
|
||||
if (isPresent) {
|
||||
val item: T? = get()
|
||||
@ -822,6 +829,11 @@ open class GenerateTask : DefaultTask() {
|
||||
}
|
||||
}
|
||||
|
||||
var dryRunSetting = false
|
||||
dryRun.ifNotEmpty { setting ->
|
||||
dryRunSetting = setting
|
||||
}
|
||||
|
||||
val clientOptInput = configurator.toClientOptInput()
|
||||
val codegenConfig = clientOptInput.config
|
||||
|
||||
@ -838,7 +850,7 @@ open class GenerateTask : DefaultTask() {
|
||||
val out = services.get(StyledTextOutputFactory::class.java).create("openapi")
|
||||
out.withStyle(StyledTextOutput.Style.Success)
|
||||
|
||||
DefaultGenerator().opts(clientOptInput).generate()
|
||||
DefaultGenerator(dryRunSetting).opts(clientOptInput).generate()
|
||||
|
||||
out.println("Successfully generated code to ${outputDir.get()}")
|
||||
} catch (e: RuntimeException) {
|
||||
|
@ -458,4 +458,45 @@ class GenerateTaskDslTest : TestBase() {
|
||||
assertEquals(TaskOutcome.FAILED, result.task(":openApiGenerate")?.outcome,
|
||||
"Expected a failed run, but found ${result.task(":openApiGenerate")?.outcome}")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `openapiGenerate should set dryRun flag`() {
|
||||
// Arrange
|
||||
val projectFiles = mapOf(
|
||||
"spec.yaml" to javaClass.classLoader.getResourceAsStream("specs/petstore-v3.0.yaml")
|
||||
)
|
||||
withProject(
|
||||
"""
|
||||
plugins {
|
||||
id 'org.openapi.generator'
|
||||
}
|
||||
openApiGenerate {
|
||||
generatorName = "kotlin"
|
||||
inputSpec = file("spec.yaml").absolutePath
|
||||
outputDir = file("build/kotlin").absolutePath
|
||||
apiPackage = "org.openapitools.example.api"
|
||||
invokerPackage = "org.openapitools.example.invoker"
|
||||
modelPackage = "org.openapitools.example.model"
|
||||
configOptions = [
|
||||
dateLibrary: "java8"
|
||||
]
|
||||
dryRun = true
|
||||
}
|
||||
""".trimIndent(),
|
||||
projectFiles
|
||||
)
|
||||
|
||||
// Act
|
||||
val result = GradleRunner.create()
|
||||
.withProjectDir(temp)
|
||||
.withArguments("openApiGenerate")
|
||||
.withPluginClasspath()
|
||||
.build()
|
||||
|
||||
// Assert
|
||||
assertTrue(
|
||||
result.output.contains("Dry Run Results:"),
|
||||
"Dry run results message is missing."
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -107,6 +107,7 @@ mvn clean compile
|
||||
| `skipIfSpecIsUnchanged` | `codegen.skipIfSpecIsUnchanged` | Skip the execution if the source file is older than the output folder (`false` by default. Can also be set globally through the `codegen.skipIfSpecIsUnchanged` property)
|
||||
| `addCompileSourceRoot` | `openapi.generator.maven.plugin.addCompileSourceRoot` | Add the output directory to the project as a source root, so that the generated java types are compiled and included in the project artifact (`true` by default). Mutually exclusive with `addTestCompileSourceRoot`.
|
||||
| `addTestCompileSourceRoot` | `openapi.generator.maven.plugin.addTestCompileSourceRoot` | Add the output directory to the project as a test source root, so that the generated java types are compiled only for the test classpath of the project (`false` by default). Mutually exclusive with `addCompileSourceRoot`.
|
||||
| `dryRun` | `openapi.generator.maven.plugin.dryRun` | Defines whether the generator should run in dry-run mode. In dry-run mode no files are written and a summary about file states is output ( `false` by default).
|
||||
| `environmentVariables` | N/A | deprecated. Use globalProperties instead.
|
||||
| `globalProperties` | N/A | A **map** of items conceptually similar to "environment variables" or "system properties". These are available to all aspects of the generation flow. See [Global Properties](https://openapi-generator.tech/docs/globals/) for list of available properties.
|
||||
| `configHelp` | `codegen.configHelp` | dumps the configuration help for the specified library (generates no sources)
|
||||
|
@ -460,6 +460,9 @@ public class CodeGenMojo extends AbstractMojo {
|
||||
@Parameter(defaultValue = "false", property = "openapi.generator.maven.plugin.addTestCompileSourceRoot")
|
||||
private boolean addTestCompileSourceRoot = false;
|
||||
|
||||
@Parameter(defaultValue = "false", property = "openapi.generator.maven.plugin.dryRun")
|
||||
private Boolean dryRun = false;
|
||||
|
||||
// TODO: Rename to global properties in version 5.1
|
||||
@Parameter
|
||||
protected Map<String, String> environmentVariables = new HashMap<>();
|
||||
@ -867,7 +870,7 @@ public class CodeGenMojo extends AbstractMojo {
|
||||
return;
|
||||
}
|
||||
adjustAdditionalProperties(config);
|
||||
new DefaultGenerator().opts(input).generate();
|
||||
new DefaultGenerator(dryRun).opts(input).generate();
|
||||
|
||||
if (buildContext != null) {
|
||||
buildContext.refresh(new File(getCompileSourceRoot()));
|
||||
|
Loading…
x
Reference in New Issue
Block a user