FSN#40005 Documenteren API2 volgens OpenAPI Specification savepoint
Enkele 'lastige' modellen nog uitgeschakeld in dispatch met nodoc: true svn path=/Website/trunk/; revision=33293
This commit is contained in:
303
APPL/API2/api2_swagger.inc
Normal file
303
APPL/API2/api2_swagger.inc
Normal file
@@ -0,0 +1,303 @@
|
||||
<% /*
|
||||
$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"
|
||||
};
|
||||
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":"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;
|
||||
};
|
||||
|
||||
function swaggermodel (model)
|
||||
{
|
||||
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/" + model.records_name
|
||||
}
|
||||
}
|
||||
},
|
||||
"security":[
|
||||
{
|
||||
"api_key":[
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
result["schema"]["fields"][model.record_name] = swaggerschema(model);
|
||||
result["schema"][model.records_name] =
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"total_count": {
|
||||
"type":"integer",
|
||||
"format":"int64",
|
||||
"example": 10
|
||||
},
|
||||
"limit": {
|
||||
"type":"integer",
|
||||
"format":"int64",
|
||||
"example": S("qp_maxrows")
|
||||
},
|
||||
"offset": {
|
||||
"type":"integer",
|
||||
"format":"int64",
|
||||
"example": 0 // Doen we altijd nog
|
||||
}
|
||||
}
|
||||
}
|
||||
result["schema"][model.records_name]["properties"][model.records_name] =
|
||||
{
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/schema/fields/" + model.record_name
|
||||
}
|
||||
};
|
||||
|
||||
result["schema"][model.record_name] = {
|
||||
"type": "object",
|
||||
"properties": {}
|
||||
};
|
||||
result["schema"][model.record_name ]["properties"][model.record_name] =
|
||||
{
|
||||
"$ref": "#/schema/fields/" + model.record_name
|
||||
}
|
||||
|
||||
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 = [
|
||||
{
|
||||
"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) == 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"
|
||||
},
|
||||
"xschema": swaggerschema(model),
|
||||
"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;
|
||||
}
|
||||
|
||||
%>
|
||||
Reference in New Issue
Block a user