We are using dev portal - smart docs to import swagger doc(.yaml). We are facing issue with optional body params getting included with in the POST request.
Back-end code doesn't expect optional empty value getting inserted.
Eg:
grant_type=client_credentials&scope=accounts Vs grant_type=client_credentials&client_secret=&client_name=&scope=accounts&code=&redirect_uri=&refresh_token="
Apigee dev portal Curl: curl -X POST --header "Authorization: Basic <<>>>==" --header "Content-Type: application/x-www-form-urlencoded" -d "grant_type=client_credentials&client_secret=&client_name=&scope=accounts&code=&redirect_uri=&refresh_token=" "https://apigee.test.com/v1/api/oauth/token"
Swagger UI curl:
curl -X POST "https://xxxx/v1/token" -H "accept: application/json; charset=utf-8" -H "Authorization: Basic xxxxx" -H "Content-Type: application/x-www-form-urlencoded;" -d "grant_type=client_credentials&scope=accounts"
I think its expected behavior. In v6 model.js there is:
bodyPayload = jQuery("#formParams").serialize(); ... if (bodyPayload && bodyPayload.replace) { results.push('-d "' + bodyPayload.replace(/"/g, '\\"') + '"'); }which just escapes double quotes, theres no attempt to parse/handle body parameters.
I think your best option is to handle the empty parameters in the API Proxy directly, or cuztomizing your model.js file to filter out empty body parameters before sending a request.
Was able to do it using JS & can be used in smartdocs proxy before it hit hits backend api..
var count = context.getVariable('request.formparams.count'); var formString = context.getVariable('request.content'); var formParamsArray = formString.split("&"); for (var i = 0; i < count; i++) { var formParamArray = formParamsArray[i].split("="); print(formParamArray[0] + "---" + typeof(formParamArray[0])+ "---" + formParamArray[1]+ "---" + typeof(formParamArray[1])); if (formParamArray[1] === "") { context.removeVariable("request.formparam." + formParamArray[0]); } }
HTH to others..
-Vinay
User | Count |
---|---|
2 | |
1 | |
1 | |
1 | |
1 |