This is a Java project to build a stand-alone server generated from a Swagger Java object which implements the Swagger spec. You can find out more about both the spec and the framework at http://swagger.io.
We could also just run a Apache httpd to expose all generated JSON and generate swagger UI pages that point to them.
# Put everything in /data/jetty and everything accessible at http://localhost:8081/myfile.json
docker run -dit --name httpd -p 8081:80 -v /data/jetty:/usr/local/apache2/htdocs/ httpd:2.4
To run the server, run this task:
mvn jetty:run-war
This will start Jetty embedded on port 8080.
Access it at http://localhost:8080/
docker build -t generate-java-swagger-api .
docker run -p 8080:8080 generate-java-swagger-api
Once started, you can navigate to http://localhost:8080/api/swagger.json to view the Swagger Resource Listing. This tells you that the server is up and ready to demonstrate Swagger.
There is an HTML5-based API tool bundled in this sample, you can view it it at http://localhost:8080. This lets you inspect the API using an interactive UI. You can access the source of this code from here
You can then open the dist/index.html file in any HTML5-enabled browser. Upen opening, enter the URL of your server in the top-centered input box (default is http://localhost:8080/api/swagger.json). Click the "Explore" button and you should see the resources available on the server.
The sample app has an implementation of the Swagger ApiAuthorizationFilter. This restricts access to resources based on api-key. There are two keys defined in the sample app:
- default-key
- special-key
When no key is applied, the "default-key" is applied to all operations. If the "special-key" is entered, a number of other resources are shown in the UI, including sample CRUD operations.
Project built from https://github.com/tminglei/binder-swagger-java/tree/master/example/java-jaxrs