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

Install docker-compose on ubuntu

Briefly introduce how I installed docker-compose on ubuntu. Quite easy.

docker,phpenv

Unable to ping host.docker.internal on Linux

You can check with docker version, confirm that the version is Docker v20.10+, you can add extra_hosts as follows:

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