Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions bin/jaxrs-cxf-petstore-server-annotated-base-path.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/sh

SCRIPT="$0"

while [ -h "$SCRIPT" ] ; do
ls=`ls -ld "$SCRIPT"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
SCRIPT="$link"
else
SCRIPT=`dirname "$SCRIPT"`/"$link"
fi
done

if [ ! -d "${APP_DIR}" ]; then
APP_DIR=`dirname "$SCRIPT"`/..
APP_DIR=`cd "${APP_DIR}"; pwd`
fi

executable="./modules/swagger-codegen-cli/target/swagger-codegen-cli.jar"

if [ ! -f "$executable" ]
then
mvn clean package
fi

# if you've executed sbt assembly previously it will use that instead.
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
ags="$@ generate -t modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l jaxrs-cxf -o samples/server/petstore/jaxrs-cxf-annotated-base-path -DhideGenerationTimestamp=true,useAnnotatedBasePath=true"

java $JAVA_OPTS -jar $executable $ags
31 changes: 31 additions & 0 deletions bin/jaxrs-cxf-petstore-server-non-spring-application.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/sh

SCRIPT="$0"

while [ -h "$SCRIPT" ] ; do
ls=`ls -ld "$SCRIPT"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
SCRIPT="$link"
else
SCRIPT=`dirname "$SCRIPT"`/"$link"
fi
done

if [ ! -d "${APP_DIR}" ]; then
APP_DIR=`dirname "$SCRIPT"`/..
APP_DIR=`cd "${APP_DIR}"; pwd`
fi

executable="./modules/swagger-codegen-cli/target/swagger-codegen-cli.jar"

if [ ! -f "$executable" ]
then
mvn clean package
fi

# if you've executed sbt assembly previously it will use that instead.
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
ags="$@ generate -t modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l jaxrs-cxf -o samples/server/petstore/jaxrs-cxf-non-spring-app -DhideGenerationTimestamp=true,generateNonSpringApplication=true"

java $JAVA_OPTS -jar $executable $ags
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ public class JavaCXFServerCodegen extends AbstractJavaJAXRSServerCodegen

protected boolean useLoggingFeatureForTests = false;

protected boolean useAnnotatedBasePath = false;

protected boolean generateNonSpringApplication = false;

public JavaCXFServerCodegen()
{
super();
Expand Down Expand Up @@ -108,6 +112,9 @@ public JavaCXFServerCodegen()
cliOptions
.add(CliOption.newBoolean(ADD_CONSUMES_PRODUCES_JSON, "Add @Consumes/@Produces Json to API interface"));

cliOptions.add(CliOption.newBoolean(USE_ANNOTATED_BASE_PATH, "Use @Path annotations for basePath"));

cliOptions.add(CliOption.newBoolean(GENERATE_NON_SPRING_APPLICATION, "Generate non-Spring application"));
}


Expand Down Expand Up @@ -159,6 +166,16 @@ public void processOpts()
this.setGenerateJbossDeploymentDescriptor(generateJbossDeploymentDescriptorProp);
}

if (additionalProperties.containsKey(USE_ANNOTATED_BASE_PATH)) {
boolean useAnnotatedBasePathProp = convertPropertyToBooleanAndWriteBack(USE_ANNOTATED_BASE_PATH);
this.setUseAnnotatedBasePath(useAnnotatedBasePathProp);
}

if (additionalProperties.containsKey(GENERATE_NON_SPRING_APPLICATION)) {
boolean generateNonSpringApplication = convertPropertyToBooleanAndWriteBack(GENERATE_NON_SPRING_APPLICATION);
this.setGenerateNonSpringApplication(generateNonSpringApplication);
}

supportingFiles.clear(); // Don't need extra files provided by AbstractJAX-RS & Java Codegen

writeOptional(outputFolder, new SupportingFile("server/pom.mustache", "", "pom.xml"));
Expand Down Expand Up @@ -191,10 +208,12 @@ public void processOpts()
(testResourcesFolder + '/'), "application.properties"));

}

}


