by Devin Yang
(This article was automatically translated.)

Published - 5 years ago ( Updated - 5 years ago )

Foreword

The best APIs are built using the Swagger tool,
This article introduces how to use docker to execute swagger-ui and editor, let us create a testable API file.
In the docker environment, we can easily start the swagger editor and user interface.

Simple Docker

Start the swagger editor

docker run --rm p 8082:8080 swaggerapi/swagger-editor

In the example above, I added --rm, which means that when the container is stopped, the container will be removed.

You can set whether to expand by default

API_URL loads the default file.

DOC_EXPANSION is set to no expansion by default.

docker run --rm -d -p 8083:8080 -e API_URL=https://raw.githubusercontent.com/DevinY/openapi/master/openapi-jwt.yaml -e DOC_EXPANSION='none' swaggerapi /swagger-ui

The -e here represents the environment variable passed into the container, which can pass in environment variables, such as default files.

In addition, the default editor and UI in this article use the 8082 and 8083 ports of this machine respectively. If the port is occupied, please adjust it according to your own preferences.

We can easily upload and import json or yaml configuration files via URL or file in swagger-editor.
swagger-ui
Here I provide a JWT Sample, which should be able to get started quickly, and the setting is very intuitive.
https://raw.githubusercontent.com/DevinY/openapi/master/openapi -jwt.yaml

Some reference documents:
https://swagger.io/docs/specification/data-models/data- types/
https://swagger.io/docs/specification/describing-responses/
https://swagger.io/docs/specification/describing-request-body/
https://swagger.io/docs/specification/authentication/bearer-authentication/
 

D-Laravel environment

If you use D-Laravel, you can also load it through D-Laravel's .env

Or modify your own docker-compose.yml file, and copy the settings to your own docker-compose.yml according to the swagger example on the service.

D-Laravel has added swagger-editor.yml and swagger-ui.yml to the service in version v1.6.18.

#===When you use the .env function of D-Laravel, please use the instructions provided by D-Laravel to control the container!===
#MYSQL_ROOT_PASSWORD=secret
LARAVEL_INSTALLER='container'
DOCKER_SERVICES='docker-compose.yml service/redis.yml service/swagger-editor.yml service/swagger-ui.yml'

Tags: docker api

Devin Yang

Feel free to ask me, if you don't get it.:)

No Comment

Post your comment

Login is required to leave comments

Similar Stories


docker

How to update or rebuild D-Laravel's FPM Image

Sometimes, the docker image will undergo some corrections or add more plug-ins, how do we update the image in the computer? It's very simple, use docker pull [use the image], if you want to create your own image is also feasible...

docker,laravel

It's super easy to build a Lravel development environment with Docker

Are you ready for the Laravel 5.5 system environment? laravel/framework 5.5.x-dev requires php >=7.0 -> your PHP version (5.6.30) does not satisfy that requirement. This article describes how to create a Laravel development environment using Docker. With the simple to explosive D-Laravel simple bash, Don't say that I can't set up a Laravel development environment.

laravel docker

About D-Laravel's project mode

If you are a new user, I suggest you use my latest environment phpenv instead. https://github.com/DevinY/phpenv