Commit 6b78c0de authored by Mahdi Sellami's avatar Mahdi Sellami

generated server from specification

parent dfd3848a
Pipeline #24147 failed with stages
in 2 minutes and 13 seconds
......@@ -18,3 +18,24 @@ Through a RESTful API as interface, a public service provider module can be easi
![Alt text](figures/sequence_c4ai.png?raw=true "Title")
## 3. How to use
### Overview
This server was generated by the [swagger-codegen](https://github.com/swagger-api/swagger-codegen) project. By using the [OpenAPI-Spec](https://github.com/OAI/OpenAPI-Specification) from a remote server, you can easily generate a server stub.
#### Running the server
To run the server, run:
```
npm start
```
To view the Swagger UI interface:
```
open http://localhost:8080/docs
```
This project leverages the mega-awesome [swagger-tools](https://github.com/apigee-127/swagger-tools) middleware which does most all the work.
This diff is collapsed.
'use strict';
var utils = require('../utils/writer.js');
var Application = require('../service/ApplicationService');
module.exports.postCaseApplication = function postCaseApplication (req, res, next, body) {
Application.postCaseApplication(body)
.then(function (response) {
utils.writeJson(res, response);
})
.catch(function (response) {
utils.writeJson(res, response);
});
};
'use strict';
var utils = require('../utils/writer.js');
var Decision = require('../service/DecisionService');
module.exports.getCaseDecisionDocumentByVerfahrensId = function getCaseDecisionDocumentByVerfahrensId (req, res, next, verfahrensId) {
Decision.getCaseDecisionDocumentByVerfahrensId(verfahrensId)
.then(function (response) {
utils.writeJson(res, response);
})
.catch(function (response) {
utils.writeJson(res, response);
});
};
'use strict';
var utils = require('../utils/writer.js');
var Info = require('../service/InfoService');
module.exports.getAllServices = function getAllServices (req, res, next) {
Info.getAllServices()
.then(function (response) {
utils.writeJson(res, response);
})
.catch(function (response) {
utils.writeJson(res, response);
});
};
module.exports.getServiceByLeiKaId = function getServiceByLeiKaId (req, res, next, leikaId) {
Info.getServiceByLeiKaId(leikaId)
.then(function (response) {
utils.writeJson(res, response);
})
.catch(function (response) {
utils.writeJson(res, response);
});
};
'use strict';
var utils = require('../utils/writer.js');
var Status = require('../service/StatusService');
module.exports.getCaseByVerfahrensId = function getCaseByVerfahrensId (req, res, next, verfahrensId) {
Status.getCaseByVerfahrensId(verfahrensId)
.then(function (response) {
utils.writeJson(res, response);
})
.catch(function (response) {
utils.writeJson(res, response);
});
};
'use strict';
var utils = require('../utils/writer.js');
var Verification = require('../service/VerificationService');
module.exports.getVerificationByVerificationId = function getVerificationByVerificationId (req, res, next, sachverhaltId) {
Verification.getVerificationByVerificationId(sachverhaltId)
.then(function (response) {
utils.writeJson(res, response);
})
.catch(function (response) {
utils.writeJson(res, response);
});
};
module.exports.postVerifcationRequest = function postVerifcationRequest (req, res, next, body) {
Verification.postVerifcationRequest(body)
.then(function (response) {
utils.writeJson(res, response);
})
.catch(function (response) {
utils.writeJson(res, response);
});
};
'use strict';
var path = require('path');
var http = require('http');
var oas3Tools = require('oas3-tools');
var serverPort = 8080;
// swaggerRouter configuration
var options = {
controllers: path.join(__dirname, './controllers')
};
var expressAppConfig = oas3Tools.expressAppConfig(path.join(__dirname, 'api/openapi.yaml'), options);
expressAppConfig.addValidator();
var app = expressAppConfig.getApp();
// Initialize the Swagger middleware
http.createServer(app).listen(serverPort, function () {
console.log('Your server is listening on port %d (http://localhost:%d)', serverPort, serverPort);
console.log('Swagger-ui is available on http://localhost:%d/docs', serverPort);
});
{
"name": "openapis-f-r-e-government",
"version": "0.0.3",
"description": "This is a sample specification of the interfaces based on a project in the city of Munich for the public sector.",
"main": "index.js",
"scripts": {
"prestart": "npm install",
"start": "node index.js"
},
"keywords": [
"swagger"
],
"license": "Unlicense",
"private": true,
"dependencies": {
"connect": "^3.2.0",
"js-yaml": "^3.3.0",
"oas3-tools": "^2.0.2"
}
}
'use strict';
/**
* Submit a new application including the application documents for an administration case
*
* body Verfahren Application details
* returns Verfahren
**/
exports.postCaseApplication = function(body) {
return new Promise(function(resolve, reject) {
var examples = {};
examples['application/json'] = {
"dataObjects" : [ {
"dataObjectId" : "dataObjectId",
"leikaId" : "leikaId",
"verfahrensId" : "verfahrensId",
"title" : "title",
"type" : "type",
"content" : { }
}, {
"dataObjectId" : "dataObjectId",
"leikaId" : "leikaId",
"verfahrensId" : "verfahrensId",
"title" : "title",
"type" : "type",
"content" : { }
} ],
"statusDescription" : "statusDescription",
"statusLastChangeDate" : "2000-01-23T04:56:07.000+00:00",
"statusId" : "statusId",
"leikaId" : "leikaId",
"verfahrensId" : "verfahrensId",
"decisionJustification" : "decisionJustification",
"responsibleAuthority" : "responsibleAuthority",
"decisionDate" : "2000-01-23T04:56:07.000+00:00",
"applicant" : {
"address" : {
"zip" : "zip",
"country" : "country",
"city" : "city",
"street" : "street",
"houseno" : "houseno"
},
"surname" : "surname",
"personId" : "personId",
"prename" : "prename",
"email" : "email"
}
};
if (Object.keys(examples).length > 0) {
resolve(examples[Object.keys(examples)[0]]);
} else {
resolve();
}
});
}
'use strict';
/**
* Request the decision document of an administration case by its case ID
*
* verfahrensId String
* returns DataObject
**/
exports.getCaseDecisionDocumentByVerfahrensId = function(verfahrensId) {
return new Promise(function(resolve, reject) {
var examples = {};
examples['application/json'] = {
"dataObjectId" : "dataObjectId",
"leikaId" : "leikaId",
"verfahrensId" : "verfahrensId",
"title" : "title",
"type" : "type",
"content" : { }
};
if (Object.keys(examples).length > 0) {
resolve(examples[Object.keys(examples)[0]]);
} else {
resolve();
}
});
}
'use strict';
/**
* Find information about the offered services
*
* returns inline_response_200
**/
exports.getAllServices = function() {
return new Promise(function(resolve, reject) {
var examples = {};
examples['application/json'] = {
"services" : [ {
"leikaId" : "leikaId",
"fimMasterData" : { },
"shortText" : "shortText",
"fullText" : "fullText",
"serviceDescription" : "serviceDescription",
"responsibleAuthority" : "responsibleAuthority"
}, {
"leikaId" : "leikaId",
"fimMasterData" : { },
"shortText" : "shortText",
"fullText" : "fullText",
"serviceDescription" : "serviceDescription",
"responsibleAuthority" : "responsibleAuthority"
} ]
};
if (Object.keys(examples).length > 0) {
resolve(examples[Object.keys(examples)[0]]);
} else {
resolve();
}
});
}
/**
* Find information about a specific service by its LeiKa ID
*
* leikaId String Leika ID
* returns Service
**/
exports.getServiceByLeiKaId = function(leikaId) {
return new Promise(function(resolve, reject) {
var examples = {};
examples['application/json'] = {
"leikaId" : "leikaId",
"fimMasterData" : { },
"shortText" : "shortText",
"fullText" : "fullText",
"serviceDescription" : "serviceDescription",
"responsibleAuthority" : "responsibleAuthority"
};
if (Object.keys(examples).length > 0) {
resolve(examples[Object.keys(examples)[0]]);
} else {
resolve();
}
});
}
'use strict';
/**
* Request the current status of an administration case by its case ID
*
* verfahrensId String
* returns Verfahren
**/
exports.getCaseByVerfahrensId = function(verfahrensId) {
return new Promise(function(resolve, reject) {
var examples = {};
examples['application/json'] = {
"dataObjects" : [ {
"dataObjectId" : "dataObjectId",
"leikaId" : "leikaId",
"verfahrensId" : "verfahrensId",
"title" : "title",
"type" : "type",
"content" : { }
}, {
"dataObjectId" : "dataObjectId",
"leikaId" : "leikaId",
"verfahrensId" : "verfahrensId",
"title" : "title",
"type" : "type",
"content" : { }
} ],
"statusDescription" : "statusDescription",
"statusLastChangeDate" : "2000-01-23T04:56:07.000+00:00",
"statusId" : "statusId",
"leikaId" : "leikaId",
"verfahrensId" : "verfahrensId",
"decisionJustification" : "decisionJustification",
"responsibleAuthority" : "responsibleAuthority",
"decisionDate" : "2000-01-23T04:56:07.000+00:00",
"applicant" : {
"address" : {
"zip" : "zip",
"country" : "country",
"city" : "city",
"street" : "street",
"houseno" : "houseno"
},
"surname" : "surname",
"personId" : "personId",
"prename" : "prename",
"email" : "email"
}
};
if (Object.keys(examples).length > 0) {
resolve(examples[Object.keys(examples)[0]]);
} else {
resolve();
}
});
}
'use strict';
/**
* Request the status and outcome of a verification request by its verification ID
*
* sachverhaltId String
* returns Verification
**/
exports.getVerificationByVerificationId = function(sachverhaltId) {
return new Promise(function(resolve, reject) {
var examples = {};
examples['application/json'] = {
"sachverhaltId" : "sachverhaltId",
"statusDescription" : "statusDescription",
"statusLastChangeDate" : "2000-01-23T04:56:07.000+00:00",
"statusId" : "statusId",
"verificationType" : "verificationType",
"verificationDataObject" : {
"dataObjectId" : "dataObjectId",
"leikaId" : "leikaId",
"verfahrensId" : "verfahrensId",
"title" : "title",
"type" : "type",
"content" : { }
},
"approverPerson" : {
"address" : {
"zip" : "zip",
"country" : "country",
"city" : "city",
"street" : "street",
"houseno" : "houseno"
},
"surname" : "surname",
"personId" : "personId",
"prename" : "prename",
"email" : "email"
}
};
if (Object.keys(examples).length > 0) {
resolve(examples[Object.keys(examples)[0]]);
} else {
resolve();
}
});
}
/**
* Submit a new verification request, e.g. to verify a decision document or a person
*
* body Body Decision details (optional)
* returns Verification
**/
exports.postVerifcationRequest = function(body) {
return new Promise(function(resolve, reject) {
var examples = {};
examples['application/json'] = {
"sachverhaltId" : "sachverhaltId",
"statusDescription" : "statusDescription",
"statusLastChangeDate" : "2000-01-23T04:56:07.000+00:00",
"statusId" : "statusId",
"verificationType" : "verificationType",
"verificationDataObject" : {
"dataObjectId" : "dataObjectId",
"leikaId" : "leikaId",
"verfahrensId" : "verfahrensId",
"title" : "title",
"type" : "type",
"content" : { }
},
"approverPerson" : {
"address" : {
"zip" : "zip",
"country" : "country",
"city" : "city",
"street" : "street",
"houseno" : "houseno"
},
"surname" : "surname",
"personId" : "personId",
"prename" : "prename",
"email" : "email"
}
};
if (Object.keys(examples).length > 0) {
resolve(examples[Object.keys(examples)[0]]);
} else {
resolve();
}
});
}
var ResponsePayload = function(code, payload) {
this.code = code;
this.payload = payload;
}
exports.respondWithCode = function(code, payload) {
return new ResponsePayload(code, payload);
}
var writeJson = exports.writeJson = function(response, arg1, arg2) {
var code;
var payload;
if(arg1 && arg1 instanceof ResponsePayload) {
writeJson(response, arg1.payload, arg1.code);
return;
}
if(arg2 && Number.isInteger(arg2)) {
code = arg2;
}
else {
if(arg1 && Number.isInteger(arg1)) {
code = arg1;
}
}
if(code && arg1) {
payload = arg1;
}
else if(arg1) {
payload = arg1;
}
if(!code) {
// if no response code given, we default to 200
code = 200;
}
if(typeof payload === 'object') {
payload = JSON.stringify(payload, null, 2);
}
response.writeHead(code, {'Content-Type': 'application/json'});
response.end(payload);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment