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


laravel,docker

How to customize Laravel pagination

Recently, I have been free, and I want to adjust the arrows on the upper and lower pages of the website. If you don’t know how to customize Laravel’s pagination, You can take a look at a short three-minute introduction on how I customize Laravel's pagination.

polymer,docker

D-Laravel supports index.html by default

D-Laravel's nginx environment settings support index.html by default, simply put Now, besides, D-Laravel can be used to run Laravel's Project, and it can also be used to run other Projects. Currently Apple's WebKit is already in preview for Service-Workers....

docker

The use of iptabels is required in the Docker Swarm environment

First of all, in the Linux environment, Docker uses iptables rules to provide network isolation. However, in the environment of Docker swarm mode, we cannot identify the connection port under 127.0.0.1 of the host. At this time, we can customize the rules through the DOCKER-USER chain in iptables.