API2: voortaan ook api2/buildings ondersteunen zonder .json/.xml aanduiding. Dan autodetext op httt-accept header
(en ook api2_swagger.inc afgesplitst) svn path=/Website/trunk/; revision=33292
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
*/
|
||||
%>
|
||||
<!-- #include file="api2.inc" -->
|
||||
<!-- #include file="api2_swagger.inc" -->
|
||||
<!-- #include file="../scf/scaffolding_common.inc" -->
|
||||
<%
|
||||
var DEZE = this;
|
||||
@@ -137,87 +138,24 @@ api2_rest = {
|
||||
Response.End;
|
||||
}
|
||||
},
|
||||
swaggerschema: function _swaggerschema(model)
|
||||
{
|
||||
var schema = {
|
||||
"type":"object",
|
||||
"properties":{},
|
||||
"required": [],
|
||||
"xml":{
|
||||
"name": model.record_name
|
||||
}
|
||||
}
|
||||
for (var fld in model.fields)
|
||||
{
|
||||
if (fld.substring(0,1) == "_")
|
||||
continue;
|
||||
var field = model.fields[fld];
|
||||
if (field.hidden)
|
||||
continue;
|
||||
if (field.required)
|
||||
schema.required.push(fld);
|
||||
switch (field.typ)
|
||||
{
|
||||
case "key":
|
||||
var prop = {
|
||||
"type":"integer",
|
||||
"format":"int64"
|
||||
};
|
||||
break;
|
||||
case "float":
|
||||
case "currency":
|
||||
var prop = {
|
||||
"type":"float",
|
||||
"format":"float"
|
||||
};
|
||||
break;
|
||||
case "number":
|
||||
var prop = {
|
||||
"type":"integer",
|
||||
"format":"int64"
|
||||
};
|
||||
break;
|
||||
case "check":
|
||||
case "check0":
|
||||
var prop = {
|
||||
"type":"integer",
|
||||
"format":"int64"
|
||||
};
|
||||
break;
|
||||
case "varchar":
|
||||
case "memo":
|
||||
var prop = {
|
||||
"type":"string",
|
||||
"format":"string"
|
||||
};
|
||||
break;
|
||||
case "date":
|
||||
var prop = {
|
||||
"type":"dateTime",
|
||||
"format":"date-time"
|
||||
};
|
||||
break;
|
||||
case "datetime":
|
||||
var prop = {
|
||||
"type":"dateTime",
|
||||
"format":"date-time"
|
||||
};
|
||||
break;
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
prop.description = field.label;
|
||||
schema["properties"][fld] = prop;
|
||||
}
|
||||
return schema;
|
||||
},
|
||||
process: function _process(model)
|
||||
{
|
||||
var wasCodePage = Session.Codepage;
|
||||
Session.Codepage = 65001; // We doen *uitsluitend* utf-8
|
||||
Response.Charset = 'utf-8';
|
||||
var format = getQParamSafe("format", "invalid").toLowerCase();
|
||||
if (format == "auto")
|
||||
{
|
||||
var accept = String(Request.ServerVariables("HTTP_ACCEPT")).split(",")[0]; // Altijd alleen eerste bekijken
|
||||
switch (accept.toLowerCase())
|
||||
{
|
||||
case "application/xml": format = "xml"; break;
|
||||
case "application/json": format = "json"; break;
|
||||
case "text/html": format = "html"; break; // vanuit browser?
|
||||
default: format = "json";
|
||||
}
|
||||
}
|
||||
|
||||
if (format == "json")
|
||||
/* global */ JSON_Result = true; // Zelf doen we er niets mee maar
|
||||
// shared.simple_page kijkt er naar
|
||||
@@ -334,155 +272,7 @@ api2_rest = {
|
||||
}
|
||||
else if (format == "api" && getQParamInt("swagger", 0) == 1)
|
||||
{
|
||||
// Swagger
|
||||
var result = {
|
||||
"get": {
|
||||
"tags":[
|
||||
getQParamSafe("module", "XXX")
|
||||
],
|
||||
"summary": "Get all {0}".format(model.records_title),
|
||||
"description": "Returns all {0} from the system that the user has access to".format(model.records_title),
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "A list of " + model.records_title
|
||||
}
|
||||
},
|
||||
"security":[
|
||||
{
|
||||
"api_key":[
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
if (getQParamInt("single", 0) == 1)
|
||||
{
|
||||
result["get"].summary = "Get one {0}".format(model.record_title);
|
||||
result["get"].parameters = [
|
||||
{
|
||||
"name":"id",
|
||||
"in":"path",
|
||||
"description":"ID of {0} to return".format(model.record_title),
|
||||
"required":true,
|
||||
"type":"integer",
|
||||
"format":"int64"
|
||||
}
|
||||
];
|
||||
}
|
||||
if (getQParamInt("single", 0) == 1 && model["REST_POST"])
|
||||
{
|
||||
result["post"] = {
|
||||
"tags":[
|
||||
getQParamSafe("module", "XXX")
|
||||
],
|
||||
"summary":"Add a new {0} to FACILITOR".format(model.record_title),
|
||||
"description":"",
|
||||
"operationId":"add" + model.records_name,
|
||||
"parameters":[
|
||||
{
|
||||
"in":"body",
|
||||
"name":"body",
|
||||
"description":"{0} object that needs to be added".format(model.record_title),
|
||||
"required":true,
|
||||
"xxxschema":{
|
||||
"$ref":"#/definitions/Pet"
|
||||
},
|
||||
"schema": api2_rest.swaggerschema(model)
|
||||
}
|
||||
],
|
||||
"responses":{
|
||||
"405":{
|
||||
"description":"Invalid input"
|
||||
}
|
||||
},
|
||||
"security":[
|
||||
{
|
||||
"petstore_auth":[
|
||||
"write:pets",
|
||||
"read:pets"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
if (getQParamInt("single", 0) == 1 && model["REST_PUT"])
|
||||
{
|
||||
result["put"] = {
|
||||
"tags":[
|
||||
getQParamSafe("module", "XXX")
|
||||
],
|
||||
"summary":"Update an existing {0} in FACILITOR".format(model.record_title),
|
||||
"description":"",
|
||||
"operationId":"add" + model.records_name,
|
||||
"parameters":[
|
||||
{
|
||||
"name":"id",
|
||||
"in":"path",
|
||||
"description":"ID of {0} to update".format(model.record_title),
|
||||
"required":true,
|
||||
"type":"integer",
|
||||
"format":"int64"
|
||||
},
|
||||
{
|
||||
"in":"body",
|
||||
"name":"body",
|
||||
"description":"{0} object that needs to be updated".format(model.record_title),
|
||||
"required":true,
|
||||
"xxxschema":{
|
||||
"$ref":"#/definitions/Pet"
|
||||
},
|
||||
"schema": api2_rest.swaggerschema(model)
|
||||
}
|
||||
],
|
||||
"responses":{
|
||||
"405":{
|
||||
"description":"Invalid input"
|
||||
}
|
||||
},
|
||||
"security":[
|
||||
{
|
||||
"petstore_auth":[
|
||||
"write:pets",
|
||||
"read:pets"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
if (getQParamInt("single", 0) == 1 && model["REST_DELETE"])
|
||||
{
|
||||
result["delete"] = {
|
||||
"tags":[
|
||||
getQParamSafe("module", "XXX")
|
||||
],
|
||||
"summary":"Delete a {0} from FACILITOR".format(model.record_title),
|
||||
"description":"",
|
||||
"operationId":"add" + model.records_name,
|
||||
"parameters":[
|
||||
{
|
||||
"name":"id",
|
||||
"in":"path",
|
||||
"description":"ID of {0} to delete".format(model.record_title),
|
||||
"required":true,
|
||||
"type":"integer",
|
||||
"format":"int64"
|
||||
}
|
||||
],
|
||||
"responses":{
|
||||
"405":{
|
||||
"description":"Invalid input"
|
||||
}
|
||||
},
|
||||
"security":[
|
||||
{
|
||||
"petstore_auth":[
|
||||
"write:pets",
|
||||
"read:pets"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
result = swaggermodel(model);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user