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> {
124
124
copyApiPath (task)
125
125
task.getApiDir().set(project.layout.projectDirectory.dir(getInputDirectory()))
126
126
task.getTargetDir().set(project.layout.projectDirectory.dir(getOutputDirectory()))
127
+ processor.getMapping()?.let { task.getMapping().set(project.file(it)) }
127
128
128
129
val handler = project.dependencies
129
130
val dependencies = ArrayList <Dependency >()
Original file line number Diff line number Diff line change @@ -8,11 +8,14 @@ package io.openapiprocessor.gradle
8
8
import org.gradle.api.DefaultTask
9
9
import org.gradle.api.file.ConfigurableFileCollection
10
10
import org.gradle.api.file.DirectoryProperty
11
+ import org.gradle.api.file.RegularFileProperty
11
12
import org.gradle.api.provider.MapProperty
12
13
import org.gradle.api.provider.Property
13
14
import org.gradle.api.tasks.Classpath
14
15
import org.gradle.api.tasks.InputDirectory
16
+ import org.gradle.api.tasks.InputFile
15
17
import org.gradle.api.tasks.Internal
18
+ import org.gradle.api.tasks.Optional
16
19
import org.gradle.api.tasks.OutputDirectory
17
20
import org.gradle.api.tasks.TaskAction
18
21
import org.gradle.workers.WorkerExecutor
@@ -33,6 +36,15 @@ abstract class OpenApiProcessorTask: DefaultTask() {
33
36
@InputDirectory
34
37
abstract fun getApiDir (): DirectoryProperty
35
38
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
+
36
48
/* *
37
49
* Target directory for the sources generated by the processor. Used by gradle for the up-to-date check.
38
50
*
Original file line number Diff line number Diff line change @@ -110,6 +110,10 @@ open class Processor(configName: String): ProcessorBase() {
110
110
other[API_PATH ] = apiPath.toString()
111
111
}
112
112
113
+ fun getMapping (): String? {
114
+ return other[" mapping" ]?.toString()
115
+ }
116
+
113
117
fun prop (props : Map <String , Any >) {
114
118
other.putAll(props)
115
119
}
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