Home > Software design >  Issue with defining inputSpec of openapi generator gradle plugin on Windows
Issue with defining inputSpec of openapi generator gradle plugin on Windows

Time:11-24

In a gradle project on a Windows machine, I'd like to generate Java code from an openapi spec. However, I can't figure out how to specify the inputSpec parameter. For simplicity I describe the validate task since the issue occurrs there as well.

plugins {
    ...
    id "org.openapi.generator" version "6.2.1"
    ...
}

openApiValidate {
    inputSpec = "src/main/resources/api/openapi.yaml"
}

leads to Caused by: java.lang.RuntimeException: Could not find src/main/resources/api/openapi.yaml on the classpath

Expecting that I could have mispelled the path, I tried to include a typo intentionally

inputSpec = "src/main/resources/api/openapi.WRONG"

But this leads to a different exception

A problem was found with the configuration of task ':publisher-service:openApiValidate' (type 'ValidateTask').
> File 'C:\dev\myProject\src\main\resources\api\openapi.WRONG' specified for property 'inputSpec' does not exist.

If using

inputSpec = "$projectDir/src/main/resources/api/openapi.yaml"

instead, it says java.net.URISyntaxException: Illegal character in opaque part at index 2: C:\dev\myProject/src/main/resources/api/openapi.yaml

Next trial with an absolute path:

inputSpec = "/c/dev/myProject/src/main/resources/api/openapi.yaml"

Again, it fails with something different:

> File 'C:\dev\myProject\c\dev\myProject\src\main\resources\api\openapi.yaml' specified for property 'inputSpec' does not exist. 

Notice that some path parts are duplicated there.

I tried running gradle (gradlew to be precise) in a git bash and from within Intellij with no difference.

Any idea how to solve this?

CodePudding user response:

It seems to be related to version 6.2.1 of the org.openapi.generator Gradle plugin. I've filed a bug report at gitlab for this:

https://github.com/OpenAPITools/openapi-generator/issues/14075

--Edit I finally also found a way to set the path with 6.2.1, this way:

inputSpec.set((new File("${projectDir}/src/main/resources/api/openapi.yml")).toString());
  • Related