Swagger
-
Upload
riteshmodi -
Category
Documents
-
view
22 -
download
3
description
Transcript of Swagger
You just have visited http://swagger.wordnik.com/ and want to do similar thing for your own REST APIs.
Assumption: Your web application is using maven as build tool, RESTEasy as Framework to implement JAX-RS standard for REST APIs, Spring Framework to inject dependencies and JBOSS(JBOSS-AS-7.1.1.Final) as Web Application Server. With Eclipse IDE
Now you want to add Swagger Framework to document the REST API in more beautiful way.
We will do it in mainly 2 Steps:We will I integrate Swagger jars with our web application to get get dynamic JSON representation of all the APIs.
We will integrate this JSON representation with swagger-ui to get beautiful interacting UI.
Goal: Dynamic JSON representation of APIs:
Add dependencies of swagger jars in your pom.xml(maven) and add it in class path.
Annotate all your API with swagger annotation. Swagger jars will read these annotations dynamically and will build corresponding json.
We need to configure the swagger apis with our application or we need to tell application that read these swagger rest apis.
Need to configure base path for application so that we can test the api through swagger when application is deployed (sandbox testing)
Deploy the application and can check whether we are getting JSON respresentaion of APIs.
Goal: Integration of JSON representation with swagger UI:Download
the swagger ui from repository. Put it into Web-INF and configure
the location and voilla !!
Creating sample resteasy REST application
You need to have java, maven and Eclipse up and running in your system. Please search the internet and get everything ready.
Now create empty Folder, in my case HelloRestEasy and create src folder inside it.Create one empty xml file named pom.xml
Now open pom.xml in your favorite text editor and copy the following lines:
4.0.0org.resteasyHelloRestEasy1war
UTF-8
We are creating empty maven project.
Now go inside the src folder and create empty main folder.
Then go inside main folder and create two empty folders: java and resources folders.
Final folder structure will look like:HelloWorldRestEasy+++src----------main############java############resources+++pom.xml
Now Go to the HelloWorldRestEasy folder and open up your command prompt in HelloWorldRestEasy folder and type mvn eclipse:eclipseYou will get Build Success
If you have problem till this point then please search on internet and get things working. You will find a lot of help on internet as all are basic stuff till this point.