Swagger is an API construction framework that can make API document design and API mock (prototype) requests. The Swagger tools used this time are the following three.
tool | Explanation |
---|---|
Swagger Spec | (Spec = Specification = Specification) This is a document related to Swagger specifications, and is YAML./Written in JSON format. |
Swagger Editor | A tool that allows you to edit Swagger Spec files that run on your browser and check the syntax in real time. |
Swagger UI | A tool that dynamically generates documents from Swagger Spec. |
For other Swagger related tools, please check the link on the official page.
First, I tried to illustrate how the Swagger Editor and Swagger UI are used, with the Swagger Spec file generation as the main axis. As an image used this time, use Swagger Editor to edit and define SwaggerSpec which is the API specification on the browser, and if you can confirm the syntax, enter it in the actual yaml file so that you can refer to it from Swagger UI. It is a flow.
Setting point:
docker-compose.yml
to create Swagger Editor and Swagger UI images.sample.yaml
.docker-compose.yml
version: '3.7'
services:
swagger-editor:
image: swaggerapi/swagger-editor
ports:
- "8001:8080"
swagger-ui:
image: swaggerapi/swagger-ui
ports:
- "8002:8080"
volumes:
- ./sample.yaml:/sample.yaml
environment:
SWAGGER_JSON: sample.yaml
Directory structure
├── docker-compose.yaml
└── sample.yaml
Do the following in your terminal:
Terminal
$ docker-compose up
Swagger Editor starts at https: // localhosst: 8001
, and Swagger UI starts at https: // localhost: 8002
.
Recommended Posts