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] Path problem of inout spec file in windows: Illegal character in opaque part at index 2: C:....\ApiFirstServer-main\build\openapiDir\petstore.yaml #15202

Open
5 of 6 tasks
SashaVolushkova opened this issue Apr 12, 2023 · 20 comments

Comments

@SashaVolushkova
Copy link

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

Problem with path declaring of file with specification. Have an error: Illegal character in opaque part at index 2: C:....\ApiFirstServer-main\build\openapiDir\petstore.yaml

openapi-generator version

6.5.0

OpenAPI declaration file content or url

the issue doest link to file formatting

Generation Details

the issue doest link to file formatting

Steps to reproduce
  • OS: windows
  • gradle version: 7.5
  • openapi-generator-plugin-version: "6.5.0"
  • add plugin: id "org.openapi.generator" version "6.5.0"
  • set inputspec in validation:
openApiValidate {
	inputSpec = "${buildDir}/openapiDir/petstore.yaml".toString()
}

or


openApiValidate {
	inputSpec = "${buildDir}\\openapiDir\\petstore.yaml".toString()
}
  • get an error: Illegal character in opaque part at index 2: C:...\ApiFirstServer-main\build\openapiDir\petstore.yaml
  • the same problem is in openApiGenerate phase
Related issues/PRs

Related issue: #14075

Suggest a fix

just format link before loading the file.

@SashaVolushkova SashaVolushkova changed the title [BUG] Description [BUG] Path problem of inout spec file in windows: Illegal character in opaque part at index 2: C:....\ApiFirstServer-main\build\openapiDir\petstore.yaml Apr 12, 2023
@martin-mfg
Copy link
Contributor

Hi, I can't reproduce the problem. Like you, I'm using Windows 10, gradle 7.5 and "org.openapi.generator" version "6.5.0".
I tried both inputSpec = "${buildDir}/openapiDir/petstore.yaml".toString() and inputSpec = "${buildDir}\\openapiDir\\petstore.yaml".toString().

I think the problem might be related to the way how you invoke gradle.
How do you do that? I tried running ./gradlew openApiValidate from powershell 7, from cmd, from git bash and from WSL. It didn't fail anywhere. Are you invoking it from a script, from an IDE or something like that?

@NikitaCartes
Copy link

I am experiencing the same error as the author of this issue.

The error occurs for me in PowerShell, CMD, Git Bash, and IDEA.
Additionally, when I include println "projectDir: " + projectDir in the build.gradle file, it returns projectDir: C:\git\myProject in all of the aforementioned environments.

@mn3noa
Copy link

mn3noa commented Jul 6, 2023

Just check which openApi version is supported by openapi-generator-maven-plugin. In my case i use openapi-generator-maven-plugin 6.6.0. I got this error when i use openapi: 3.1.0 in my openApi yml file. With openapi: 3.0.3 it works.

@kromit
Copy link

kromit commented Sep 18, 2023

This also occurs with maven on Windows 11 with openapi-generator-maven-plugin: 7.0.0 an openapi: 3.1.0 in the file.

  [ERROR] Error resolving schema ./model/v1/SomeObj.yaml
  java.net.URISyntaxException: Illegal character in opaque part at index 2: C:\project\folder/../src/main/resources/openapi.yaml

Changing back to openapi: 3.0.3 within this same file works again.

@wing328
Copy link
Member

wing328 commented Sep 18, 2023

please try openapi-generator v7.0.1 which provides beta support for v3.1.0 spec.

@kromit
Copy link

kromit commented Sep 18, 2023

Same error with 7.0.1., but it seems like its is a problem of swagger resolve

[ERROR] Error resolving schema ./model/v1/SomeObj.yaml
java.net.URISyntaxException: Illegal character in opaque part at index 2: C:\project\folder/../src/main/resources/openapi.yaml
at java.net.URI$Parser.fail (URI.java:2976)
at java.net.URI$Parser.checkChars (URI.java:3147)
at java.net.URI$Parser.parse (URI.java:3183)
at java.net.URI.<init> (URI.java:623)
at io.swagger.v3.parser.reference.ReferenceUtils.resolve (ReferenceUtils.java:29)
at io.swagger.v3.parser.reference.ReferenceVisitor.resolveSchemaRef (ReferenceVisitor.java:227)
at io.swagger.v3.parser.reference.ReferenceVisitor.visitSchema (ReferenceVisitor.java:141)
at io.swagger.v3.parser.reference.OpenAPI31Traverser.traverseSchema (OpenAPI31Traverser.java:790)
at io.swagger.v3.parser.reference.OpenAPI31Traverser.traverseSchemaMap (OpenAPI31Traverser.java:946)
at io.swagger.v3.parser.reference.OpenAPI31Traverser.traverseComponents (OpenAPI31Traverser.java:169)
at io.swagger.v3.parser.reference.OpenAPI31Traverser.traverseOpenApi (OpenAPI31Traverser.java:128)
at io.swagger.v3.parser.reference.OpenAPI31Traverser.traverse (OpenAPI31Traverser.java:65)
at io.swagger.v3.parser.reference.OpenAPIDereferencer31.dereference (OpenAPIDereferencer31.java:74)
at io.swagger.v3.parser.OpenAPIV3Parser.resolve (OpenAPIV3Parser.java:225)
at io.swagger.v3.parser.OpenAPIV3Parser.readContents (OpenAPIV3Parser.java:181)
at io.swagger.v3.parser.OpenAPIV3Parser.readLocation (OpenAPIV3Parser.java:97)
at io.swagger.parser.OpenAPIParser.readLocation (OpenAPIParser.java:16)
at org.openapitools.codegen.config.CodegenConfigurator.toContext (CodegenConfigurator.java:637)
at org.openapitools.codegen.config.CodegenConfigurator.toClientOptInput (CodegenConfigurator.java:695)
at org.openapitools.codegen.plugin.CodeGenMojo.execute (CodeGenMojo.java:884)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:126)
at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:328)
at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:316)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:212)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:174)
at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:75)
at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:162)
at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:159)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:73)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:53)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:118)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:261)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:173)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:101)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:906)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:283)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:206)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:77)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:568)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:283)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:226)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:407)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:348)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:77)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:568)
at org.apache.maven.wrapper.BootstrapMainStarter.start (BootstrapMainStarter.java:52)
at org.apache.maven.wrapper.WrapperExecutor.execute (WrapperExecutor.java:161)
at org.apache.maven.wrapper.MavenWrapperMain.main (MavenWrapperMain.java:73)

@black-snow
Copy link

Same here, generator 7.0.1, Win11, Gradle 8.3, OpenAPI 3.1.0 - will fall back to 3.0.3 for now.

@craigmit
Copy link

Same exception as @kromit . openapi-generator-maven-plugin 7.0.1. Win11. Maven 3.6.3. Java 17.0.6. OpenAPI 3.1.0 - falling back to 3.0.3.

@wing328
Copy link
Member

wing328 commented Sep 21, 2023

Same error with 7.0.1., but it seems like its is a problem of swagger resolve

right, please report the issue to swagger parser. thanks.

@shorn
Copy link

shorn commented Oct 30, 2023

swagger-parse has this open issue: swagger-api/swagger-parser#1511

That issue references #10053 on this project (which this issue is maybe a duplicate of?)

There is a possible workaround mentioned (involving use of a later version of swagger-parser-v3) with the openapi-generator Gradle plugin.

My functioning workaround is to just fall back to using openapi spec 3.0.3.

@shorn
Copy link

shorn commented Nov 2, 2023

Another possible workaround is to use the cli via docker, to take advantage of docker-desktop running the container in a Linux environment.

Note that docker-desktop for Windows requires a paid subscription for commercial use.

Here's my Gradle task that seems to be working:

tasks.register('dockerRunApiIdl', Exec) {
  group="docker"
  dependsOn dockerStageApiIdl

  ignoreExitValue = true

  doFirst {
    delete file(outputDir)
  }

  commandLine osCmd('docker', 'run', '--rm',
    '--volume', "${file(stagingDir).path}:/input",
    '--volume', "${file(outputDir).path}:/output",
    'openapitools/openapi-generator-cli',
    'generate',
    '--input-spec', '/input/kopi-openapi-3.1.yaml',
    '--config', '/input/spring-generator-config.json',
    '--output', '/output',
  )
}

@otrebor
Copy link

otrebor commented Dec 20, 2023

I had the same problem with Maven. The "" symbol , used in the inputspec configuration parameter, creates the problem during the parsing of the URI containing the path to the yaml file.

my workaround is to create a property in my pom:

<input.spec.original>${basedir}/src/main/resources/api/openapi.yaml<input.spec.original>

then I replace all the "" symbols to "/" using a maven plugin.

org.codehaus.mojo build-helper-maven-plugin ${maven.build-helper.version} regex-property regex-property project.apis.folder ${project.apis.folder.original} \\ / false

And finally i pass the value of the property named "project.apis.folder" as input for the OpenApi generator.

org.openapitools openapi-generator-maven-plugin 7.1.0 ... ${project.apis.folder} ... ...

I hope this workaround can help.

@rongli-mx
Copy link

I have the same problem on Windows with Maven 3.8.7, OpenAPI Generator 7.2.0 and OpenAPI Version 3.1.0.
The solution from @otrebor works for me. The maven plugin passes the <inputSpec> directly to the Swagger OpenAPIParser:

SwaggerParseResult result = new OpenAPIParser().readLocation(inputSpec, authorizationValues, options);

OpenAPIParser expect inputSpec as URL, so I think the maven plugin should convert <inputSpec> to a valid URL.

@marcoblos
Copy link

As a possible workaround, you can use a relative path, for instance:
<inputSpec>src/main/resources/open-api-spec.yaml</inputSpec>

@Gelunox
Copy link

Gelunox commented Feb 27, 2024

As a possible workaround, you can use a relative path, for instance: <inputSpec>src/main/resources/open-api-spec.yaml</inputSpec>

Note that this doesn't work with multi module projects, especially if the spec is in a different module.

@marcoblos
Copy link

As a possible workaround, you can use a relative path, for instance: <inputSpec>src/main/resources/open-api-spec.yaml</inputSpec>

Note that this doesn't work with multi module projects, especially if the spec is in a different module.

That's true!

@jbroekhuizen-maqqie
Copy link

I was also facing the issue today. The "${buildDir}" part is returning a path including backslashes (''), which was for me causing the problem. Replacing them to a forward slash ('/') was the solution for me. This link was the solution for me: https://www.bennorthrop.com/Snippets/string-replace-in-maven-with-regex.php

@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.

openapi-generator = { id = "org.openapi.generator", version = "7.7.0" }

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)

Edit: added my workaround from #14075 (comment)

Simple workaround:

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

@BierDav
Copy link

BierDav commented Aug 6, 2024

this workaround fixes the issue for me: #14075 (comment)

@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