-
Notifications
You must be signed in to change notification settings - Fork 6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue 5431 Support jaxrs client api interfaces (#6412)
* Adds the ability to create code for an interface-based jaxrs client. * Adds shell script and sample files for jaxrs-spec-interface * rebase into adds shell * Fixes bug in creation of Produces/Consumes in method annotation. Allows for instance "application/json; charset=utf-8" * Fixes generated pom.xml * Generate pom.xml by default * Prettier output from api.mustache * Fixes bug in mediatype, allowing charset-specification in swagger.yaml. * Merges generation of interface-based jaxrs client/api into jaxrs-spec. * Moves jaxrs-spec server interface to match location of jaxrs-spec server * Makes Generated-annotation in genereated classes slightly prettier.
- Loading branch information
Showing
58 changed files
with
6,054 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/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 -i modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -l jaxrs-spec -o samples/server/petstore/jaxrs-spec-interface | ||
-DhideGenerationTimestamp=true | ||
-DinterfaceOnly=true" | ||
|
||
java $JAVA_OPTS -jar $executable $ags |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
modules/swagger-codegen/src/main/resources/JavaJaxRS/spec/apiInterface.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
@{{httpMethod}}{{#subresourceOperation}} | ||
@Path("{{{path}}}"){{/subresourceOperation}}{{#hasConsumes}} | ||
@Consumes({ {{#consumes}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/consumes}} }){{/hasConsumes}}{{#hasProduces}} | ||
@Produces({ {{#produces}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/produces}} }){{/hasProduces}} | ||
@ApiOperation(value = "{{{summary}}}", notes = "{{{notes}}}"{{#hasAuthMethods}}, authorizations = { | ||
{{#authMethods}}@Authorization(value = "{{name}}"{{#isOAuth}}, scopes = { | ||
{{#scopes}}@AuthorizationScope(scope = "{{scope}}", description = "{{description}}"){{#hasMore}}, | ||
{{/hasMore}}{{/scopes}} | ||
}{{/isOAuth}}){{#hasMore}}, | ||
{{/hasMore}}{{/authMethods}} | ||
}{{/hasAuthMethods}}, tags={ {{#vendorExtensions.x-tags}}"{{tag}}"{{#hasMore}}, {{/hasMore}}{{/vendorExtensions.x-tags}} }) | ||
@ApiResponses(value = { {{#responses}} | ||
@ApiResponse(code = {{{code}}}, message = "{{{message}}}", response = {{{baseType}}}.class{{#returnContainer}}, responseContainer = "{{{returnContainer}}}"{{/returnContainer}}){{#hasMore}},{{/hasMore}}{{/responses}} }) | ||
{{>returnTypeInterface}} {{nickname}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#hasMore}},{{/hasMore}}{{/allParams}}); |
16 changes: 16 additions & 0 deletions
16
modules/swagger-codegen/src/main/resources/JavaJaxRS/spec/apiMethod.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
@{{httpMethod}}{{#subresourceOperation}} | ||
@Path("{{{path}}}"){{/subresourceOperation}}{{#hasConsumes}} | ||
@Consumes({ {{#consumes}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/consumes}} }){{/hasConsumes}}{{#hasProduces}} | ||
@Produces({ {{#produces}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/produces}} }){{/hasProduces}} | ||
@ApiOperation(value = "{{{summary}}}", notes = "{{{notes}}}", response = {{{returnBaseType}}}.class{{#returnContainer}}, responseContainer = "{{{returnContainer}}}"{{/returnContainer}}{{#hasAuthMethods}}, authorizations = { | ||
{{#authMethods}}@Authorization(value = "{{name}}"{{#isOAuth}}, scopes = { | ||
{{#scopes}}@AuthorizationScope(scope = "{{scope}}", description = "{{description}}"){{#hasMore}}, | ||
{{/hasMore}}{{/scopes}} | ||
}{{/isOAuth}}){{#hasMore}}, | ||
{{/hasMore}}{{/authMethods}} | ||
}{{/hasAuthMethods}}, tags={ {{#vendorExtensions.x-tags}}"{{tag}}"{{#hasMore}}, {{/hasMore}}{{/vendorExtensions.x-tags}} }) | ||
@ApiResponses(value = { {{#responses}} | ||
@ApiResponse(code = {{{code}}}, message = "{{{message}}}", response = {{{baseType}}}.class{{#containerType}}, responseContainer = "{{{containerType}}}"{{/containerType}}){{#hasMore}},{{/hasMore}}{{/responses}} }) | ||
public Response {{nickname}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#hasMore}},{{/hasMore}}{{/allParams}}) { | ||
return Response.ok().entity("magic!").build(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
modules/swagger-codegen/src/main/resources/JavaJaxRS/spec/returnTypeInterface.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{{#returnContainer}}{{{returnContainer}}}<{{/returnContainer}}{{{returnType}}}{{#returnContainer}}>{{/returnContainer}} |
77 changes: 77 additions & 0 deletions
77
...er-codegen/src/test/java/io/swagger/codegen/languages/JavaJAXRSSpecServerCodegenTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package io.swagger.codegen.languages; | ||
|
||
import io.swagger.codegen.CliOption; | ||
import io.swagger.codegen.SupportingFile; | ||
import io.swagger.models.properties.BooleanProperty; | ||
import org.junit.Test; | ||
import org.testng.Assert; | ||
|
||
public class JavaJAXRSSpecServerCodegenTest { | ||
|
||
private JavaJAXRSSpecServerCodegen generator = new JavaJAXRSSpecServerCodegen(); | ||
|
||
@Test | ||
public void do_not_process_RestApplication_when_interfaceOnly_is_true() { | ||
generator.additionalProperties().put(JavaJAXRSSpecServerCodegen.INTERFACE_ONLY, "true"); | ||
generator.processOpts(); | ||
for (SupportingFile file : generator.supportingFiles()) { | ||
Assert.assertNotEquals("RestApplication.mustache", file.templateFile); | ||
} | ||
} | ||
|
||
@Test | ||
public void do_process_pom_by_default() { | ||
generator.processOpts(); | ||
for (SupportingFile file : generator.supportingFiles()) { | ||
if ("pom.mustache".equals(file.templateFile)) { | ||
return; | ||
} | ||
} | ||
Assert.fail("Missing pom.mustache"); | ||
} | ||
|
||
@Test | ||
public void process_pom_if_generatePom_is_true() { | ||
generator.additionalProperties().put(JavaJAXRSSpecServerCodegen.GENERATE_POM, "true"); | ||
generator.processOpts(); | ||
for (SupportingFile file : generator.supportingFiles()) { | ||
if ("pom.mustache".equals(file.templateFile)) { | ||
return; | ||
} | ||
} | ||
Assert.fail("Missing pom.mustache"); | ||
} | ||
|
||
@Test | ||
public void do_not_process_pom_if_generatePom_is_false() { | ||
generator.additionalProperties().put(JavaJAXRSSpecServerCodegen.GENERATE_POM, "false"); | ||
generator.processOpts(); | ||
for (SupportingFile file : generator.supportingFiles()) { | ||
Assert.assertNotEquals("pom.mustache", file.templateFile); | ||
} | ||
} | ||
|
||
@Test | ||
public void verify_that_generatePom_exists_as_a_parameter_with_default_true() { | ||
for (CliOption option : generator.cliOptions()) { | ||
if (option.getOpt().equals(JavaJAXRSSpecServerCodegen.GENERATE_POM)) { | ||
Assert.assertEquals(BooleanProperty.TYPE, option.getType()); | ||
Assert.assertEquals("true", option.getDefault()); | ||
return; | ||
} | ||
} | ||
Assert.fail("Missing " + JavaJAXRSSpecServerCodegen.GENERATE_POM); | ||
} | ||
|
||
@Test | ||
public void verify_that_interfaceOnly_exists_as_a_parameter_with_default_false() { | ||
for (CliOption option : generator.cliOptions()) { | ||
if (option.getOpt().equals(JavaJAXRSSpecServerCodegen.INTERFACE_ONLY)) { | ||
Assert.assertEquals(BooleanProperty.TYPE, option.getType()); | ||
Assert.assertEquals("false", option.getDefault()); | ||
return; | ||
} | ||
} | ||
Assert.fail("Missing " + JavaJAXRSSpecServerCodegen.INTERFACE_ONLY); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
samples/server/petstore/jaxrs-spec-interface/.swagger-codegen-ignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
1 change: 1 addition & 0 deletions
1
samples/server/petstore/jaxrs-spec-interface/.swagger-codegen/VERSION
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
2.3.0-SNAPSHOT |
Oops, something went wrong.