bin | ||
conf/java | ||
src/main/java/com/wordnik/swagger | ||
.gitignore | ||
build.xml | ||
ivy.xml | ||
ivysettings.xml | ||
README.md |
Swagger Client Code-Generator
Overview
This is a project to build the Swagger code-gen library which can be used to automatically generate client libraries from a Swagger-compliant server. It also contains a testing framework which allows the client library to query an API server and validate expected results You can find out more about both the spec and the framework at http://swagger.wordnik.com. For more information about Wordnik's APIs, please visit http://developer.wordnik.com.
Prerequisites
You need the following installed and available in your $PATH:
To build the codegen library
If you don't have the Apache Ivy dependency manager installed, run this build script:
ant -f install-ivy
This will copy the ivy ant lib into your antlib directory. Now you can build the artifact:
ant
This will create the swagger-codegen library in your build folder.
To build a client library
./bin/generate-java-lib.sh {server-url} {api_key} {output-package} {output-dir}
for example:
./bin/generate-java-lib.sh http://petstore.swagger.wordnik.com/api/ special-key com.sample.petstore generated
To build a client library for a different programming language, refer to the
conf/java/templatesfolder for sample code templates. The code-gen uses the antlr string template library for generating the output files, please look at http://www.stringtemplate.org for details on the antlr framework.
The files in the
conf/structurefolder are copied by default to the destination directory.
The main class for the generator is at src/main/java/com/wordnik/swagger/codegen/config/java/JavaLibCodeGen.java
The Swagger client test framework
The testing framework helps you to test Swagger generated client libraries using declarative test scripts. The same scripts can be used to test client libraries in different languages. The framework can be used for client and server regression testing.
There are two components in the test framework:
Test script details
Test script is written in JSON structure. The JSON consists of following elements:
Resources. This is a list of resources considered in the test. Each resource object consists of following properties:
Test suites. This is a logical way of grouping related test cases. Each test suite consists of following properties:
Each assertion contains
Test data file is documented using a Test Data Object which is generated as part of Java client library code-gen. This class provides list getters and setters for each model object available in the resource description. It is called "TestData" and it is available in model package of the java library code generation output.
Chaining results of test cases:
${input., followed by object graph navigation syntax. Example: to refer a first user object in test data file use the syntax
${input.userList[0]}
${input.userList[0].username}
${output.
${output(1.2)}. Individual attributes can be accessed using OGNL syntax. Example:
${output(1.1).username}
Reporting Test Results
A Summary will be reported with each test run. For instance:
Sample: "Summary --> Total Test Cases: 9 Failed Test Cases: 0"
In detail section each test case and its status (passed/failed) are reported. Failures include an exception trace. Test case path is combination of test suite id and test case id separated by "."