Skip to content

Commit 9a044b2

Browse files
committed
Add utilities for applying a handler to a schema
1 parent 58d8c7e commit 9a044b2

File tree

5 files changed

+3293
-758
lines changed

5 files changed

+3293
-758
lines changed

include/rapidjson/document.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5698,6 +5698,8 @@ class GenericValue {
56985698
return GetIntSubTypeString();
56995699
} else if (IsUint() || IsUint64()) {
57005700
return GetUintSubTypeString();
5701+
} else if (IsString() && !IsYggdrasil()) {
5702+
return GetStringSubTypeString();
57015703
} else {
57025704
RAPIDJSON_ASSERT(IsYggdrasil());
57035705
RAPIDJSON_ASSERT(schema_->HasMember(GetSubTypeString()));
@@ -7064,6 +7066,15 @@ class GenericDocument : public GenericValue<Encoding, Allocator> {
70647066
@returns true if successful, false otherwise.
70657067
*/
70667068
bool Normalize(const ValueType& schema, StringBuffer* error=NULL);
7069+
/*!
7070+
@brief Encode a Value as a schema.
7071+
@param[in] doc Value to encode the schema for.
7072+
@param[in] minimal If True, the schema will not fully describe the
7073+
document and only contain enough properties to validate the
7074+
general properties.
7075+
@returns true if successful, false otherwise.
7076+
*/
7077+
bool EncodeSchema(const ValueType& doc, const bool minimal=false);
70677078
// TODO: Version where schema not provided when setting from existing
70687079
// populated document.
70697080
size_t CountVarArgs(ValueType& schema, bool set) const {

include/rapidjson/error/en.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ inline const RAPIDJSON_ERROR_CHARTYPE* GetValidateError_En(ValidateErrorCode val
135135
// Generic error for debugging
136136
case kValidateErrorGeneric: return RAPIDJSON_ERROR_STRING("Generic error occurred: %message");
137137
case kIncompatibleSchemas: return RAPIDJSON_ERROR_STRING("Incompatible schema property '%property': %expected vs %actual.");
138+
case kValidateErrorMissingSubschema: return RAPIDJSON_ERROR_STRING("Subschema is missing from one of the two schemas.");
139+
case kValidateErrorSubschemas: return RAPIDJSON_ERROR_STRING("Object has one or more invalid subschemas.");
138140
#endif // RAPIDJSON_YGGDRASIL
139141

140142
case kValidateErrorReadOnly: return RAPIDJSON_ERROR_STRING("Property is read-only but has been provided when validation is for writing.");

include/rapidjson/error/error.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,8 @@ enum ValidateErrorCode {
214214
kDeprecatedWarning, //!< Property is being deprecated.
215215
kValidateErrorGeneric, //!< Generic error occurred: %message.
216216
kIncompatibleSchemas, //!< Incompatible schema property `%property`: %expected vs %actual.
217+
kValidateErrorMissingSubschema, //!< Subschema is missing from one of the two schemas.
218+
kValidateErrorSubschemas, //!< Object has one or more invalid subschemas.
217219
#endif // RAPIDJSON_YGGDRASIL
218220

219221
kValidateErrorReadOnly, //!< Property is read-only but has been provided when validation is for writing

0 commit comments

Comments
 (0)