Install
npx @stoplight/prism-cli
docker-compose.yml
version: '3.9'services: prism: image: stoplight/prism:4 command: 'mock -h 0.0.0.0 /tmp/test-api.yaml' volumes: - ./test-api.yaml:/tmp/test-api.yaml:ro ports: # Serve the mocked API locally as available on port 4010 - '4010:4010'
test-api.yaml
openapi: 3.0.1
info:
title: anisAPI
version: '1.0'
paths:
'/getName/{userId}':
parameters:
- schema:
type: integer
name: userId
in: path
required: true
description: Id of an existing user.
get:
summary: Get User Info by User ID
tags: []
responses:
'200':
description: User Found
content:
application/json:
schema:
$ref: '#/components/schemas/User'
'404':
description: User Not Found
operationId: get-users-userId
description: Retrieve the information of the user with the matching user ID.
'/getName':
parameters:
- schema:
type: string
name: emailId
in: query
required: true
description: Email of an existing user.
get:
summary: Get User Info by User Email
tags: []
responses:
'200':
description: User Found
content:
application/json:
schema:
$ref: '#/components/schemas/User'
'404':
description: User Not Found
operationId: get-users-email
description: Retrieve the information of the user with the matching user email.
components:
schemas:
User:
title: User
type: object
description: ''
properties:
id:
type: integer
description: Unique identifier for the given user.
firstName:
type: string
lastName:
type: string
email:
type: string
format: email
required:
- id
- firstName
- lastName
- email
準備好swagger yaml檔後
docker-compose up


> Info(from stoplightio/prism github)
Cannot access mock server when using Docker?
Prism uses localhost by default, which usually means 127.0.0.1. When using docker the mock server will be unreachable outside of the container unless you run the mock command with -h 0.0.0.0
.
Reference