Sound Good. Looking forward to this plugins.

Leslie Tsang
leslie.ts...@icloud.com

> On 10 Jan 2022, at 10:11 AM, EH <rui1...@foxmail.com> wrote:
> 
> Sure, its a good advice, how about "x-mock-by: apisix"?
> 
> 
> 
> 
> ------------------&nbsp;原始邮件&nbsp;------------------
> 发件人:                                                                          
>                                               "dev"                           
>                                                          
> <leslie.ts...@icloud.com.INVALID <mailto:leslie.ts...@icloud.com.INVALID>&gt;;
> 发送时间:&nbsp;2022年1月9日(星期天) 下午5:57
> 收件人:&nbsp;"dev"<dev@apisix.apache.org <mailto:dev@apisix.apache.org>&gt;;
> 
> 主题:&nbsp;Re: [Proposal] api mocking plugin: generate mock response for 
> debegging,testing or pressure measurement.
> 
> 
> 
> LGTM, Shall we add a Header to notify the client that the response is 
> generated by the mock plugin ?
> 
> 
> Leslie Tsang
> leslie.ts...@icloud.com
> 
> &gt; On 6 Jan 2022, at 10:51 AM, EH <rui1...@foxmail.com&gt; wrote:
> &gt; 
> &gt; @shuaijinchao&amp;nbsp;Thank you for your attension.And I think these 
> two questions are actually same.
> &gt; Most of the time, we need a random response generated based on JSON 
> SCHEMA, because we usually define only the type of the response parameter, 
> not the value of the parameter, when defining the API.
> &gt; So when we need a random response based on JSON SCHEMA, we use the 
> `response_schema` param, and when we need a fixed response we use the 
> `response_example` param.
> &gt; Comparing the two plugins,the `mocking` plugin focuses more on mock the 
> response body of real apis&amp;nbsp;while the `fault-injection` focuses more 
> on mock the delay of apis.
> &gt; By the way, the 'mocking' plugin will next support returning different 
> response body based on different request headers and params.
> &gt; 
> &gt; 
> &gt; 
> &gt; 
> &gt; 
> &gt; 
> &gt; ------------------&amp;nbsp;原始邮件&amp;nbsp;------------------
> &gt; 
> 发件人:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
>  <shuaijinc...@apache.org <mailto:shuaijinc...@apache.org&gt;&amp;gt;;
> &gt; 发送时间:&amp;nbsp;2022年1月5日(星期三) 晚上7:09
> &gt; 收件人:&amp;nbsp;"dev"<dev@apisix.apache.org 
> <mailto:dev@apisix.apache.org&gt;&amp;gt;;
> &gt; 
> &gt; 主题:&amp;nbsp;Re: [Proposal] api mocking plugin: generate mock response 
> for debegging,testing or pressure measurement.
> &gt; 
> &gt; 
> &gt; 
> &gt; Hi, @EH Thank you very much for your suggestions
> &gt; 
> &gt; I have two questions:
> &gt; 1. Why is JSON response independent, instead of `response_body` that
> &gt; combines `response_example` and `response_schema` into one?
> &gt; 2. Do you think the `fault-injection`[1] plugin can meet the current 
> needs?
> &gt; 
> &gt; [1]
> &gt; 
> https://github.com/apache/apisix/blob/master/docs/zh/latest/plugins/fault-injection.md
>  
> <https://github.com/apache/apisix/blob/master/docs/zh/latest/plugins/fault-injection.md>
> &gt; 
> &gt; EH <rui1...@foxmail.com <mailto:rui1...@foxmail.com>&amp;gt; 
> 于2021年12月31日周五 15:43写道:
> &gt; 
> &gt; &amp;gt; *Background*
> &gt; &amp;gt; usualy when we develop a new feature on website or miniprogram 
> or mobile
> &gt; &amp;gt; application, we go through 3 steps:
> &gt; &amp;gt; 1. design api documents,include api path,paramter,response;
> &gt; &amp;gt; 2. develop frontend and backend at the same time;
> &gt; &amp;gt; 3. testing and debugging the frontend and backend program.
> &gt; &amp;gt;
> &gt; &amp;gt; in step 2, the frontend need to mock the api’s parameter and 
> response,to
> &gt; &amp;gt; debug program,and if there’s multiple front-end 
> applications,each app need
> &gt; &amp;gt; to do mock.
> &gt; &amp;gt;
> &gt; &amp;gt; consider this scenario,if our api gateway can support api 
> mocking,the
> &gt; &amp;gt; steps 2 will come down to:
> &gt; &amp;gt; 1. turn on mocking plugin when backend is still developing apis.
> &gt; &amp;gt; 2. turn off mocking plugin when the api is finished.
> &gt; &amp;gt; and there is nothing need to do for frontend developer,even 
> neednt to
> &gt; &amp;gt; change the api url.
> &gt; &amp;gt;
> &gt; &amp;gt; based on the above scenario, the mocking plugin can be use in 
> more
> &gt; &amp;gt; scenario,such as:
> &gt; &amp;gt;
> &gt; &amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; - when we pressure test the 
> APISIX. we can use the mocking plugins to
> &gt; &amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; mock duration of api and status 
> and response,instead of real upstream.
> &gt; &amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; - in microservice invocation 
> chain,we can mock service one by one to
> &gt; &amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; find the&amp;nbsp; abnormal 
> service.
> &gt; &amp;gt;
> &gt; &amp;gt; *Plugin Design*
> &gt; &amp;gt; this plugin design is reference to mock.js
> &gt; &amp;gt; <https://github.com/nuysoft/Mock/wiki/Mock.Random&amp;gt 
> <https://github.com/nuysoft/Mock/wiki/Mock.Random&amp;gt&gt;; and kong's 
> mocking
> &gt; &amp;gt; plugin <https://docs.konghq.com/hub/kong-inc/mocking/&amp;gt 
> <https://docs.konghq.com/hub/kong-inc/mocking/&amp;gt&gt;;.
> &gt; &amp;gt; it is planned to be implemented in two phases.
> &gt; &amp;gt;
> &gt; &amp;gt; phase 1, goal to implement base mock abilities.
> &gt; &amp;gt; the general design is as follows:
> &gt; &amp;gt;
> &gt; &amp;gt; local schema = {
> &gt; &amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; type = "object",
> &gt; &amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; properties = {
> &gt; 
> &amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
>  -- specify response delay time,default 0ms
> &gt; 
> &amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
>  delay = { type = "integer" },
> &gt; 
> &amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
>  -- specify response status,default 200
> &gt; 
> &amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
>  response_status = { type = "integer" },
> &gt; 
> &amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
>  -- specify response content type,support application/xml,text/plain and 
> application/json,default application/json
> &gt; 
> &amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
>  content_type = { type = "content_type" },
> &gt; 
> &amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
>  -- specify response body.
> &gt; 
> &amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
>  response_example = {type = "string"},
> &gt; 
> &amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
>  -- specify response json schema,if response_example is not nil,this conf 
> will be ignore.
> &gt; 
> &amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
>  -- generate random response by json schema.
> &gt; 
> &amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
>  response_schema = { type = "object" },
> &gt; &amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; },
> &gt; &amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; anyOf = {
> &gt; 
> &amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
>  {required = {"response_example"}},
> &gt; 
> &amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
>  {required = {"response_schema"}}
> &gt; &amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
> &gt; &amp;gt; }
> &gt; &amp;gt;
> &gt; &amp;gt;
> &gt; &amp;gt; phase 2, goal to implement higher-order ability,such as 
> "expectation and
> &gt; &amp;gt; response patterns".
> &gt; &amp;gt;
> &gt; &amp;gt;
> &gt; &amp;gt;
> &gt; &amp;gt;
> &gt; 
> &gt; -- 
> &gt; Thanks,
> &gt; Janko

Reply via email to