* \brief Parse `{"step": N}` from a slice-PUT body. * * \param body Pre-parsed JSON body. * \param resourceContext Resource label embedded into the rejection when * `position` is present (e.g. "StdMulti * selected-slice", "MxN selected-slice"). Identifies * which slice resource produced the error.
| 944 | * \returns nullopt on success; an error fragment otherwise. |
| 945 | */ |
| 946 | std::optional<std::string> ParseSliceStepBody(const nlohmann::json& body, |
| 947 | std::string_view resourceContext, |
| 948 | const std::string& positionHint, |
| 949 | unsigned int& step) |
| 950 | { |
| 951 | if (!body.is_object()) |
| 952 | return "Request body must be a JSON object."; |
| 953 | |
| 954 | if (body.contains("position")) |
| 955 | return std::string("'position' is not accepted on ") + std::string(resourceContext) |
| 956 | + ". " + positionHint; |
| 957 | |
| 958 | for (auto it = body.begin(); it != body.end(); ++it) |
| 959 | { |
| 960 | if (it.key() != "step") |
| 961 | return "Unknown field '" + it.key() + "'."; |
| 962 | } |
| 963 | |
| 964 | if (!body.contains("step")) |
| 965 | return "'step' field is required."; |
| 966 | |
| 967 | const auto& s = body["step"]; |
| 968 | if (!s.is_number_integer()) |
| 969 | return "'step' must be a non-negative integer."; |
| 970 | |
| 971 | const auto raw = s.get<long long>(); |
| 972 | if (raw < 0) |
| 973 | return "'step' must be a non-negative integer."; |
| 974 | |
| 975 | step = static_cast<unsigned int>(raw); |
| 976 | return std::nullopt; |
| 977 | } |
| 978 | |
| 979 | nlohmann::json CameraStateToJson(const mitk::CameraState& s) |
| 980 | { |
no test coverage detected