Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Issue with defining inputSpec of openapi generator gradle plugin on Windows #14075

Open
rainer198 opened this issue Nov 21, 2022 · 8 comments

Comments

@rainer198
Copy link

Description

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?

openapi-generator version

6.2.1

Older versions seem to work. I've tried 6.1.0 which does not have this issue. Instead I have another problem with spec validation com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'openapi': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')

OpenAPI declaration file content or url
Steps to reproduce
Related issues/PRs
Suggest a fix
@rainer198
Copy link
Author

I've also asked in Stackoverflow: https://stackoverflow.com/questions/74489893/issue-with-defining-inputspec-of-openapi-generator-gradle-plugin-on-windows . However, as it seems to be related to the current release, I decided to create a bug report

@rainer198
Copy link
Author

I don't know, after switching between different versions, it works with 6.2.1 as well, at least when defining the inputSpec like

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

@rainer198
Copy link
Author

In another project which uses another gradle version (7.5.1) even the described workaround did not work.

@martin-mfg
Copy link
Contributor

It works fine for me using:

  • Windows 10
  • org.openapi.generator 6.2.1
  • gradlew with gradle 8.0
  • git bash to run the command ./gradlew openApiValidate
  • input path "C:/Users/MY_USER_NAME/Desktop/webhook-example.yaml"

The important part is probably that even when using git bash you should still specify the input path using "C:/...".

Hope this helps!

@mtrakal
Copy link

mtrakal commented Aug 2, 2024

it's broken with: openapi: 3.1.0
when change to: openapi: 3.0.x it generate.

Windows 11 + openapi: 3.1.0

problem is path which it try to use: D:\ instead of /

 -Illegal character in opaque part at index 2: D:\Projects\project\module\api/api.yaml

        at org.openapitools.codegen.config.CodegenConfigurator.toContext(CodegenConfigurator.java:717)
        at org.openapitools.codegen.config.CodegenConfigurator.toClientOptInput(CodegenConfigurator.java:744)
        at org.openapitools.generator.gradle.plugin.tasks.GenerateTask.doWork(GenerateTask.kt:937)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:125)
        at org.gradle.api.internal.project.taskfactory.StandardTaskAction.doExecute(StandardTaskAction.java:58)
        at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:51)
        at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:29)

@mtrakal
Copy link

mtrakal commented Aug 2, 2024

Simple workaround:

openApiGenerate {
    // add .replace("\\","/") behind yaml file path :)
    inputSpec = "$projectDir/specification.yaml".replace("\\","/")

@desertratx
Copy link

desertratx commented Aug 15, 2024

the workaround does unfortunatly not work in maven with 'inputSpecRootDirectory'
'inputSpecRootDirectory' ${good.basedir}/src/main/resources '/inputSpecRootDirectory'

Reading spec: .........../src/main/resources\models.yaml

@koscejev
Copy link
Contributor

koscejev commented Sep 23, 2024

Encountered the same issue. Here's a workaround that uses a newer Gradle approach (.kts version):

inputSpec = layout.buildDirectory.file("resources/main/openapi.yaml").map { it.asFile.toURI().toString() }

Note: this is using the processed resource (after filtering, etc.) from buildDirectory, so:

tasks.getByName("openApiValidate") { dependsOn(tasks.processResources) }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants