-
Notifications
You must be signed in to change notification settings - Fork 6k
adding support for both Java client using Netflix Feign and JMeter tests #1625
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
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
be94465
added initial Netflix Feign support
077a24f
updated README.md on the new Netflix Feign library
3cf8f24
updated README.md on the new Netflix Feign library
4b9b7a6
updated README.md on the new Netflix Feign library
7272cb0
fixed feign api template
a7f225b
added support for generating JMeter project from swagger
845dd22
added missing JMeter files
ff7d177
Delete gen-config.json
davidkiss 83223ae
rolling back previous accidental push on changes to pom.xml files
62c9a3d
Merge remote-tracking branch 'origin/master'
44c2751
added missing files to support JMeter
9cfb1c9
removing references to fork in te main README.md file
bb4589d
cleaned up README.md
davidkiss 340e8b3
reverting changes to swagger-codegen pom.xml
davidkiss 21e8822
cleaned up output folder from repo
eb0e474
Add petstore client sample for Java-feign
xhh eb4acd0
added unit tests to feign client
davidkiss 538ccb3
Merge remote-tracking branch 'xhh2/davidkiss-master'
davidkiss 1723078
added support in feign for binary uploads
davidkiss 0d19b30
using isBodyParam instead of vendorExtention.x-isBody
davidkiss File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,4 @@ | ||
| { | ||
| "library": "feign", | ||
| "artifactId": "swagger-petstore-feign" | ||
| } |
This file contains hidden or 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,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 -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l java -c bin/java-petstore-feign.json -o samples/client/petstore/java/feign" | ||
|
|
||
| java $JAVA_OPTS -jar $executable $ags |
This file contains hidden or 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 @@ | ||
| {"library":"feign"} |
This file contains hidden or 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
183 changes: 183 additions & 0 deletions
183
modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JMeterCodegen.java
This file contains hidden or 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,183 @@ | ||
| package io.swagger.codegen.languages; | ||
|
|
||
| import io.swagger.codegen.*; | ||
| import io.swagger.models.Operation; | ||
| import io.swagger.models.Path; | ||
| import io.swagger.models.Swagger; | ||
| import io.swagger.models.properties.*; | ||
| import org.apache.commons.lang.StringUtils; | ||
|
|
||
| import java.util.*; | ||
| import java.io.File; | ||
|
|
||
| public class JMeterCodegen extends DefaultCodegen implements CodegenConfig { | ||
|
|
||
| // source folder where to write the files | ||
| protected String sourceFolder = ""; | ||
| protected String apiVersion = "1.0.0"; | ||
|
|
||
| /** | ||
| * Configures the type of generator. | ||
| * | ||
| * @return the CodegenType for this generator | ||
| * @see io.swagger.codegen.CodegenType | ||
| */ | ||
| public CodegenType getTag() { | ||
| return CodegenType.CLIENT; | ||
| } | ||
|
|
||
| /** | ||
| * Configures a friendly name for the generator. This will be used by the generator | ||
| * to select the library with the -l flag. | ||
| * | ||
| * @return the friendly name for the generator | ||
| */ | ||
| public String getName() { | ||
| return "jmeter"; | ||
| } | ||
|
|
||
| /** | ||
| * Returns human-friendly help for the generator. Provide the consumer with help | ||
| * tips, parameters here | ||
| * | ||
| * @return A string value for the help message | ||
| */ | ||
| public String getHelp() { | ||
| return "Generates a JMeter .jmx file."; | ||
| } | ||
|
|
||
| public JMeterCodegen() { | ||
| super(); | ||
|
|
||
| // set the output folder here | ||
| outputFolder = "generated-code/JMeterCodegen"; | ||
|
|
||
| /** | ||
| * Api classes. You can write classes for each Api file with the apiTemplateFiles map. | ||
| * as with models, add multiple entries with different extensions for multiple files per | ||
| * class | ||
| */ | ||
| apiTemplateFiles.put( | ||
| "api.mustache", // the template to use | ||
| ".jmx"); // the extension for each file to write | ||
|
|
||
| apiTemplateFiles.put("testdata-localhost.mustache", ".csv"); | ||
|
|
||
| /** | ||
| * Template Location. This is the location which templates will be read from. The generator | ||
| * will use the resource stream to attempt to read the templates. | ||
| */ | ||
| templateDir = "JMeter"; | ||
|
|
||
| /** | ||
| * Api Package. Optional, if needed, this can be used in templates | ||
| */ | ||
| apiPackage = ""; | ||
|
|
||
| /** | ||
| * Model Package. Optional, if needed, this can be used in templates | ||
| */ | ||
| modelPackage = ""; | ||
|
|
||
| /** | ||
| * Reserved words. Override this with reserved words specific to your language | ||
| */ | ||
| reservedWords = new HashSet<String> ( | ||
| Arrays.asList( | ||
| "sample1", // replace with static values | ||
| "sample2") | ||
| ); | ||
|
|
||
| /** | ||
| * Additional Properties. These values can be passed to the templates and | ||
| * are available in models, apis, and supporting files | ||
| */ | ||
| additionalProperties.put("apiVersion", apiVersion); | ||
|
|
||
| // supportingFiles.add(new SupportingFile("testdata-localhost.mustache", "input", "testdata-localhost.csv")); | ||
| } | ||
|
|
||
| public void preprocessSwagger(Swagger swagger) { | ||
| if (swagger != null && swagger.getPaths() != null) { | ||
| for (String pathname : swagger.getPaths().keySet()) { | ||
| Path path = swagger.getPath(pathname); | ||
| if (path.getOperations() != null) { | ||
| for (Operation operation : path.getOperations()) { | ||
| String pathWithDollars = pathname.replaceAll("\\{", "\\$\\{"); | ||
| operation.setVendorExtension("x-path", pathWithDollars); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Escapes a reserved word as defined in the `reservedWords` array. Handle escaping | ||
| * those terms here. This logic is only called if a variable matches the reseved words | ||
| * | ||
| * @return the escaped term | ||
| */ | ||
| @Override | ||
| public String escapeReservedWord(String name) { | ||
| return "_" + name; // add an underscore to the name | ||
| } | ||
|
|
||
| /** | ||
| * Location to write model files. You can use the modelPackage() as defined when the class is | ||
| * instantiated | ||
| */ | ||
| public String modelFileFolder() { | ||
| return outputFolder + "/" + sourceFolder + "/" + modelPackage().replace('.', File.separatorChar); | ||
| } | ||
|
|
||
| /** | ||
| * Location to write api files. You can use the apiPackage() as defined when the class is | ||
| * instantiated | ||
| */ | ||
| @Override | ||
| public String apiFileFolder() { | ||
| return outputFolder + "/" + sourceFolder + "/" + apiPackage().replace('.', File.separatorChar); | ||
| } | ||
|
|
||
| /** | ||
| * Optional - type declaration. This is a String which is used by the templates to instantiate your | ||
| * types. There is typically special handling for different property types | ||
| * | ||
| * @return a string value used as the `dataType` field for model templates, `returnType` for api templates | ||
| */ | ||
| @Override | ||
| public String getTypeDeclaration(Property p) { | ||
| if(p instanceof ArrayProperty) { | ||
| ArrayProperty ap = (ArrayProperty) p; | ||
| Property inner = ap.getItems(); | ||
| return getSwaggerType(p) + "[" + getTypeDeclaration(inner) + "]"; | ||
| } | ||
| else if (p instanceof MapProperty) { | ||
| MapProperty mp = (MapProperty) p; | ||
| Property inner = mp.getAdditionalProperties(); | ||
| return getSwaggerType(p) + "[String, " + getTypeDeclaration(inner) + "]"; | ||
| } | ||
| return super.getTypeDeclaration(p); | ||
| } | ||
|
|
||
| /** | ||
| * Optional - swagger type conversion. This is used to map swagger types in a `Property` into | ||
| * either language specific types via `typeMapping` or into complex models if there is not a mapping. | ||
| * | ||
| * @return a string value of the type or complex model for this property | ||
| * @see io.swagger.models.properties.Property | ||
| */ | ||
| @Override | ||
| public String getSwaggerType(Property p) { | ||
| String swaggerType = super.getSwaggerType(p); | ||
| String type = null; | ||
| if(typeMapping.containsKey(swaggerType)) { | ||
| type = typeMapping.get(swaggerType); | ||
| if(languageSpecificPrimitives.contains(type)) | ||
| return toModelName(type); | ||
| } | ||
| else | ||
| type = swaggerType; | ||
| return toModelName(type); | ||
| } | ||
| } |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are
x-contentTypeandx-acceptssimilar toproducesandconsumes?In Java (and other programming languages), we've helper methods (defined in the generated code) to pick one ContentType and Accepts from a list of MIME types. Ref: https://github.com/swagger-api/swagger-codegen/blob/master/samples/client/petstore/java/default/src/main/java/io/swagger/client/ApiClient.java#L348
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
x-contentType and x-accepts is computed using the same logic as it's done with other java libraries. The reason I didn't use it for feign is that the generated Apis are interfaces and the values for content type and accepts are provided as constants in the Header annotation. Because of that, the api cannot call the methods in the ApiClient.