Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
622 views
in Technique[技术] by (71.8m points)

mocking - Swagger/OpenAPI mock server

I have an API reference in a Swagger file. I want to create a very simple mock server, so that when I call e.g.:

mymockurl.com/users it will return a predefined JSON (no need to connect to a database).

What's the easiest way to do this? I'm not a backend guy.

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

An easy way to create simple mock from an OpenAPI (fka Swagger) spec without code is to use a tool call prism available at http://github.com/stoplightio/prism written in Typescript.

This command line is all you need:

./prism run --mock --list --spec <your swagger spec file>

The mock server will return a dynamic response based on the OpenAPI spec. If examples are provided in the spec, prism will return them, if not it will generate dummy data based on the spec.

Edit (Aug 2020):

The command has changed in the latest version. The following will do:

prism mock <your spec file>

It accepts swagger and postman doc as well.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...