diff --git a/examples/relay/main.cpp b/examples/relay/main.cpp index 9f810f7..25fa5d9 100644 --- a/examples/relay/main.cpp +++ b/examples/relay/main.cpp @@ -59,7 +59,7 @@ public: String json; serializeJson(resp, json); request->send(ok ? 200 : 400, "application/json", json); - }, std::vector{ ApiServer::ParamSpec{ String("state"), true, String("body"), String("string") } }); + }, std::vector{ ApiServer::ParamSpec{ String("state"), true, String("body"), String("string"), { String("on"), String("off"), String("toggle") } } }); } void turnOn() { diff --git a/include/ApiServer.h b/include/ApiServer.h index 0366cf8..7bf88ae 100644 --- a/include/ApiServer.h +++ b/include/ApiServer.h @@ -28,6 +28,7 @@ public: bool required; String location; // "query" | "body" | "path" | "header" String type; // e.g. "string", "number", "boolean" + std::vector values; // optional allowed values }; struct EndpointCapability { String uri; diff --git a/src/ApiServer.cpp b/src/ApiServer.cpp index 1c52cb3..e7059f8 100644 --- a/src/ApiServer.cpp +++ b/src/ApiServer.cpp @@ -77,8 +77,8 @@ void ApiServer::begin() { addEndpoint("/api/tasks/control", HTTP_POST, std::bind(&ApiServer::onTaskControlRequest, this, std::placeholders::_1), std::vector{ - ParamSpec{String("task"), true, String("body"), String("string")}, - ParamSpec{String("action"), true, String("body"), String("string")} + ParamSpec{String("task"), true, String("body"), String("string"), {}}, + ParamSpec{String("action"), true, String("body"), String("string"), {String("enable"), String("disable"), String("start"), String("stop"), String("status")}} } ); @@ -370,6 +370,12 @@ void ApiServer::onCapabilitiesRequest(AsyncWebServerRequest *request) { p["location"] = ps.location; p["required"] = ps.required; p["type"] = ps.type; + if (!ps.values.empty()) { + JsonArray allowed = p["values"].to(); + for (const auto& v : ps.values) { + allowed.add(v); + } + } } } }