npm install -g @stoplight/prism-cli
{
"openapi": "3.0.0",
"info": {
"title": "Sample Mock API",
"version": "1.0.0"
},
"paths": {
"/users": {
"get": {
"summary": "Retrieve a list of users",
"responses": {
"200": {
"description": "A JSON array of user names",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"success": {
"type": "boolean"
},
"message": {
"type": "string"
},
"data": {
"type": "array"
}
}
},
"example": {
"success": true,
"message": "get user success",
"data": [
{
"id": 1,
"name": "alex",
"addresses": [
{
"street": "jln. jambu",
"postalCode": "0001"
},
{
"street": "jln. apel",
"postalCode": "0002"
}
]
},
{
"id": 2,
"name": "john",
"addresses": [
{
"street": "jln. kijang",
"postalCode": "0011"
},
{
"street": "jln. tiger",
"postalCode": "0012"
}
]
}
]
}
}
}
}
}
}
},
"/users/{userId}": {
"get": {
"summary": "Retrieve a specific user",
"parameters": [
{
"name": "userId",
"in": "path",
"required": true,
"schema": {
"type": "integer",
"example": 1
}
}
],
"responses": {
"200": {
"description": "A user object",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"success": {
"type": "boolean"
},
"message": {
"type": "string"
},
"data": {
"type": "object"
}
}
},
"example": {
"success": true,
"message": "get user by id success",
"data": {
"id": 1,
"name": "alex"
}
}
}
}
},
"404": {
"description": "User not found",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"success": {
"type": "boolean",
"example": false
},
"message": {
"type": "string",
"example": "user not found"
}
}
}
}
}
}
}
}
},
"/articles": {
"get": {
"summary": "Retrieve a list of articles",
"parameters": [
{
"name": "createdAt",
"in": "query",
"required": false,
"schema": {
"type": "string",
"example": "2024-09-24"
}
}
],
"responses": {
"200": {
"description": "A JSON array of articles",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"success": {
"type": "boolean"
},
"message": {
"type": "string"
},
"data": {
"type": "array"
}
}
},
"example": {
"success": true,
"message": "ger articles success",
"data": [
{
"id": 1,
"title": "Artificial Intelligence",
"content": "Artificial Intelligence xxxxxx xxxxxx xxxxx",
"author": "Robert D.",
"createdAt": "2024-08-29"
}
]
}
}
}
},
"404": {
"description": "Articles empty",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"success": {
"type": "boolean",
"example": true
},
"message": {
"type": "string",
"example": "articles not found"
},
"data": {
"type": "array",
"example": []
}
}
}
}
}
}
}
}
}
}
}
prism mock user-openapi.json
prism mock user-openapi.json -p 5001
Simulate User List
http://127.0.0.1:4010/users
Simulate Find User By Id
http://127.0.0.1:4010/users/1
Simulate Find User By Id with return 404 Not Found
http://127.0.0.1:4010/users/1?__code=404