if (this.generateNonSpringApplication) {
writeOptional(outputFolder, new SupportingFile("server/nonspring-web.mustache",
("src/main/webapp/WEB-INF"), "web.xml"));
}
}

@Override
Expand Down Expand Up @@ -293,4 +312,12 @@ public void setAddConsumesProducesJson(boolean addConsumesProducesJson) {
this.addConsumesProducesJson = addConsumesProducesJson;
}

public void setUseAnnotatedBasePath(boolean useAnnotatedBasePath) {
this.useAnnotatedBasePath = useAnnotatedBasePath;
}

public void setGenerateNonSpringApplication(boolean generateNonSpringApplication) {
this.generateNonSpringApplication = generateNonSpringApplication;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,18 @@ public interface CXFServerFeatures

public static final String ADD_CONSUMES_PRODUCES_JSON = "addConsumesProducesJson";

public static final String USE_ANNOTATED_BASE_PATH = "useAnnotatedBasePath";

public static final String GENERATE_NON_SPRING_APPLICATION = "generateNonSpringApplication";

public void setUseWadlFeature(boolean useWadlFeature);

public void setUseMultipartFeature(boolean useMultipartFeature);

public void setAddConsumesProducesJson(boolean addConsumesProducesJson);

public void setUseAnnotatedBasePath(boolean useAnnotatedBasePath);

public void setGenerateNonSpringApplication(boolean generateNonSpringApplication);

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import io.swagger.jaxrs.PATCH;
import javax.validation.constraints.*;
{{/useBeanValidation}}

@Path("/")
@Path("{{^useAnnotatedBasePath}}/{{/useAnnotatedBasePath}}{{#useAnnotatedBasePath}}{{contextPath}}{{/useAnnotatedBasePath}}")
@Api(value = "/", description = "{{description}}")
{{#addConsumesProducesJson}}
@Consumes(MediaType.APPLICATION_JSON)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" version="3.0"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">

<servlet>
<display-name>CXF Non-Spring Jaxrs Servlet</display-name>
<servlet-name>CXFNonSpringJaxrsServlet</servlet-name>
<servlet-class>org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet</servlet-class>
{{#apiInfo}}
<init-param>
<param-name>jaxrs.serviceClasses</param-name>
<param-value>{{#apis}}{{package}}.impl.{{classname}}ServiceImpl{{^-last}},{{/-last}}{{/apis}}</param-value>
</init-param>
{{/apiInfo}}
<init-param>
<param-name>jaxrs.providers</param-name>
<param-value>com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider</param-value>
</init-param>
</servlet>

<servlet-mapping>
<servlet-name>CXFNonSpringJaxrsServlet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>

</web-app>
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ public class JavaCXFServerOptionsProvider extends JavaOptionsProvider {
public static final String ADD_CONSUMES_PRODUCES_JSON = "true";

public static final String IMPL_FOLDER_VALUE = "src/main/java";

public static final String USE_ANNOTATED_BASE_PATH = "true";

public static final String GENERATE_NON_SPRING_APPLICATION = "true";

@Override
public boolean isServer() {
Expand Down Expand Up @@ -85,6 +89,10 @@ public Map<String, String> createOptions() {

builder.put(JavaCXFServerCodegen.ADD_CONSUMES_PRODUCES_JSON, ADD_CONSUMES_PRODUCES_JSON);

builder.put(JavaCXFServerCodegen.USE_ANNOTATED_BASE_PATH, USE_ANNOTATED_BASE_PATH);

builder.put(JavaCXFServerCodegen.GENERATE_NON_SPRING_APPLICATION, GENERATE_NON_SPRING_APPLICATION);

return builder.build();

}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Swagger Codegen Ignore
# Generated by swagger-codegen https://github.com/swagger-api/swagger-codegen

# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.

# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell Swagger Codgen to ignore just this file by uncommenting the following line:
#ApiClient.cs

# You can match any string of characters against a directory, file or extension with a single asterisk (*):
#foo/*/qux
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux

# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
#foo/**/qux
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux

# You can also negate patterns with an exclamation (!).
# For example, you can ignore all files in a docs folder with the file extension .md:
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md
Loading