wso2 / docs-apim

Apache License 2.0
70 stars 392 forks source link

[Docs] Replace UI screenshots in Prototype Implementation Page #3534

Open npamudika opened 3 years ago

npamudika commented 3 years ago

Describe your problem(s)

The screenshots in "Creating a Prototype API with Mock Payload Generated Inline Scripts" doc page are outdated and should be replaced with the screenshots taken from the new UIs.

Doc link - https://apim.docs.wso2.com/en/4.0.0-dev/design/prototype-api/create-a-mock-api-with-an-inline-script/

npamudika commented 3 years ago

The inline scripts provided in the doc are also outdated. We need to update them too.

The instructions to modify the inline scripts are not clear enough (not clear what part to replace) in 6 and 7 points in Step 1. Need to reword them by clearly mentioning which parts to be replaced and which parts to be kept. It's good to provide a complete example with the full script without editing and after manually editing.

For the auto-generated example of pet/{petId}, need to provide sth like this in point 6 after the screenshot.

var accept = mc.getProperty('AcceptHeader');
var responseCode = mc.getProperty('query.param.responseCode');
var responseCodeSC;
var responses = [];

if (!responses[200]) {
 responses [200] = [];
}
responses[200]["application/json"] = "";

responses[200]["application/xml"] = <pet><id>10</id><name>doggie</name><category><id>1</id><name>Dogs</name></category><photoUrlss><photoUrl>string</photoUrl></photoUrlss><tagss><tag><id>0</id><name>string</name></tag></tagss><status>available</status></pet>;
if (!responses[400]) {
  responses[400] = [];
}
responses[400]["application/json"] = "";
responses[400]["application/xml"] = "";

if (!responses[404]) {
  responses[404] = [];
}
responses[404]["application/json"] = "";
responses[404]["application/xml"] = "";

responses[501] = [];
responses[501]["application/json"] = {
"code" : 501,
"description" : "Not Implemented"}
responses[501]["application/xml"] = <response><code>501</code><description>Not Implemented</description></response>;

if (responseCode == null) {
 responseCode = 200;
}

if (!responses[responseCode]) {
  if (responses["default"]) {
    responseCode = "default"
  } else {
    responseCode = 501;
  }
}
if (responseCode === "default") {
  responseCodeSC = mc.getProperty('query.param.responseCode');
} else {
  responseCodeSC = responseCode;
}
if (accept == null || !responses[responseCode][accept]) {
 accept = "application/json";
}

if (accept == "application/json") {
 mc.setProperty('CONTENT_TYPE', 'application/json');
 mc.setProperty('HTTP_SC', responseCodeSC + "");
 mc.setPayloadJSON(responses[responseCode]["application/json"]);
} else if (accept == "application/xml") {
 mc.setProperty('CONTENT_TYPE', 'application/xml');
 mc.setProperty('HTTP_SC', responseCodeSC + "");
 mc.setPayloadXML(responses[responseCode]["application/xml"]);
}

Then in point 7, we should explain which part of the above auto generated script can be replaced and which parts to be kept. And provide an example for a complete script after modifying.

https://apim.docs.wso2.com/en/4.0.0-dev/design/prototype-api/create-a-mock-api-with-an-inline-script/#step-1-create-a-prototype-api-with-mock-response-payloads