openapi-processor / openapi-processor-gradle

openapi-processor gradle plugin
https://docs.openapiprocessor.io
Apache License 2.0
3 stars 1 forks source link

Kotlin gradle integration #19

Closed mdibaiee closed 3 years ago

mdibaiee commented 3 years ago

Hello!

While trying to integrate your project (it's wonderful by the way! great job!), we realised that it's not easy to integrate it with a Kotlin gradle DSL.

In order to add a processor, I had to do this:

openapiProcessor {
    apiPath("$projectDir/src/main/resources/openapi.yaml")

    val p = com.github.hauner.openapi.gradle.Processor("spring")
    p.processor("io.openapiprocessor:openapi-processor-spring:2021.3")
    p.targetDir("$projectDir/build/openapi")
    p.other.put("mapping", "$projectDir/src/main/resources/openapi-mapping.yaml")

    processors.put("spring", p)
}

Apparently the methodMissing method that you have does not work properly in Kotlin DSL, and using a spring { processor } does not work unfortunately.

hauner commented 3 years ago

yes, that doesn't look very intuitive.

Thanks for reporting and the praise :-)

hauner commented 3 years ago

just released 2021.3, you can now do this

// build.gradle.kts

openapiProcessor {
    apiPath("${projectDir}/src/api/openapi.yaml")

    process("spring") {
        processor("io.openapiprocessor:openapi-processor-spring:<version>")
        targetDir("${projectDir}/build/openapi")
        prop("mapping", "${projectDir}/src/api/mapping.yaml")
    }

    process("json") {
        processor("io.openapiprocessor:openapi-processor-json:<version>")
        targetDir("${buildDir}/json")
    }
}

.. unfortunately this does NOT seem to work (the integration test fails) with gradle older than 6.5. Which is strange because I can use the new methods in a groovy dsl and versions older than 6.5.

mdibaiee commented 3 years ago

Thank you @hauner !