Deploying Swagger-Enabled Endpoints With Websphere Liberty in Aix
Deploying Swagger-Enabled Endpoints With Websphere Liberty in Aix
10. Repeat Step 3 to redeploy the modified web application. The API can be now
accessible as,
http://example.ibm.com:9080/simple-service-
webapp/webapi/myresource/hello/joe
By accessing the URL, you will get the hello message with the user name “joe”
printed in the webpage.
Swagger Overview
Swagger is a open source project created to standardize the way REST APIs are best
described and documented. The swagger specification defines a set of files(swagger.json) to
describe a RESTful API. There are two major sub-project under Swagger,
1. Swagger-ui (http://swagger.io/swagger-ui/):
a. This utility is a web based tool used to display the API and its
documentation based on the swagger definition files defined by the API
provider in a user friendly way.
b. It also provides a way to the end users to try out the API right from the
web interface even before its integrated to their application.
2. Swagger-codegen (http://swagger.io/swagger-codegen/):
a. This command line utility is capable of generating client library code
based on the swagger specification file in many popular languages so that
the REST APIs can be easily consumed by end users.
b. It is capable of generating the server stub code in many popular web
frameworks based on a swagger definition file. API developers can insert
the business core logic into the templated generated by the tool.
More information related to Swagger specification can be found in
http://swagger.io/specification/.
Adding Swagger Definitions
Before publishing the created REST API, proper documentation is required in a
standardized way. Swagger has standardized the REST API documentation & also made it easier
for getting it discovered inside API Managers.
So it’s time to add a Swagger compliant documentation to our Web Service by following
the steps,
1. The annotations are added to the class names and method names as follows,
2. The swagger annotations will be resolved only after you add the following
dependencies inside the base directory’s pom.xml file,
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-jersey2-jaxrs</artifactId>
<version>1.5.9</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
3. Next step to get swagger definitions ready for our simple rest API is to add the
Bootstrap code (Bootstrap.java) to our web application under the package
“com.ibm.helpers”,
4. In order to make sure the swagger code gets initialized make the necessary
changes to the web.xml found under ./src/main/webapp/WEB-INF/ directory as
follows,
5. The project should be rebuilt using “mvn package” and the generated “.war” file
should be redeployed to WebSphere Liberty Profile server.
6. Now along with the web service, a swagger definition file is also made available
under the URL:
http://example.ibm.com:9080/simple-service-webapp/webapi/swagger.json
Integration with WebSphere’s ApiDiscovery Feature
ApiDiscovery is a feature of WebSphere Liberty Profile that can be installed & loaded
separately to the existing WebSphere Liberty Profile server runtime by executing the following
command after getting into the WebSphere Liberty Profile install directory,
To make this feature available to the server configuration add the following line under
the featureManager tag to the server.xml,
<feature>apiDiscovery-1.0</feature>
Here is a snapshot of the server.xml file after the change,
After enabling this feature, you can access the following URL:
https://example.ibm.com:9443/ibm/api/explorer
To include the web applications discoverable, add the following line in server.xml,
Now the Swagger UI for the newly created API is seen as follows,
This is the type of UI that will be used by Application developer who want to use the REST
Api exposed by your organization. The UI gives them the option to interact by providing them
“Try it out” button right from the documentation page.
Reference:
1. https://jersey.java.net/
2. http://swagger.io/
3. https://maven.apache.org/download.cgi
4. https://developer.ibm.com/wasdev/downloads/liberty-profile-using-non-eclipse-
environments/