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.

docker,dlaravel

D-Laravel 1.5.5 Change Notes

D-Laravel's fpm image was rebuilt using the official dockerfile of docker php before php 7.2.1. And so I can specify that the default owner of fpm is dlaravel, --with-fpm-user=USER Set the user for php-fpm to run as. (default: nobody) --with-fpm-group=GRP Set the group for php-fpm to run as.

docker,polymer,seo

Solving Polymer SEO Problems with Rendertron (Polymer Summit 2017)

The video below the article introduces how to use rendertron to solve Polymer SEO optimization problems. In the source of my fork, it has been adjusted to support the Chinese environment. And also added the API interface of pdf, which can also be used to convert pdf.