|
cwist
Modern C web framework with libttak runtime
|
Strict JSON schema validation (Zod-style) for CWIST. More...


Go to the source code of this file.
Classes | |
| struct | cwist_zod_error |
| A single validation failure. More... | |
| struct | cwist_zod_result |
| Result returned by cwist_zod_validate() / cwist_zod_parse(). More... | |
Macros | |
| #define | CWIST_ZOD_MAX_ERRORS 32 |
| #define | CWIST_ZOD_FIELD_MAX 64 |
| #define | CWIST_ZOD_MSG_MAX 256 |
Typedefs | |
| typedef struct cwist_zod_error | cwist_zod_error_t |
| A single validation failure. | |
| typedef struct cwist_zod_result | cwist_zod_result_t |
| Result returned by cwist_zod_validate() / cwist_zod_parse(). | |
Functions | |
| cwist_zod_result_t | cwist_zod_validate (const cJSON *json, const cwist_schema_t *schema) |
| Strictly validate an already-parsed cJSON object against a schema. | |
| cwist_zod_result_t | cwist_zod_parse (const char *raw, const cwist_schema_t *schema, cJSON **out) |
| Parse a raw JSON string and validate it in one step. | |
| void | cwist_zod_print_errors (const cwist_zod_result_t *r) |
| Print all validation errors to stderr. | |
Strict JSON schema validation (Zod-style) for CWIST.
Unlike the self-healing layer, this module rejects data that does not conform to the schema. Use it at trust boundaries (HTTP API inputs, DB writes) where silent coercion is undesirable.
It shares the cwist_schema_t / cwist_schema_field_t types defined in json_heal.h so the same schema descriptor can drive both healing and strict validation.
Usage:
Definition in file zod.h.
A single validation failure.
Result returned by cwist_zod_validate() / cwist_zod_parse().
| cwist_zod_result_t cwist_zod_parse | ( | const char * | raw, |
| const cwist_schema_t * | schema, | ||
| cJSON ** | out | ||
| ) |
Parse a raw JSON string and validate it in one step.
On success *out is set to the parsed cJSON tree; the caller must call cJSON_Delete(*out) when done. On failure *out is set to NULL.
| raw | Null-terminated JSON string. |
| schema | Schema descriptor. |
| out | [out] Parsed cJSON tree on success, NULL otherwise. |
Parse a raw JSON string and validate it in one step.
| raw | Raw JSON text to parse. |
| schema | Expected field list and type requirements. |
| out | Optional output pointer that receives the parsed cJSON object on success. |
Definition at line 112 of file zod.c.
References cap, cwist_zod_validate(), and cwist_zod_result::valid.
Referenced by cwist_db_insert_healed().
| void cwist_zod_print_errors | ( | const cwist_zod_result_t * | r | ) |
Print all validation errors to stderr.
Print all validation errors to stderr.
| r | Validation result to print. |
Definition at line 146 of file zod.c.
References cap, cwist_zod_result::error_count, cwist_zod_result::errors, cwist_zod_error::field, and cwist_zod_error::message.
Referenced by cwist_db_insert_healed().
| cwist_zod_result_t cwist_zod_validate | ( | const cJSON * | json, |
| const cwist_schema_t * | schema | ||
| ) |
Strictly validate an already-parsed cJSON object against a schema.
Checks:
No type coercion is performed; use cwist_json_heal() first if coercion is acceptable.
| json | cJSON object (not array / primitive). |
| schema | Schema descriptor. |
Strictly validate an already-parsed cJSON object against a schema.
| json | Parsed JSON object to inspect. |
| schema | Expected field list and type requirements. |
Definition at line 65 of file zod.c.
References cap, CWIST_ZOD_MSG_MAX, cwist_schema::field_count, cwist_schema::fields, cwist_schema_field::name, cwist_schema_field::required, cwist_schema_field::type, and cwist_zod_result::valid.
Referenced by cwist_db_query_strict(), and cwist_zod_parse().