-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: mocking plugin #5940
feat: mocking plugin #5940
Conversation
hi, @Drery thanks for your contribution. Mock has many applications in front-end and back-end development and client troubleshooting scenarios. this is a good idea. However, I checked this PR. Its current completion rate is relatively low and only supports responses in a single data format.I think the simulation plug-in should support custom responses, custom data formats, custom headers, custom status codes, and custom timeouts to meet the basic simulation requirements. |
@juzhiyuan the kong's mocking plugin is support too simple.i design this plugin is reference to mock.js which is closer to the scenario used for front-end developer. https://github.com/nuysoft/Mock/wiki/Mock.Random |
Glad to know that, and I used mock.js to do mocking as well 😄 Could @shuaijinchao help to guide @Drery if we need this kind of plugin? |
|
hi @Drery, usually when we add new features, we need to send a cc @juzhiyuan |
yes, @Drery here is the mailing list of Proposals, see https://lists.apache.org/list?dev@apisix.apache.org:lte=1M:proposal Here is the mailing list subscription guide: https://apisix.apache.org/docs/general/subscribe-guide |
@shuaijinchao @juzhiyuan |
The mail link is https://lists.apache.org/thread/xbkwz2k1dpoxgpcs7gm8t8d6ddvq1dto |
Co-authored-by: leslie <59061168+leslie-tsang@users.noreply.github.com>
Co-authored-by: leslie <59061168+leslie-tsang@users.noreply.github.com>
@spacewander done, is it sorted as this? |
When you want to disable this plugin, it is very simple, | ||
you can delete the corresponding JSON configuration in the plugin configuration, | ||
no need to restart the service, it will take effect immediately: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When you want to disable this plugin, it is very simple, | |
you can delete the corresponding JSON configuration in the plugin configuration, | |
no need to restart the service, it will take effect immediately: | |
To disable this plugin, simply delete the corresponding JSON configuration in the plugin configuration, | |
there is no need to restart the service, the change will take effect immediately: |
Would be better ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
emm, I just copy this from other plugins~
Co-authored-by: leslie <59061168+leslie-tsang@users.noreply.github.com>
Co-authored-by: leslie <59061168+leslie-tsang@users.noreply.github.com>
@leslie-tsang done |
@shuaijinchao @juzhiyuan @leslie-tsang @spacewander 请各位大佬再看一下,还有不要再抠格式排版这种细节了好吗??? |
I can understand your impatience. This PR has been reviewed for a long time. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, There is some optimization of implementation like ctx.lua that can be done in another PR.
Thanks for your contribution, :)
@spacewander @leslie-tsang Thanks, I resolved the conflicts, please have a review again. |
@shuaijinchao |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, Great @Drery
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @Drery.
b1b789c
Co-authored-by: Bisakh <bisakhmondal00@gmail.com>
What this PR does / why we need it:
Background
usualy when we develop a new feature on website or miniprogram or mobile application, we go through 3 steps:
in step 2, the frontend need to mock the api’s parameter and response,to debug program,and if there’s multiple front-end applications,each app need to do mock.
consider this scenario,if our api gateway can support api mocking,the steps 2 will come down to:
and there is nothing need to do for frontend developer,even neednt to change the api url.
based on the above scenario, the mocking plugin can be use in more scenario,such as:
when we pressure test the APISIX. we can use the mocking plugins to mock duration of api and status and response,instead of real upstream.
in microservice invocation chain,we can mock service one by one to find the abnormal service.
Plugin Design
this plugin design is reference to mock.js and kong's mocking plugin.
it is planned to be implemented in two phases.
phase 1, goal to implement base mock abilities.
the general design is as follows:
local schema = {
type = "object",
properties = {
-- specify response delay time,default 0ms
delay = { type = "integer" },
-- specify response status,default 200
response_status = { type = "integer" },
-- specify response content type,support application/xml,text/plain and application/json,default application/json
content_type = { type = "content_type" },
-- specify response body.
response_example = {type = "string"},
-- specify response json schema,if response_example is not nil,this conf will be ignore.
-- generate random response by json schema.
response_schema = { type = "object" },
},
anyOf = {
{required = {"response_example"}},
{required = {"response_schema"}}
}
}
phase 2, goal to implement higher-order ability,such as "expectation and response patterns" and file download.
Related Discussion is #5896
The mail link is https://lists.apache.org/thread/xbkwz2k1dpoxgpcs7gm8t8d6ddvq1dto
Pre-submission checklist:
Did you explain what problem does this PR solve? Or what new features have been added?
others
What do you think about this idea?
i just commit the plugin code and chinese document now, If the idead works, i can attach else neccessary.