summaryrefslogtreecommitdiffstats
path: root/redfish-core/include
diff options
context:
space:
mode:
Diffstat (limited to 'redfish-core/include')
-rw-r--r--redfish-core/include/error_messages.hpp297
-rw-r--r--redfish-core/include/node.hpp17
-rw-r--r--redfish-core/include/utils/json_utils.hpp279
3 files changed, 179 insertions, 414 deletions
diff --git a/redfish-core/include/error_messages.hpp b/redfish-core/include/error_messages.hpp
index 085b76f..62925e1 100644
--- a/redfish-core/include/error_messages.hpp
+++ b/redfish-core/include/error_messages.hpp
@@ -24,6 +24,8 @@
#pragma once
#include <nlohmann/json.hpp>
+#include "crow/http_response.h"
+
namespace redfish
{
@@ -34,56 +36,13 @@ constexpr const char* messageVersionPrefix = "Base.1.2.0.";
constexpr const char* messageAnnotation = "@Message.ExtendedInfo";
/**
- * @brief Adds Message JSON object to error object
- *
- * @param[out] target Target JSON to which message will be added
- * @param[in] message Message JSON that should be added to target
- *
- * @return None
- */
-void addMessageToErrorJson(nlohmann::json& target,
- const nlohmann::json& message);
-
-/**
- * @brief Adds Message JSON object to target JSON
- *
- * @internal
- * This function has similar implementation to addMessageToJson(...), but
- * does not use nlohmann::json_pointer to avoid costly construction
- * @endinternal
- *
- * @param[out] target Target JSON to which message will be added
- * @param[in] message Message JSON that should be added to target
- *
- * @return None
- */
-void addMessageToJsonRoot(nlohmann::json& target,
- const nlohmann::json& message);
-
-/**
- * @brief Adds Message JSON object connected with specific field to target JSON
- *
- * @param[out] target Target JSON to which message will be added
- * @param[in] message Message JSON that should be added to target
- * @param[in] fieldPath Path of related field
- *
- * @return None
- */
-void addMessageToJson(nlohmann::json& target, const nlohmann::json& message,
- const std::string& fieldPath);
-
-/*********************************
- * AUTOGENERATED FUNCTIONS START *
- *********************************/
-
-/**
* @brief Formats ResourceInUse message into JSON
* Message body: "The change to the requested resource failed because the
* resource is in use or in transition."
*
*
* @returns Message ResourceInUse formatted to JSON */
-nlohmann::json resourceInUse();
+void resourceInUse(crow::Response& res);
/**
* @brief Formats MalformedJSON message into JSON
@@ -92,7 +51,7 @@ nlohmann::json resourceInUse();
*
*
* @returns Message MalformedJSON formatted to JSON */
-nlohmann::json malformedJSON();
+void malformedJSON(crow::Response& res);
/**
* @brief Formats ResourceMissingAtURI message into JSON
@@ -101,7 +60,7 @@ nlohmann::json malformedJSON();
* @param[in] arg1 Parameter of message that will replace %1 in its body.
*
* @returns Message ResourceMissingAtURI formatted to JSON */
-nlohmann::json resourceMissingAtURI(const std::string& arg1);
+void resourceMissingAtURI(crow::Response& res, const std::string& arg1);
/**
* @brief Formats ActionParameterValueFormatError message into JSON
@@ -113,9 +72,10 @@ nlohmann::json resourceMissingAtURI(const std::string& arg1);
* @param[in] arg3 Parameter of message that will replace %3 in its body.
*
* @returns Message ActionParameterValueFormatError formatted to JSON */
-nlohmann::json actionParameterValueFormatError(const std::string& arg1,
- const std::string& arg2,
- const std::string& arg3);
+void actionParameterValueFormatError(crow::Response& res,
+ const std::string& arg1,
+ const std::string& arg2,
+ const std::string& arg3);
/**
* @brief Formats InternalError message into JSON
@@ -124,7 +84,16 @@ nlohmann::json actionParameterValueFormatError(const std::string& arg1,
*
*
* @returns Message InternalError formatted to JSON */
-nlohmann::json internalError();
+void internalError(crow::Response& res);
+
+/**
+ * @brief Formats InternalError message into JSON for the specified field
+ * Message body: "The request failed due to an internal service error. The
+ * service is still operational."
+ *
+ *
+ * @returns Message InternalError formatted to JSON */
+void internalError(crow::Response& res, const std::string& fieldPath);
/**
* @brief Formats UnrecognizedRequestBody message into JSON
@@ -133,7 +102,7 @@ nlohmann::json internalError();
*
*
* @returns Message UnrecognizedRequestBody formatted to JSON */
-nlohmann::json unrecognizedRequestBody();
+void unrecognizedRequestBody(crow::Response& res);
/**
* @brief Formats ResourceAtUriUnauthorized message into JSON
@@ -144,8 +113,8 @@ nlohmann::json unrecognizedRequestBody();
* @param[in] arg2 Parameter of message that will replace %2 in its body.
*
* @returns Message ResourceAtUriUnauthorized formatted to JSON */
-nlohmann::json resourceAtUriUnauthorized(const std::string& arg1,
- const std::string& arg2);
+void resourceAtUriUnauthorized(crow::Response& res, const std::string& arg1,
+ const std::string& arg2);
/**
* @brief Formats ActionParameterUnknown message into JSON
@@ -156,8 +125,8 @@ nlohmann::json resourceAtUriUnauthorized(const std::string& arg1,
* @param[in] arg2 Parameter of message that will replace %2 in its body.
*
* @returns Message ActionParameterUnknown formatted to JSON */
-nlohmann::json actionParameterUnknown(const std::string& arg1,
- const std::string& arg2);
+void actionParameterUnknown(crow::Response& res, const std::string& arg1,
+ const std::string& arg2);
/**
* @brief Formats ResourceCannotBeDeleted message into JSON
@@ -166,7 +135,7 @@ nlohmann::json actionParameterUnknown(const std::string& arg1,
*
*
* @returns Message ResourceCannotBeDeleted formatted to JSON */
-nlohmann::json resourceCannotBeDeleted();
+void resourceCannotBeDeleted(crow::Response& res);
/**
* @brief Formats PropertyDuplicate message into JSON
@@ -175,7 +144,7 @@ nlohmann::json resourceCannotBeDeleted();
* @param[in] arg1 Parameter of message that will replace %1 in its body.
*
* @returns Message PropertyDuplicate formatted to JSON */
-nlohmann::json propertyDuplicate(const std::string& arg1);
+void propertyDuplicate(crow::Response& res, const std::string& arg1);
/**
* @brief Formats ServiceTemporarilyUnavailable message into JSON
@@ -185,7 +154,8 @@ nlohmann::json propertyDuplicate(const std::string& arg1);
* @param[in] arg1 Parameter of message that will replace %1 in its body.
*
* @returns Message ServiceTemporarilyUnavailable formatted to JSON */
-nlohmann::json serviceTemporarilyUnavailable(const std::string& arg1);
+void serviceTemporarilyUnavailable(crow::Response& res,
+ const std::string& arg1);
/**
* @brief Formats ResourceAlreadyExists message into JSON
@@ -197,9 +167,8 @@ nlohmann::json serviceTemporarilyUnavailable(const std::string& arg1);
* @param[in] arg3 Parameter of message that will replace %3 in its body.
*
* @returns Message ResourceAlreadyExists formatted to JSON */
-nlohmann::json resourceAlreadyExists(const std::string& arg1,
- const std::string& arg2,
- const std::string& arg3);
+void resourceAlreadyExists(crow::Response& res, const std::string& arg1,
+ const std::string& arg2, const std::string& arg3);
/**
* @brief Formats AccountForSessionNoLongerExists message into JSON
@@ -208,7 +177,7 @@ nlohmann::json resourceAlreadyExists(const std::string& arg1,
*
*
* @returns Message AccountForSessionNoLongerExists formatted to JSON */
-nlohmann::json accountForSessionNoLongerExists();
+void accountForSessionNoLongerExists(crow::Response& res);
/**
* @brief Formats CreateFailedMissingReqProperties message into JSON
@@ -218,7 +187,8 @@ nlohmann::json accountForSessionNoLongerExists();
* @param[in] arg1 Parameter of message that will replace %1 in its body.
*
* @returns Message CreateFailedMissingReqProperties formatted to JSON */
-nlohmann::json createFailedMissingReqProperties(const std::string& arg1);
+void createFailedMissingReqProperties(crow::Response& res,
+ const std::string& arg1);
/**
* @brief Formats PropertyValueFormatError message into JSON
@@ -229,8 +199,22 @@ nlohmann::json createFailedMissingReqProperties(const std::string& arg1);
* @param[in] arg2 Parameter of message that will replace %2 in its body.
*
* @returns Message PropertyValueFormatError formatted to JSON */
-nlohmann::json propertyValueFormatError(const std::string& arg1,
- const std::string& arg2);
+void propertyValueFormatError(crow::Response& res, const std::string& arg1,
+ const std::string& arg2);
+
+/**
+ * @brief Formats PropertyValueFormatError message into JSON for the specified
+ * property
+ * Message body: "The value <arg0> for the property <arg1> is of a different
+ * format than the property can accept."
+ *
+ * @param[in] arg1 Parameter of message that will replace %1 in its body.
+ * @param[in] arg2 Parameter of message that will replace %2 in its body.
+ *
+ * @returns Message PropertyValueFormatError formatted to JSON */
+void propertyValueFormatError(crow::Response& res, const std::string& arg1,
+ const std::string& arg2,
+ const std::string property);
/**
* @brief Formats PropertyValueNotInList message into JSON
@@ -241,8 +225,22 @@ nlohmann::json propertyValueFormatError(const std::string& arg1,
* @param[in] arg2 Parameter of message that will replace %2 in its body.
*
* @returns Message PropertyValueNotInList formatted to JSON */
-nlohmann::json propertyValueNotInList(const std::string& arg1,
- const std::string& arg2);
+void propertyValueNotInList(crow::Response& res, const std::string& arg1,
+ const std::string& arg2);
+
+/**
+ * @brief Formats PropertyValueNotInList message into JSON for the specified
+ * property
+ * Message body: "The value <arg0> for the property <arg1> is not in
+ * the list of acceptable values."
+ *
+ * @param[in] arg1 Parameter of message that will replace %1 in its body.
+ * @param[in] arg2 Parameter of message that will replace %2 in its body.
+ *
+ * @returns Message PropertyValueNotInList formatted to JSON */
+void propertyValueNotInList(crow::Response& res, const std::string& arg1,
+ const std::string& arg2,
+ const std::string property);
/**
* @brief Formats ResourceAtUriInUnknownFormat message into JSON
@@ -252,7 +250,7 @@ nlohmann::json propertyValueNotInList(const std::string& arg1,
* @param[in] arg1 Parameter of message that will replace %1 in its body.
*
* @returns Message ResourceAtUriInUnknownFormat formatted to JSON */
-nlohmann::json resourceAtUriInUnknownFormat(const std::string& arg1);
+void resourceAtUriInUnknownFormat(crow::Response& res, const std::string& arg1);
/**
* @brief Formats ServiceInUnknownState message into JSON
@@ -261,7 +259,7 @@ nlohmann::json resourceAtUriInUnknownFormat(const std::string& arg1);
*
*
* @returns Message ServiceInUnknownState formatted to JSON */
-nlohmann::json serviceInUnknownState();
+void serviceInUnknownState(crow::Response& res);
/**
* @brief Formats EventSubscriptionLimitExceeded message into JSON
@@ -270,7 +268,7 @@ nlohmann::json serviceInUnknownState();
*
*
* @returns Message EventSubscriptionLimitExceeded formatted to JSON */
-nlohmann::json eventSubscriptionLimitExceeded();
+void eventSubscriptionLimitExceeded(crow::Response& res);
/**
* @brief Formats ActionParameterMissing message into JSON
@@ -281,8 +279,8 @@ nlohmann::json eventSubscriptionLimitExceeded();
* @param[in] arg2 Parameter of message that will replace %2 in its body.
*
* @returns Message ActionParameterMissing formatted to JSON */
-nlohmann::json actionParameterMissing(const std::string& arg1,
- const std::string& arg2);
+void actionParameterMissing(crow::Response& res, const std::string& arg1,
+ const std::string& arg2);
/**
* @brief Formats StringValueTooLong message into JSON
@@ -292,7 +290,8 @@ nlohmann::json actionParameterMissing(const std::string& arg1,
* @param[in] arg2 Parameter of message that will replace %2 in its body.
*
* @returns Message StringValueTooLong formatted to JSON */
-nlohmann::json stringValueTooLong(const std::string& arg1, const int& arg2);
+void stringValueTooLong(crow::Response& res, const std::string& arg1,
+ const int& arg2);
/**
* @brief Formats PropertyValueTypeError message into JSON
@@ -303,8 +302,22 @@ nlohmann::json stringValueTooLong(const std::string& arg1, const int& arg2);
* @param[in] arg2 Parameter of message that will replace %2 in its body.
*
* @returns Message PropertyValueTypeError formatted to JSON */
-nlohmann::json propertyValueTypeError(const std::string& arg1,
- const std::string& arg2);
+void propertyValueTypeError(crow::Response& res, const std::string& arg1,
+ const std::string& arg2);
+
+/**
+ * @brief Formats PropertyValueTypeError message into JSON for the specified
+ * property
+ * Message body: "The value <arg0> for the property <arg1> is of a
+ * different type than the property can accept."
+ *
+ * @param[in] arg1 Parameter of message that will replace %1 in its body.
+ * @param[in] arg2 Parameter of message that will replace %2 in its body.
+ *
+ * @returns Message PropertyValueTypeError formatted to JSON */
+void propertyValueTypeError(crow::Response& res, const std::string& arg1,
+ const std::string& arg2,
+ const std::string& property);
/**
* @brief Formats ResourceNotFound message into JSON
@@ -315,8 +328,8 @@ nlohmann::json propertyValueTypeError(const std::string& arg1,
* @param[in] arg2 Parameter of message that will replace %2 in its body.
*
* @returns Message ResourceNotFound formatted to JSON */
-nlohmann::json resourceNotFound(const std::string& arg1,
- const std::string& arg2);
+void resourceNotFound(crow::Response& res, const std::string& arg1,
+ const std::string& arg2);
/**
* @brief Formats CouldNotEstablishConnection message into JSON
@@ -326,7 +339,7 @@ nlohmann::json resourceNotFound(const std::string& arg1,
* @param[in] arg1 Parameter of message that will replace %1 in its body.
*
* @returns Message CouldNotEstablishConnection formatted to JSON */
-nlohmann::json couldNotEstablishConnection(const std::string& arg1);
+void couldNotEstablishConnection(crow::Response& res, const std::string& arg1);
/**
* @brief Formats PropertyNotWritable message into JSON
@@ -336,7 +349,19 @@ nlohmann::json couldNotEstablishConnection(const std::string& arg1);
* @param[in] arg1 Parameter of message that will replace %1 in its body.
*
* @returns Message PropertyNotWritable formatted to JSON */
-nlohmann::json propertyNotWritable(const std::string& arg1);
+void propertyNotWritable(crow::Response& res, const std::string& arg1);
+
+/**
+ * @brief Formats PropertyNotWritable message into JSON for the specified
+ * property
+ * Message body: "The property <arg0> is a read only property and
+ * cannot be assigned a value."
+ *
+ * @param[in] arg1 Parameter of message that will replace %1 in its body.
+ *
+ * @returns Message PropertyNotWritable formatted to JSON */
+void propertyNotWritable(crow::Response& res, const std::string& arg1,
+ const std::string& property);
/**
* @brief Formats QueryParameterValueTypeError message into JSON
@@ -347,8 +372,8 @@ nlohmann::json propertyNotWritable(const std::string& arg1);
* @param[in] arg2 Parameter of message that will replace %2 in its body.
*
* @returns Message QueryParameterValueTypeError formatted to JSON */
-nlohmann::json queryParameterValueTypeError(const std::string& arg1,
- const std::string& arg2);
+void queryParameterValueTypeError(crow::Response& res, const std::string& arg1,
+ const std::string& arg2);
/**
* @brief Formats ServiceShuttingDown message into JSON
@@ -357,7 +382,7 @@ nlohmann::json queryParameterValueTypeError(const std::string& arg1,
*
*
* @returns Message ServiceShuttingDown formatted to JSON */
-nlohmann::json serviceShuttingDown();
+void serviceShuttingDown(crow::Response& res);
/**
* @brief Formats ActionParameterDuplicate message into JSON
@@ -368,8 +393,8 @@ nlohmann::json serviceShuttingDown();
* @param[in] arg2 Parameter of message that will replace %2 in its body.
*
* @returns Message ActionParameterDuplicate formatted to JSON */
-nlohmann::json actionParameterDuplicate(const std::string& arg1,
- const std::string& arg2);
+void actionParameterDuplicate(crow::Response& res, const std::string& arg1,
+ const std::string& arg2);
/**
* @brief Formats ActionParameterNotSupported message into JSON
@@ -380,8 +405,8 @@ nlohmann::json actionParameterDuplicate(const std::string& arg1,
* @param[in] arg2 Parameter of message that will replace %2 in its body.
*
* @returns Message ActionParameterNotSupported formatted to JSON */
-nlohmann::json actionParameterNotSupported(const std::string& arg1,
- const std::string& arg2);
+void actionParameterNotSupported(crow::Response& res, const std::string& arg1,
+ const std::string& arg2);
/**
* @brief Formats SourceDoesNotSupportProtocol message into JSON
@@ -392,8 +417,8 @@ nlohmann::json actionParameterNotSupported(const std::string& arg1,
* @param[in] arg2 Parameter of message that will replace %2 in its body.
*
* @returns Message SourceDoesNotSupportProtocol formatted to JSON */
-nlohmann::json sourceDoesNotSupportProtocol(const std::string& arg1,
- const std::string& arg2);
+void sourceDoesNotSupportProtocol(crow::Response& res, const std::string& arg1,
+ const std::string& arg2);
/**
* @brief Formats AccountRemoved message into JSON
@@ -401,7 +426,7 @@ nlohmann::json sourceDoesNotSupportProtocol(const std::string& arg1,
*
*
* @returns Message AccountRemoved formatted to JSON */
-nlohmann::json accountRemoved();
+void accountRemoved(crow::Response& res);
/**
* @brief Formats AccessDenied message into JSON
@@ -411,7 +436,7 @@ nlohmann::json accountRemoved();
* @param[in] arg1 Parameter of message that will replace %1 in its body.
*
* @returns Message AccessDenied formatted to JSON */
-nlohmann::json accessDenied(const std::string& arg1);
+void accessDenied(crow::Response& res, const std::string& arg1);
/**
* @brief Formats QueryNotSupported message into JSON
@@ -419,7 +444,7 @@ nlohmann::json accessDenied(const std::string& arg1);
*
*
* @returns Message QueryNotSupported formatted to JSON */
-nlohmann::json queryNotSupported();
+void queryNotSupported(crow::Response& res);
/**
* @brief Formats CreateLimitReachedForResource message into JSON
@@ -428,7 +453,7 @@ nlohmann::json queryNotSupported();
*
*
* @returns Message CreateLimitReachedForResource formatted to JSON */
-nlohmann::json createLimitReachedForResource();
+void createLimitReachedForResource(crow::Response& res);
/**
* @brief Formats GeneralError message into JSON
@@ -437,7 +462,7 @@ nlohmann::json createLimitReachedForResource();
*
*
* @returns Message GeneralError formatted to JSON */
-nlohmann::json generalError();
+void generalError(crow::Response& res);
/**
* @brief Formats Success message into JSON
@@ -445,7 +470,15 @@ nlohmann::json generalError();
*
*
* @returns Message Success formatted to JSON */
-nlohmann::json success();
+void success(crow::Response& res);
+
+/**
+ * @brief Formats Success message into JSON for the specified field
+ * Message body: "Successfully Completed Request"
+ *
+ *
+ * @returns Message Success formatted to JSON */
+void success(crow::Response& res, const std::string& fieldPath);
/**
* @brief Formats Created message into JSON
@@ -453,7 +486,7 @@ nlohmann::json success();
*
*
* @returns Message Created formatted to JSON */
-nlohmann::json created();
+void created(crow::Response& res);
/**
* @brief Formats PropertyUnknown message into JSON
@@ -463,7 +496,18 @@ nlohmann::json created();
* @param[in] arg1 Parameter of message that will replace %1 in its body.
*
* @returns Message PropertyUnknown formatted to JSON */
-nlohmann::json propertyUnknown(const std::string& arg1);
+void propertyUnknown(crow::Response& res, const std::string& arg1);
+
+/**
+ * @brief Formats PropertyUnknown message into JSON for the specified property
+ * Message body: "The property <arg0> is not in the list of valid properties for
+ * the resource."
+ *
+ * @param[in] arg1 Parameter of message that will replace %1 in its body.
+ *
+ * @returns Message PropertyUnknown formatted to JSON */
+void propertyUnknown(crow::Response& res, const std::string& arg1,
+ const std::string& property);
/**
* @brief Formats NoValidSession message into JSON
@@ -472,7 +516,7 @@ nlohmann::json propertyUnknown(const std::string& arg1);
*
*
* @returns Message NoValidSession formatted to JSON */
-nlohmann::json noValidSession();
+void noValidSession(crow::Response& res);
/**
* @brief Formats InvalidObject message into JSON
@@ -481,7 +525,7 @@ nlohmann::json noValidSession();
* @param[in] arg1 Parameter of message that will replace %1 in its body.
*
* @returns Message InvalidObject formatted to JSON */
-nlohmann::json invalidObject(const std::string& arg1);
+void invalidObject(crow::Response& res, const std::string& arg1);
/**
* @brief Formats ResourceInStandby message into JSON
@@ -490,7 +534,7 @@ nlohmann::json invalidObject(const std::string& arg1);
*
*
* @returns Message ResourceInStandby formatted to JSON */
-nlohmann::json resourceInStandby();
+void resourceInStandby(crow::Response& res);
/**
* @brief Formats ActionParameterValueTypeError message into JSON
@@ -502,9 +546,9 @@ nlohmann::json resourceInStandby();
* @param[in] arg3 Parameter of message that will replace %3 in its body.
*
* @returns Message ActionParameterValueTypeError formatted to JSON */
-nlohmann::json actionParameterValueTypeError(const std::string& arg1,
- const std::string& arg2,
- const std::string& arg3);
+void actionParameterValueTypeError(crow::Response& res, const std::string& arg1,
+ const std::string& arg2,
+ const std::string& arg3);
/**
* @brief Formats SessionLimitExceeded message into JSON
@@ -513,7 +557,7 @@ nlohmann::json actionParameterValueTypeError(const std::string& arg1,
*
*
* @returns Message SessionLimitExceeded formatted to JSON */
-nlohmann::json sessionLimitExceeded();
+void sessionLimitExceeded(crow::Response& res);
/**
* @brief Formats ActionNotSupported message into JSON
@@ -522,7 +566,7 @@ nlohmann::json sessionLimitExceeded();
* @param[in] arg1 Parameter of message that will replace %1 in its body.
*
* @returns Message ActionNotSupported formatted to JSON */
-nlohmann::json actionNotSupported(const std::string& arg1);
+void actionNotSupported(crow::Response& res, const std::string& arg1);
/**
* @brief Formats InvalidIndex message into JSON
@@ -531,7 +575,7 @@ nlohmann::json actionNotSupported(const std::string& arg1);
* @param[in] arg1 Parameter of message that will replace %1 in its body.
*
* @returns Message InvalidIndex formatted to JSON */
-nlohmann::json invalidIndex(const int& arg1);
+void invalidIndex(crow::Response& res, const int& arg1);
/**
* @brief Formats EmptyJSON message into JSON
@@ -540,7 +584,7 @@ nlohmann::json invalidIndex(const int& arg1);
*
*
* @returns Message EmptyJSON formatted to JSON */
-nlohmann::json emptyJSON();
+void emptyJSON(crow::Response& res);
/**
* @brief Formats QueryNotSupportedOnResource message into JSON
@@ -548,7 +592,7 @@ nlohmann::json emptyJSON();
*
*
* @returns Message QueryNotSupportedOnResource formatted to JSON */
-nlohmann::json queryNotSupportedOnResource();
+void queryNotSupportedOnResource(crow::Response& res);
/**
* @brief Formats InsufficientPrivilege message into JSON
@@ -558,7 +602,7 @@ nlohmann::json queryNotSupportedOnResource();
*
*
* @returns Message InsufficientPrivilege formatted to JSON */
-nlohmann::json insufficientPrivilege();
+void insufficientPrivilege(crow::Response& res);
/**
* @brief Formats PropertyValueModified message into JSON
@@ -569,8 +613,8 @@ nlohmann::json insufficientPrivilege();
* @param[in] arg2 Parameter of message that will replace %2 in its body.
*
* @returns Message PropertyValueModified formatted to JSON */
-nlohmann::json propertyValueModified(const std::string& arg1,
- const std::string& arg2);
+void propertyValueModified(crow::Response& res, const std::string& arg1,
+ const std::string& arg2);
/**
* @brief Formats AccountNotModified message into JSON
@@ -578,7 +622,7 @@ nlohmann::json propertyValueModified(const std::string& arg1,
*
*
* @returns Message AccountNotModified formatted to JSON */
-nlohmann::json accountNotModified();
+void accountNotModified(crow::Response& res);
/**
* @brief Formats QueryParameterValueFormatError message into JSON
@@ -589,8 +633,9 @@ nlohmann::json accountNotModified();
* @param[in] arg2 Parameter of message that will replace %2 in its body.
*
* @returns Message QueryParameterValueFormatError formatted to JSON */
-nlohmann::json queryParameterValueFormatError(const std::string& arg1,
- const std::string& arg2);
+void queryParameterValueFormatError(crow::Response& res,
+ const std::string& arg1,
+ const std::string& arg2);
/**
* @brief Formats PropertyMissing message into JSON
@@ -600,7 +645,18 @@ nlohmann::json queryParameterValueFormatError(const std::string& arg1,
* @param[in] arg1 Parameter of message that will replace %1 in its body.
*
* @returns Message PropertyMissing formatted to JSON */
-nlohmann::json propertyMissing(const std::string& arg1);
+void propertyMissing(crow::Response& res, const std::string& arg1);
+
+/**
+ * @brief Formats PropertyMissing message into JSON for the specified property
+ * Message body: "The property <arg0> is a required property and must be
+ * included in the request."
+ *
+ * @param[in] arg1 Parameter of message that will replace %1 in its body.
+ *
+ * @returns Message PropertyMissing formatted to JSON */
+void propertyMissing(crow::Response& res, const std::string& arg1,
+ const std::string& property);
/**
* @brief Formats ResourceExhaustion message into JSON
@@ -610,7 +666,7 @@ nlohmann::json propertyMissing(const std::string& arg1);
* @param[in] arg1 Parameter of message that will replace %1 in its body.
*
* @returns Message ResourceExhaustion formatted to JSON */
-nlohmann::json resourceExhaustion(const std::string& arg1);
+void resourceExhaustion(crow::Response& res, const std::string& arg1);
/**
* @brief Formats AccountModified message into JSON
@@ -618,7 +674,7 @@ nlohmann::json resourceExhaustion(const std::string& arg1);
*
*
* @returns Message AccountModified formatted to JSON */
-nlohmann::json accountModified();
+void accountModified(crow::Response& res, const std::string& fieldPath);
/**
* @brief Formats QueryParameterOutOfRange message into JSON
@@ -630,13 +686,8 @@ nlohmann::json accountModified();
* @param[in] arg3 Parameter of message that will replace %3 in its body.
*
* @returns Message QueryParameterOutOfRange formatted to JSON */
-nlohmann::json queryParameterOutOfRange(const std::string& arg1,
- const std::string& arg2,
- const std::string& arg3);
-
-/*********************************
- * AUTOGENERATED FUNCTIONS END *
- *********************************/
+void queryParameterOutOfRange(crow::Response& res, const std::string& arg1,
+ const std::string& arg2, const std::string& arg3);
} // namespace messages
diff --git a/redfish-core/include/node.hpp b/redfish-core/include/node.hpp
index 80e0744..41257e0 100644
--- a/redfish-core/include/node.hpp
+++ b/redfish-core/include/node.hpp
@@ -39,23 +39,6 @@ class AsyncResp
~AsyncResp()
{
- if (res.result() != boost::beast::http::status::ok)
- {
- nlohmann::json::iterator error = res.jsonValue.find("error");
-
- if (error == res.jsonValue.end())
- {
- // If an error value hasn't yet been set, assume that whatever
- // content we have is garbage, and provide a worthless internal
- // server error
- res.jsonValue = {};
- }
- // Reset the json object to clear out any data that made it in
- // before the error happened todo(ed) handle error condition with
- // proper code
- messages::addMessageToErrorJson(res.jsonValue,
- messages::internalError());
- }
res.end();
}
diff --git a/redfish-core/include/utils/json_utils.hpp b/redfish-core/include/utils/json_utils.hpp
index 3263c73..b8195c4 100644
--- a/redfish-core/include/utils/json_utils.hpp
+++ b/redfish-core/include/utils/json_utils.hpp
@@ -28,264 +28,6 @@ namespace json_util
{
/**
- * @brief Defines JSON utils operation status
- */
-enum class Result
-{
- SUCCESS,
- NOT_EXIST,
- WRONG_TYPE,
- NULL_POINTER
-};
-
-/**
- * @brief Describes JSON utils messages requirement
- */
-enum class MessageSetting
-{
- NONE = 0x0, ///< No messages will be added
- MISSING = 0x1, ///< PropertyMissing message will be added
- TYPE_ERROR = 0x2 ///< PropertyValueTypeError message will be added
-};
-
-/**
- * @brief Wrapper function for extracting string from JSON object without
- * throwing exceptions
- *
- * @param[in] fieldName Name of requested field
- * @param[in] json JSON object from which field should be extracted
- * @param[out] output Variable to which extracted will be written in case
- * of success
- *
- * @return Result informing about operation status, output will be
- * written only in case of Result::SUCCESS
- */
-Result getString(const char* fieldName, const nlohmann::json& json,
- const std::string*& output);
-
-/**
- * @brief Wrapper function for extracting object from JSON object without
- * throwing exceptions
- *
- * @param[in] fieldName Name of requested field
- * @param[in] json JSON object from which field should be extracted
- * @param[out] output Variable to which extracted will be written in case
- * of success
- *
- * @return Result informing about operation status, output will be
- * written only in case of Result::SUCCESS
- */
-Result getObject(const char* fieldName, const nlohmann::json& json,
- nlohmann::json* output);
-
-/**
- * @brief Wrapper function for extracting array from JSON object without
- * throwing exceptions
- *
- * @param[in] fieldName Name of requested field
- * @param[in] json JSON object from which field should be extracted
- * @param[out] output Variable to which extracted will be written in case
- * of success
- *
- * @return Result informing about operation status, output will be
- * written only in case of Result::SUCCESS
- */
-Result getArray(const char* fieldName, const nlohmann::json& json,
- nlohmann::json* output);
-
-/**
- * @brief Wrapper function for extracting int from JSON object without
- * throwing exceptions
- *
- * @param[in] fieldName Name of requested field
- * @param[in] json JSON object from which field should be extracted
- * @param[out] output Variable to which extracted will be written in case
- * of success
- *
- * @return Result informing about operation status, output will be
- * written only in case of Result::SUCCESS
- */
-Result getInt(const char* fieldName, const nlohmann::json& json,
- int64_t& output);
-
-/**
- * @brief Wrapper function for extracting uint from JSON object without
- * throwing exceptions
- *
- * @param[in] fieldName Name of requested field
- * @param[in] json JSON object from which field should be extracted
- * @param[out] output Variable to which extracted will be written in case
- * of success
- *
- * @return Result informing about operation status, output will be
- * written only in case of Result::SUCCESS
- */
-Result getUnsigned(const char* fieldName, const nlohmann::json& json,
- uint64_t& output);
-
-/**
- * @brief Wrapper function for extracting bool from JSON object without
- * throwing exceptions
- *
- * @param[in] fieldName Name of requested field
- * @param[in] json JSON object from which field should be extracted
- * @param[out] output Variable to which extracted will be written in case
- * of success
- *
- * @return Result informing about operation status, output will be
- * written only in case of Result::SUCCESS
- */
-Result getBool(const char* fieldName, const nlohmann::json& json, bool& output);
-
-/**
- * @brief Wrapper function for extracting float from JSON object without
- * throwing exceptions (nlohmann stores JSON floats as C++ doubles)
- *
- * @param[in] fieldName Name of requested field
- * @param[in] json JSON object from which field should be extracted
- * @param[out] output Variable to which extracted will be written in case
- * of success
- *
- * @return Result informing about operation status, output will be
- * written only in case of Result::SUCCESS
- */
-Result getDouble(const char* fieldName, const nlohmann::json& json,
- double& output);
-
-/**
- * @brief Wrapper function for extracting string from JSON object without
- * throwing exceptions
- *
- * @param[in] fieldName Name of requested field
- * @param[in] json JSON object from which field should be extracted
- * @param[out] output Variable to which extracted will be written in case
- * of success
- * @param[in] msgCfgMap Map for message addition settings
- * @param[out] msgJson JSON to which error messages will be added
- * @param[in] fieldPath Field path in JSON
- *
- * @return Result informing about operation status, output will be
- * written only in case of Result::SUCCESS
- */
-Result getString(const char* fieldName, const nlohmann::json& json,
- const std::string*& output, uint8_t msgCfgMap,
- nlohmann::json& msgJson, const std::string&& fieldPath);
-
-/**
- * @brief Wrapper function for extracting object from JSON object without
- * throwing exceptions
- *
- * @param[in] fieldName Name of requested field
- * @param[in] json JSON object from which field should be extracted
- * @param[out] output Variable to which extracted will be written in case
- * of success
- * @param[in] msgCfgMap Map for message addition settings
- * @param[out] msgJson JSON to which error messages will be added
- * @param[in] fieldPath Field path in JSON
- *
- * @return Result informing about operation status, output will be
- * written only in case of Result::SUCCESS
- */
-Result getObject(const char* fieldName, const nlohmann::json& json,
- nlohmann::json* output, uint8_t msgCfgMap,
- nlohmann::json& msgJson, const std::string&& fieldPath);
-
-/**
- * @brief Wrapper function for extracting array from JSON object without
- * throwing exceptions
- *
- * @param[in] fieldName Name of requested field
- * @param[in] json JSON object from which field should be extracted
- * @param[out] output Variable to which extracted will be written in case
- * of success
- * @param[in] msgCfgMap Map for message addition settings
- * @param[out] msgJson JSON to which error messages will be added
- * @param[in] fieldPath Field path in JSON
- *
- * @return Result informing about operation status, output will be
- * written only in case of Result::SUCCESS
- */
-Result getArray(const char* fieldName, const nlohmann::json& json,
- nlohmann::json* output, uint8_t msgCfgMap,
- nlohmann::json& msgJson, const std::string&& fieldPath);
-
-/**
- * @brief Wrapper function for extracting int from JSON object without
- * throwing exceptions
- *
- * @param[in] fieldName Name of requested field
- * @param[in] json JSON object from which field should be extracted
- * @param[out] output Variable to which extracted will be written in case
- * of success
- * @param[in] msgCfgMap Map for message addition settings
- * @param[out] msgJson JSON to which error messages will be added
- * @param[in] fieldPath Field path in JSON
- *
- * @return Result informing about operation status, output will be
- * written only in case of Result::SUCCESS
- */
-Result getInt(const char* fieldName, const nlohmann::json& json,
- int64_t& output, uint8_t msgCfgMap, nlohmann::json& msgJson,
- const std::string&& fieldPath);
-
-/**
- * @brief Wrapper function for extracting uint from JSON object without
- * throwing exceptions
- *
- * @param[in] fieldName Name of requested field
- * @param[in] json JSON object from which field should be extracted
- * @param[out] output Variable to which extracted will be written in case
- * of success
- * @param[in] msgCfgMap Map for message addition settings
- * @param[out] msgJson JSON to which error messages will be added
- * @param[in] fieldPath Field path in JSON
- *
- * @return Result informing about operation status, output will be
- * written only in case of Result::SUCCESS
- */
-Result getUnsigned(const char* fieldName, const nlohmann::json& json,
- uint64_t& output, uint8_t msgCfgMap, nlohmann::json& msgJson,
- const std::string&& fieldPath);
-
-/**
- * @brief Wrapper function for extracting bool from JSON object without
- * throwing exceptions
- *
- * @param[in] fieldName Name of requested field
- * @param[in] json JSON object from which field should be extracted
- * @param[out] output Variable to which extracted will be written in case
- * of success
- * @param[in] msgCfgMap Map for message addition settings
- * @param[out] msgJson JSON to which error messages will be added
- * @param[in] fieldPath Field path in JSON
- *
- * @return Result informing about operation status, output will be
- * written only in case of Result::SUCCESS
- */
-Result getBool(const char* fieldName, const nlohmann::json& json, bool& output,
- uint8_t msgCfgMap, nlohmann::json& msgJson,
- const std::string&& fieldPath);
-
-/**
- * @brief Wrapper function for extracting float from JSON object without
- * throwing exceptions (nlohmann stores JSON floats as C++ doubles)
- *
- * @param[in] fieldName Name of requested field
- * @param[in] json JSON object from which field should be extracted
- * @param[out] output Variable to which extracted will be written in case
- * of success
- * @param[in] msgCfgMap Map for message addition settings
- * @param[out] msgJson JSON to which error messages will be added
- * @param[in] fieldPath Field path in JSON
- *
- * @return Result informing about operation status, output will be
- * written only in case of Result::SUCCESS
- */
-Result getDouble(const char* fieldName, const nlohmann::json& json,
- double& output, uint8_t msgCfgMap, nlohmann::json& msgJson,
- const std::string&& fieldPath);
-
-/**
* @brief Processes request to extract JSON from its body. If it fails, adds
* MalformedJSON message to response and ends it.
*
@@ -318,9 +60,7 @@ void readJsonValues(const std::string& key, nlohmann::json& jsonValue,
crow::Response& res, std::bitset<Count>& handled)
{
BMCWEB_LOG_DEBUG << "Unable to find variable for key" << key;
- messages::addMessageToErrorJson(res.jsonValue,
- messages::propertyUnknown(key));
- res.result(boost::beast::http::status::bad_request);
+ messages::propertyUnknown(res, key, key);
}
template <size_t Count, size_t Index, typename ValueType,
@@ -344,11 +84,7 @@ void readJsonValues(const std::string& key, nlohmann::json& jsonValue,
{
BMCWEB_LOG_DEBUG << "Value for key " << key
<< " was incorrect type: " << jsonValue.type_name();
- messages::addMessageToErrorJson(
- res.jsonValue,
- messages::propertyValueTypeError(jsonValue.dump(), key));
- res.result(boost::beast::http::status::bad_request);
-
+ messages::propertyValueTypeError(res, jsonValue.dump(), key, key);
return;
}
@@ -367,9 +103,7 @@ void handleMissing(std::bitset<Count>& handled, crow::Response& res,
{
if (!handled.test(Index) && unpackValue<ValueType>::isRequired::value)
{
- messages::addMessageToErrorJson(res.jsonValue,
- messages::propertyMissing(key));
- res.result(boost::beast::http::status::bad_request);
+ messages::propertyMissing(res, key, key);
}
details::handleMissing<Index + 1, Count>(handled, res, in...);
}
@@ -388,17 +122,14 @@ bool readJson(const crow::Request& req, crow::Response& res, const char* key,
if (!jsonRequest.is_object())
{
BMCWEB_LOG_DEBUG << "Json value is not an object";
- messages::addMessageToErrorJson(res.jsonValue,
- messages::unrecognizedRequestBody());
- res.result(boost::beast::http::status::bad_request);
+ messages::unrecognizedRequestBody(res);
return false;
}
if (jsonRequest.empty())
{
BMCWEB_LOG_DEBUG << "Json value is empty";
- messages::addMessageToErrorJson(res.jsonValue, messages::emptyJSON());
- res.result(boost::beast::http::status::bad_request);
+ messages::emptyJSON(res);
return false;
}
OpenPOWER on IntegriCloud