FSN#40005 Documenteren API2 volgens OpenAPI Specification: betere HTTP error codes

svn path=/Website/trunk/; revision=33407
This commit is contained in:
Jos Groot Lipman
2017-04-04 14:16:23 +00:00
parent b16684eecb
commit 0880dccc95
2 changed files with 15 additions and 16 deletions

View File

@@ -219,20 +219,20 @@ api2_rest = {
{
var parsed = RequestJSON();
if (parsed.error)
api2.error(500, "Error parsing input JSON: " + parsed.error);
api2.error(400, "Error parsing input JSON: " + parsed.error);
jsondata = api2_rest.plugin.transform_incoming(requestparams, parsed.json);
if (!jsondata)
api2.error(500, "Error parsing input JSON: Empty");
api2.error(400, "Error parsing input JSON: Empty");
break;
}
case "xml":
{
var parsed = RequestXML();
if (parsed.error)
api2.error(500, "Error parsing input XML: " + parsed.error);
api2.error(400, "Error parsing input XML: " + parsed.error);
jsondata = api2_rest.xml2json(parsed.xml);
if (!jsondata)
api2.error(500, "Error parsing input XML: Empty");
api2.error(400, "Error parsing input XML: Empty");
break;
}
//case "form":
@@ -245,7 +245,7 @@ api2_rest = {
}
if (!jsondata || !(model.record_name in jsondata || (model.multi_update && model.records_name in jsondata)))
{
api2.error(500, "No '{0}' found in input".format(model.record_name));
api2.error(400, "No '{0}' found in input".format(model.record_name));
}
}
}
@@ -369,7 +369,8 @@ api2_rest = {
else if (model.record_name in jsondata) // een enkel record
{
if (jsondata[model.record_name] instanceof Array)
abort_with_warning("API2 error: {0} should be single record only.".format(method));
api2.error(400, "{0} should be single record only.".format(method))
var result = model["REST_" + method]( requestparams, jsondata[model.record_name], key );
}
else
@@ -882,8 +883,9 @@ function RequestJSON()
}
catch (e)
{
__DoLog("JSON eval faalt met: '{0}'\n{1}".format(e.description||e.message, jvraag), "ffff00");
return { error: e.description };
result = { error: e.description || (e.message + ": " + e.name) };
__DoLog("JSON eval faalt met: '{0}'\n{1}".format(result, jvraag), "ffff00");
return result ;
}
return { json: vraag };
}

View File

@@ -257,8 +257,8 @@
"$ref": "#/schema/" + model.record_name
}
},
"405":{
"description":"Invalid input"
"400":{
"description":"Bad request"
},
"403": {
"description": "Forbidden"
@@ -312,8 +312,8 @@
"403": {
"description": "Forbidden"
},
"405":{
"description":"Invalid input"
"400":{
"description":"Bad request"
}
},
"security":[
@@ -344,13 +344,10 @@
],
"responses":{
"204":{
"description":"No content"
"description":"No content (delete succesfull or record not found)"
},
"403": {
"description": "Forbidden"
},
"405":{
"description":"Invalid input"
}
},
"security":[