by Devin Yang
(This article was automatically translated.)

Published - 6 years ago ( Updated - 6 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,container,laravel

Manually update the full record of D-Laravel's user id on Nas

This article fully records how I update the uid of the fpm image on my Nas. In this article, you should learn to query related concepts such as container id and commit container.

docker,phpenv

Ran out of Docker IPv4 address pool problem solving

Maybe in the old version of the docker environment, when using Docker compose to start the container, you will encounter the following error: Error response from daemon: could not find an available, non-overlapping IPv4 address pool among the defaults to assign to the network This is actually this It is a symptom of running out of default-address-pools. In some environments, docker-compose will use the private network of Class B by default. The private IP of segment 172 has a range, from 172.16.0.0 to 172.31.255.255. That is to say, when we start a docker-compose Project, it will eat a private section of Class B, which is very heroic.

docker,laravel

How to use multiple YAML files to execute multiple docker container services

This video introduces how to use the docker-compose command to specify multiple YAML structure language configuration files to create container execution, and introduces how we simplify docker-compose by using .env in the D-Laravel environment Start command.