diff --git a/README.md b/README.md index 173a178..b376e80 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,10 @@ # OpenWiFi Provisioning +## Build from source. +You need: https://github.com/pboettch/json-schema-validator.git +You need: https://github.com/nlohmann/json.git +build and install them. + ## Root entity It's UUID value is 0000-0000-0000. Its parent entity must be empty. diff --git a/build b/build index 34bba94..147ea53 100644 --- a/build +++ b/build @@ -1 +1 @@ -156 \ No newline at end of file +158 \ No newline at end of file diff --git a/openapi/ow_prov.yaml b/openapi/ow_prov.yaml index ad65399..1181b19 100644 --- a/openapi/ow_prov.yaml +++ b/openapi/ow_prov.yaml @@ -1934,6 +1934,11 @@ paths: format: uuid example: When creating the root entity, the uuid 0000-0000-0000 must be entered. When creating a non-root entity, uuid must be 1 required: true + - in: query + name: validateOnly + schema: + type: boolean + required: false requestBody: description: Information used to create the new entity content: diff --git a/src/ConfigurationValidator.h b/src/ConfigurationValidator.h index b3ce1da..2fed429 100644 --- a/src/ConfigurationValidator.h +++ b/src/ConfigurationValidator.h @@ -56,7 +56,7 @@ namespace OpenWifi { std::unique_ptr Validator_; }; - bool ValidateUCentralConfiguration(const std::string &C) { return ConfigurationValidator::instance()->Validate(C); } + inline bool ValidateUCentralConfiguration(const std::string &C) { return ConfigurationValidator::instance()->Validate(C); } } #endif //OWPROV_CONFIGURATIONVALIDATOR_H diff --git a/src/RESTAPI_configurations_handler.cpp b/src/RESTAPI_configurations_handler.cpp index f5580fc..5666919 100644 --- a/src/RESTAPI_configurations_handler.cpp +++ b/src/RESTAPI_configurations_handler.cpp @@ -12,6 +12,8 @@ #include "Daemon.h" #include "RESTAPI_errors.h" +#include "ConfigurationValidator.h" + namespace OpenWifi{ void RESTAPI_configurations_handler::DoGet() { @@ -103,6 +105,21 @@ namespace OpenWifi{ return; } + std::string Arg; + if(HasParameter("validateOnly",Arg) && Arg=="true") { + auto Body = ParseStream(); + if(!Body->has("configuration")) { + BadRequest("Must have 'configuration' element."); + return; + } + auto Config=Body->get("configuration").toString(); + Poco::JSON::Object Answer; + auto Res = ValidateUCentralConfiguration(Config); + Answer.set("valid",Res); + ReturnObject(Answer); + return; + } + ProvObjects::DeviceConfiguration C; Poco::JSON::Object::Ptr Obj = ParseStream(); if (!C.from_json(Obj)) {