swagger-api / swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
http://swagger.io
Apache License 2.0
16.98k stars 6.04k forks source link

[jaxrs] StringUtil.java will be generated in 'apiPackage', but package is defined as 'invokerPackage' #2298

Open CroniD opened 8 years ago

CroniD commented 8 years ago

swagger-codegen version: 2.1.5 language: jaxrs

See https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/StringUtil.mustache#L1

and

https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaJerseyServerCodegen.java#L89

wing328 commented 8 years ago

@CroniD can you provide us a spec to reproduce the issue?

CroniD commented 8 years ago

Oh, sure, sry.

Given the pom.xml

<?xml version="1.0"?>
<project
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
    xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.demo</groupId>
    <artifactId>demo</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>pom</packaging>
    <name>demo</name>
    <properties>
        <project.java.version>1.7</project.java.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <demo.artifactId>demo</demo.artifactId>
    </properties>
    <build>
        <plugins>
            <plugin>
                <groupId>io.swagger</groupId>
                <artifactId>swagger-codegen-maven-plugin</artifactId>
                <version>2.1.5</version>
                <!-- see https://generator.swagger.io/#/ for configuration values -->
                <executions>
                    <execution>
                        <id>${demo.artifactId}</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <language>jaxrs</language>
                            <inputSpec>${basedir}/swagger.yaml</inputSpec>
                            <output>${basedir}/../${demo.artifactId}</output>
                            <invokerPackage>${project.groupId}.server.jaxrs</invokerPackage>
                            <apiPackage>${project.groupId}.server.jaxrs.api</apiPackage>
                            <modelPackage>${project.groupId}.server.jaxrs.model</modelPackage>
                            <indentSize>4</indentSize>
                            <lineLength>120</lineLength>
                            <addCompileSourceRoot>false</addCompileSourceRoot>
                            <configOptions>
                                <groupId>${project.groupId}</groupId>
                                <artifactId>${demo.artifactId}</artifactId>
                                <artifactVersion>${project.version}</artifactVersion>
                                <dateLibrary>Joda</dateLibrary>
                                <bigDecimalAsString>true</bigDecimalAsString>
                            </configOptions>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

and the http://petstore.swagger.io/v2/swagger.json

Once the generation is done, a new folder "demo" is created at "../demo". In "demo/src/gen/java/org/demo/server/jaxrs/api/StringUtil.java" is a wrong package declaration package org.demo.server.jaxrs;, which leads to a compile error.