345 lines
12 KiB
PHP
345 lines
12 KiB
PHP
<% /*
|
|
$Revision$
|
|
$Id$
|
|
|
|
File: api2_swagger.inc
|
|
Description: Genereer OpenAPI compatible documentatie
|
|
zodat swagger ui die kan lezen
|
|
Notes:
|
|
Status:
|
|
|
|
*/
|
|
%>
|
|
<%
|
|
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"
|
|
};
|
|
if (fld == "id")
|
|
prop["readOnly"] = true; // Wordt nog genegeerd door Swagger-ui 2.0
|
|
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",
|
|
"enum":[0, 1]
|
|
};
|
|
break;
|
|
case "varchar":
|
|
case "memo":
|
|
var prop = {
|
|
"type":"string",
|
|
"format":"string"
|
|
};
|
|
break;
|
|
case "date":
|
|
var prop = {
|
|
"type":"date",
|
|
"format":"date"
|
|
};
|
|
break;
|
|
case "datetime":
|
|
var prop = {
|
|
"type":"dateTime",
|
|
"format":"date-time"
|
|
};
|
|
break;
|
|
break;
|
|
default:
|
|
continue;
|
|
}
|
|
prop.description = field.label;
|
|
//prop["default"] = field.defaultvalue;
|
|
if ("LOV" in field)
|
|
{
|
|
var spl = api2.splitLOV(field.LOV);
|
|
var enums = [];
|
|
for (var l in spl)
|
|
{
|
|
enums.push(l);
|
|
}
|
|
prop["enum"] = enums;
|
|
}
|
|
schema["properties"][fld] = prop;
|
|
}
|
|
return schema;
|
|
};
|
|
|
|
function swaggermodel (model)
|
|
{
|
|
model.records_title = model.records_title || model.records_name;
|
|
model.record_title = model.record_title || model.record_name;
|
|
var result = {
|
|
"schema": { "fields": {} },
|
|
"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,
|
|
"schema": {
|
|
"$ref": "#/schema/{0}".format(model.records_name)
|
|
}
|
|
}
|
|
},
|
|
"security":[
|
|
{
|
|
"api_key":[
|
|
]
|
|
}
|
|
],
|
|
"parameters": []
|
|
}
|
|
};
|
|
|
|
if (model.includes)
|
|
{
|
|
var enums = [];
|
|
for (var i in model.includes)
|
|
enums.push(i);
|
|
var inc = model.includes[i];
|
|
result["get"].parameters.push(
|
|
{
|
|
"name": "include",
|
|
"in": "query",
|
|
"description": "Include all {0}".format("model" in inc?inc.model.records_title:i),
|
|
"required": false,
|
|
"type": "array",
|
|
"enum": enums
|
|
});
|
|
};
|
|
|
|
result["schema"]["fields"][model.record_name + "fields"] = swaggerschema(model);
|
|
result["schema"][model.records_name] =
|
|
{
|
|
"type": "object",
|
|
"properties": {
|
|
"total_count": {
|
|
"type":"integer",
|
|
"format":"int64",
|
|
"example": 10,
|
|
"xml": {
|
|
"attribute": true
|
|
}
|
|
},
|
|
"limit": {
|
|
"type":"integer",
|
|
"format":"int64",
|
|
"example": S("qp_maxrows"),
|
|
"xml": {
|
|
"attribute": true
|
|
}
|
|
},
|
|
"offset": {
|
|
"type":"integer",
|
|
"format":"int64",
|
|
"example": 0, // Doen we altijd nog
|
|
"xml": {
|
|
"attribute": true
|
|
}
|
|
}
|
|
}
|
|
}
|
|
result["schema"][model.records_name]["properties"][model.records_name] =
|
|
{
|
|
"type": "array",
|
|
"items": {
|
|
"$ref": "#/schema/fields/" + model.record_name + "fields"
|
|
}
|
|
};
|
|
|
|
result["schema"][model.record_name] = {
|
|
"type": "object",
|
|
"properties": {}
|
|
};
|
|
result["schema"][model.record_name ]["properties"][model.record_name] =
|
|
{
|
|
"$ref": "#/schema/fields/" + model.record_name + "fields"
|
|
}
|
|
|
|
if (getQParamInt("single", 0) == 1)
|
|
{
|
|
result["get"].summary = "Get one {0}".format(model.record_title);
|
|
result["get"].description = "Returns the {0}".format(model.record_title),
|
|
|
|
result["get"].parameters.push(
|
|
{
|
|
"name":"id",
|
|
"in":"path",
|
|
"description":"ID of {0} to return".format(model.record_title),
|
|
"required":true,
|
|
"type":"integer",
|
|
"format":"int64"
|
|
}
|
|
);
|
|
result["get"]["responses"] =
|
|
{
|
|
"200": {
|
|
"description": "A " + model.record_title,
|
|
"schema": {
|
|
"$ref": "#/schema/" + model.record_name
|
|
}
|
|
}
|
|
};
|
|
}
|
|
if (getQParamInt("single", 0) == 0 && 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": {
|
|
"$ref": "#/schema/" + model.record_name
|
|
}
|
|
}
|
|
],
|
|
"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": {
|
|
"$ref": "#/schema/" + model.record_name
|
|
}
|
|
}
|
|
],
|
|
"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"
|
|
]
|
|
}
|
|
]
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
%> |