File tree Expand file tree Collapse file tree 4 files changed +87
-0
lines changed
main/kotlin/io/openapiprocessor/gradle
testInt/groovy/io/openapiprocessor/gradle Expand file tree Collapse file tree 4 files changed +87
-0
lines changed Original file line number Diff line number Diff line change @@ -124,6 +124,7 @@ class OpenApiProcessorPlugin: Plugin<Project> {
124124 copyApiPath (task)
125125 task.getApiDir().set(project.layout.projectDirectory.dir(getInputDirectory()))
126126 task.getTargetDir().set(project.layout.projectDirectory.dir(getOutputDirectory()))
127+ processor.getMapping()?.let { task.getMapping().set(project.file(it)) }
127128
128129 val handler = project.dependencies
129130 val dependencies = ArrayList <Dependency >()
Original file line number Diff line number Diff line change @@ -8,11 +8,14 @@ package io.openapiprocessor.gradle
88import org.gradle.api.DefaultTask
99import org.gradle.api.file.ConfigurableFileCollection
1010import org.gradle.api.file.DirectoryProperty
11+ import org.gradle.api.file.RegularFileProperty
1112import org.gradle.api.provider.MapProperty
1213import org.gradle.api.provider.Property
1314import org.gradle.api.tasks.Classpath
1415import org.gradle.api.tasks.InputDirectory
16+ import org.gradle.api.tasks.InputFile
1517import org.gradle.api.tasks.Internal
18+ import org.gradle.api.tasks.Optional
1619import org.gradle.api.tasks.OutputDirectory
1720import org.gradle.api.tasks.TaskAction
1821import org.gradle.workers.WorkerExecutor
@@ -33,6 +36,15 @@ abstract class OpenApiProcessorTask: DefaultTask() {
3336 @InputDirectory
3437 abstract fun getApiDir (): DirectoryProperty
3538
39+ /* *
40+ * mapping.yaml input file. Used by gradle for the up-to-date check.
41+ *
42+ * @return mapping.yaml
43+ */
44+ @Optional
45+ @InputFile
46+ abstract fun getMapping (): RegularFileProperty
47+
3648 /* *
3749 * Target directory for the sources generated by the processor. Used by gradle for the up-to-date check.
3850 *
Original file line number Diff line number Diff line change @@ -110,6 +110,10 @@ open class Processor(configName: String): ProcessorBase() {
110110 other[API_PATH ] = apiPath.toString()
111111 }
112112
113+ fun getMapping (): String? {
114+ return other[" mapping" ]?.toString()
115+ }
116+
113117 fun prop (props : Map <String , Any >) {
114118 other.putAll(props)
115119 }
Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright 2025 https://github.com/openapi-processor/openapi-processor-gradle
3+ * PDX-License-Identifier: Apache-2.0
4+ */
5+
6+ package io.openapiprocessor.gradle
7+
8+
9+ import io.openapiprocessor.gradle.support.PluginSpec
10+
11+ class MappingSpec extends PluginSpec {
12+
13+ @Override
14+ String getBuildFileName () {
15+ ' build.gradle.kts'
16+ }
17+
18+ @Override
19+ String getBuildFile (String projectDir ) {
20+ """ \
21+ import io.openapiprocessor.gradle.OpenApiProcessorTask
22+
23+ plugins {
24+ id("io.openapiprocessor.openapi-processor")
25+ }
26+
27+ repositories {
28+ mavenCentral()
29+ }
30+
31+ openapiProcessor {
32+ apiPath(file("src/api/openapi.yaml"))
33+
34+ process("v1") {
35+ processor(project.files("$projectDir /processor-v1/build/libs/processor-v1.jar"))
36+ targetDir(layout.buildDirectory.dir("v1"))
37+
38+ prop("mapping", file("mapping.yaml"))
39+ }
40+ }
41+
42+ afterEvaluate {
43+ val task = tasks.named("processV1").get() as OpenApiProcessorTask
44+
45+ println("MAPPING:")
46+ val mapping = task.getMapping()
47+ println(mapping)
48+
49+ val mapping2 = mapping.get()
50+ println(mapping2)
51+ }
52+
53+ """ . stripIndent ()
54+ }
55+
56+ @Override
57+ List<String > getGradleArguments () {
58+ [' --stacktrace' , ' --debug' ]
59+ }
60+
61+ void " passes mapping to task if set" () {
62+ when :
63+ def result = build(" 9.0.0" , """ \
64+ """ . stripIndent())
65+
66+ then :
67+ def mapping = new File (testProjectDir, " mapping.yaml" )
68+ result. output. contains(mapping. absolutePath)
69+ }
70+ }
You can’t perform that action at this time.
0 commit comments