Swagger Restful interface to set up a tutorial
I. Introduction
Swagger is a document RESTFUL online interface to automatically generate functional test function + software, with many companies now realize the separation of the front and rear end, swagger more and more popular.
Chinese official website: http://www.sosoapi.com/
Second, the historical version (dry goods out of print)
In fact, there are two versions of swagger, but the difference is so large, is a swagger-ui is swagger1; there is a springfox-swagger is swagger2; many people do not know to confuse the two versions each there will each characteristic, this blog first say swagger-ui.
Third, the version a (swagger-ui)
By entering /dist/index.html 8080 / Project with path: http: // localhost direct access to your page.
I was http: // localhost: 8080 / swagger_springmvc / dist / index.html # /
Fourth, ready to work
The front end html download
Download dist file
- swagger-ui first need to download the HTML version, there are two ways
- The first: download html from github,;
https://github.com/swagger-api/swagger-ui
Caution
If you take the first way to download it, be sure to note the version, do not download the latest version dist otherwise swagger-ui is not supported. To download the 2.x version.
Address: https: //github.com/swagger-api/swagger-ui/tree/2.x/dist
personal recommendations or downloaded from my blog, after all I've somehow gave.
Jar package download
<!-- Swagger包 --> swagger-springmvc 1.0.2 swagger-models 1.0.2 swagger-annotations 1.3.11 <-! JSON wrapped -> json-lib 2.4 <-! JACKSON follicles -> jackson-annotations 2.6.5 jackson-databind 2.6.5 jackson-core 2.6.5
Note
these versions jar package can not be changed, if the version changed probably because the version of reason can not be achieved, says the simplest version Swagger jar package if changed, it is not very likely, before this blogger personally tested .
If your project is a maven project, then the proposal is to give these to their own jar package with maven repository. Pom file and then introduced, like my case.
Of course, you can also directly add the introduction of personal recommendations or on the pom in fairly standard.
Fifth, code implementation
jar package introduced
To say that the introduction of the jar package before the (Chapter III).
The introduction of front-end file dist
Copy the downloaded file to the dist webapp directory. (I use the myeclipse, different software names may be different)
Url modify the index.html file in dist folder will become the url url modify your project swagger naming convention is IP + port number + project root path (if you have the project root path if) + api-docs
Precautions
After the URL API-docs is fixed
Config Configuration
New config folder, the new swagger.java file in the file, start the configuration information.
Then the introduction of the present document profile
Controller Notes
There are two ways to control layer may show according to our preferences.
method one
Second way
Both approaches can watch you like that kind of writing.
Sixth, the results show access
Start project access address
address + IP + port number of projects with the path + / dist / index.html # /
I is http: // localhost: 8080 / swagger_springmvc / dist / index.html # / Do not change the suffix is fixed