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

io.swagger : swagger-codegen-maven-plugin : 2.1.6 / 2.2.1 #3583

Open
ArnoVenner opened this issue Aug 12, 2016 · 3 comments
Open

io.swagger : swagger-codegen-maven-plugin : 2.1.6 / 2.2.1 #3583

ArnoVenner opened this issue Aug 12, 2016 · 3 comments

Comments

@ArnoVenner
Copy link

ArnoVenner commented Aug 12, 2016

Description

In a multi-module maven project when running a 'reactor build', relative paths configured in a subproject, do not resolve relatively to the sub-projects,'

Swagger-codegen version

Found in Versions: 2.1.6 and 2.2.1

Swagger declaration file content or url
Maven plugin configuration used
<plugin>
    <groupId>io.swagger</groupId>
    <artifactId>swagger-codegen-maven-plugin</artifactId>
    <!-- <version>2.1.6</version> -->
    <version>2.2.1</version>
    <executions><execution>
        <goals><goal>generate</goal></goals>
        <phase>generate-sources</phase>
        <configuration>
            <inputSpec>src/main/resources/api.yaml</inputSpec>
            <language>java</language>
            <configOptions><dateLibrary>joda</dateLibrary></configOptions>
            <library>jersey2</library>
        </configuration>
    </execution></executions>
</plugin>
Steps to reproduce

pom.xml
codegen-module/pom.xml
codegen-module/src/main/resources/api.yml

if I build codegen-module standalone, it works
if I build the multi-module project, it fails saying

'src/main/resources/api.yml not found

Related issues

not found

Suggest a Fix

The maven plugin 'CodeGenMojo' should check whether the path given in inputSpec is relative or absolute.
It should prefix relative paths it with the value of maven variable ${project.basedir}.

Workaround
<plugin>
    <groupId>io.swagger</groupId>
    <artifactId>swagger-codegen-maven-plugin</artifactId>
    <!-- <version>2.1.6</version> -->
    <version>2.2.1</version>
    <executions><execution>
        <goals><goal>generate</goal></goals>
        <phase>generate-sources</phase>
        <configuration>
            <inputSpec>${project.basedir}/src/main/resources/api.yaml</inputSpec>
            <language>java</language>
            <configOptions><dateLibrary>joda</dateLibrary></configOptions>
            <library>jersey2</library>
        </configuration>
    </execution></executions>
</plugin>
@wing328
Copy link
Contributor

wing328 commented Aug 15, 2016

@ArnoVenner thanks for reporting the issue.

May I know if you've cycle to contribute the fix by submitting the PR?

cc @ePaul

@ePaul
Copy link
Contributor

ePaul commented Aug 15, 2016

I have to confess that all our projects already use ${project.basedir}/... as the input spec path, thus I didn't note this (or didn't think it was important, not sure).

A bit of analysis of this issue:

  • The maven plugin simply passes the value to the CodegenConfigurator
  • CodegenConfigurator then calls SwaggerParser.read() with this value, ...
  • ... which passes this to Swagger20Parser.read, which tries to resolve this as a HTTP url (if it starts with http) or a file path (which will be relative to the current working directory), with fallback to the class path.

When running maven, the current working directory is the directory from which maven is called (which can be different from the location of the pom.xml, even if we don't have a submodule situation).

I guess prefixing with ${project.basedir} could work, though one needs to take care that http URIs are not broken when relative file paths are prefixed. (Also, windows paths like c:\....)

@ePaul
Copy link
Contributor

ePaul commented Aug 15, 2016

Also, it looks like the same issue appears when using the configurationFile ... both for finding the configuration file from the maven plugin, and when the configurationFile contains a relative input spec file name.

The latter is likely also a problem when using the CLI version. (I.e. you start call the CLI with a configuration file which is not in the current directory, and the config file contains a relative file name. This will be resolved relative to the calling directory, not the config file directory.)

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

3 participants