diff options
author | neodarz <neodarz@neodarz.net> | 2019-09-11 16:22:33 +0200 |
---|---|---|
committer | neodarz <neodarz@neodarz.net> | 2019-09-11 16:22:33 +0200 |
commit | a826aeae4b7f9a1e3b0e0d9622fe2a2f94f1d641 (patch) | |
tree | 927ccd582b765dd1d3ed720d926b920d774c8114 /api | |
parent | 1ae302dae3df2cb48c99ebdf407e490dca97d5fd (diff) | |
download | umosapicpp-a826aeae4b7f9a1e3b0e0d9622fe2a2f94f1d641.tar.xz umosapicpp-a826aeae4b7f9a1e3b0e0d9622fe2a2f94f1d641.zip |
Add ability to have an object in response
Diffstat (limited to '')
-rw-r--r-- | api/umosapi.cpp | 13 | ||||
-rw-r--r-- | api/umosapi.h | 2 |
2 files changed, 10 insertions, 5 deletions
diff --git a/api/umosapi.cpp b/api/umosapi.cpp index f5d7003..c14e9a5 100644 --- a/api/umosapi.cpp +++ b/api/umosapi.cpp @@ -210,11 +210,16 @@ void UmosapiService::Api::parameter(std::string name, std::string description, s UmosapiService::Api::_swagger["paths"][UmosapiService::Api::_path.name][UmosapiService::Api::_path.words.back().name]["parameters"].push_back(parameter); } -void UmosapiService::Api::response(std::string http_code, std::string description, std::string definition) { +void UmosapiService::Api::response(std::string http_code, std::string description, std::string definition, std::string type = "object") { std::string schema = "#/definitions/"; - UmosapiService::Api::_swagger["paths"][UmosapiService::Api::_path.name][UmosapiService::Api::_path.words.back().name]["responses"][http_code]["description"] = description; - UmosapiService::Api::_swagger["paths"][UmosapiService::Api::_path.name][UmosapiService::Api::_path.words.back().name]["responses"][http_code]["schema"]["items"]["$ref"] = schema.append(definition); - UmosapiService::Api::_swagger["paths"][UmosapiService::Api::_path.name][UmosapiService::Api::_path.words.back().name]["responses"][http_code]["schema"]["type"] = "array"; + if (type == "object") { + UmosapiService::Api::_swagger["paths"][UmosapiService::Api::_path.name][UmosapiService::Api::_path.words.back().name]["responses"][http_code]["description"] = description; + UmosapiService::Api::_swagger["paths"][UmosapiService::Api::_path.name][UmosapiService::Api::_path.words.back().name]["responses"][http_code]["schema"]["$ref"] = schema.append(definition); + } else { + UmosapiService::Api::_swagger["paths"][UmosapiService::Api::_path.name][UmosapiService::Api::_path.words.back().name]["responses"][http_code]["description"] = description; + UmosapiService::Api::_swagger["paths"][UmosapiService::Api::_path.name][UmosapiService::Api::_path.words.back().name]["responses"][http_code]["schema"]["items"]["$ref"] = schema.append(definition); + UmosapiService::Api::_swagger["paths"][UmosapiService::Api::_path.name][UmosapiService::Api::_path.words.back().name]["responses"][http_code]["schema"]["type"] = type; + } } void UmosapiService::Api::swagger(std::string ui_path, std::string swagger_dir, std::string api_path) { diff --git a/api/umosapi.h b/api/umosapi.h index a066ac9..fbdc755 100644 --- a/api/umosapi.h +++ b/api/umosapi.h @@ -81,7 +81,7 @@ class Api { void produce(std::string); void consume(std::string); void parameter(std::string, std::string, std::string); - void response(std::string err_code, std::string description, std::string schema); + void response(std::string err_code, std::string description, std::string schema, std::string type); void publish(); void basePath(std::string basePath); void description(std::string description); |