Skip to content

[BUG][Java][spring][maven] FileNotFoundException when spec file is present in another jar #1792

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

Closed
ashuto-sh opened this issue Jan 2, 2019 · 4 comments · Fixed by #3440
Closed

Comments

@ashuto-sh
Copy link

Description

When using openapi-generator-maven-plugin to generate sources with a yaml spec present in another jar, the models and other operation files are generated successfully but towards the end FileNotFoundException is thrown. Probably this might be due to classloader.

openapi-generator version

4.0.0-beta

Pom file configuration
...
      <plugin>
        <groupId>org.openapitools</groupId>
        <artifactId>openapi-generator-maven-plugin</artifactId>
        <version>4.0.0-beta</version>

        <executions>
          <execution>
            <goals>
              <goal>generate</goal>
            </goals>
            <configuration>
              <inputSpec>/openapi.yaml</inputSpec>
              <language>spring</language>
              <library>spring-mvc</library>
              <configOptions>                
                <useTags>false</useTags>
                <invokerPackage>${project.groupId}.backend.generated.server</invokerPackage>
                <apiPackage>${project.groupId}.backend.generated.server.api</apiPackage>
                <modelPackage>${project.groupId}.backend.generated.server.model</modelPackage>
              </configOptions>             
              <modelNameSuffix>Model</modelNameSuffix>
            </configuration>
          </execution>
        </executions>

        <dependencies>
          <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>${swagger.spec.artifactId}</artifactId>
            <version>${swagger.spec.version}</version>
          </dependency>
        </dependencies>
      </plugin>
...
Suggest a fix

Probable solution would be to use something similar to

this.getClass().getClassLoader().getResourceAsStream(inputSpec)

instead of

File inputSpecFile = new File(inputSpec);

at following line

@auto-labeler
Copy link

auto-labeler bot commented Jan 2, 2019

👍 Thanks for opening this issue!
🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

@Woodham
Copy link

Woodham commented Jan 2, 2019

I think the same line of code is breaking remote inputSpecs? If the inputSpec is a URL then it also breaks with a FileNotFoundException (naturally because a url isn't a file).

@Catscratch
Copy link

Same here. It would also be nice to use an external server address as inputSpec, like WSDL stub generation works.

E.g.
<inputSpec>https://petstore.swagger.io/v2/swagger.json</inputSpec>

@wing328
Copy link
Member

wing328 commented Sep 4, 2019

Please give it another try as #3440 has been merged into master

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

Successfully merging a pull request may close this issue.

4 participants