|
1 | 1 | //! Provides interfaces to generate a regular expression based on a given JSON schema. |
2 | 2 | //! |
3 | 3 | //! An optional custom pattern could be passed as well to handle whitespace within the regex. |
4 | | -//! If `None`, the default [WHITESPACE] pattern is used. |
| 4 | +//! If `None`, the default [`WHITESPACE`] pattern is used. |
5 | 5 | //! |
6 | | -//! Returns errors if the JSON schema content is invalid or some feature is not yet supported |
| 6 | +//! Returns errors if JSON schema's content is invalid or some feature is not yet supported |
7 | 7 | //! for regex generation. |
| 8 | +//! |
| 9 | +//! ## Supported features |
| 10 | +//! |
| 11 | +//! Note, that only some of the features of JSON schema are supported for regex generation. |
| 12 | +//! |
| 13 | +//! ### Supported constraints |
| 14 | +//! |
| 15 | +//! #### Common |
| 16 | +//! - `type` |
| 17 | +//! - Specifies the data type (string, number, integer, boolean, array, object, null). |
| 18 | +//! - `enum` |
| 19 | +//! - Lists the allowed values. |
| 20 | +//! - `const` |
| 21 | +//! - Specifies a single allowed value. |
| 22 | +//! |
| 23 | +//! #### Object |
| 24 | +//! - `properties` |
| 25 | +//! - Defines the expected properties of an object and their schemas. |
| 26 | +//! - `required` |
| 27 | +//! - Lists the properties that must be present. |
| 28 | +//! - `additionalProperties` |
| 29 | +//! - Specifies whether additional properties are allowed or defines their schema. |
| 30 | +//! - `minProperties` |
| 31 | +//! - Minimum number of properties required. |
| 32 | +//! - `maxProperties` |
| 33 | +//! - Maximum number of properties allowed. |
| 34 | +//! |
| 35 | +//! #### Array |
| 36 | +//! - `items` |
| 37 | +//! - Defines the schema for array elements (single schema or a schema per index). |
| 38 | +//! - `prefixItems` |
| 39 | +//! - Specifies schemas for the first few elements of an array (tuple validation). |
| 40 | +//! - `minItems` |
| 41 | +//! - Minimum number of items required in the array. |
| 42 | +//! - `maxItems` |
| 43 | +//! - Maximum number of items allowed in the array. |
| 44 | +//! |
| 45 | +//! #### String |
| 46 | +//! - `minLength` |
| 47 | +//! - Minimum string length. |
| 48 | +//! - `maxLength` |
| 49 | +//! - Maximum string length. |
| 50 | +//! - `pattern` |
| 51 | +//! - Regular expression the string must match. |
| 52 | +//! - `format` |
| 53 | +//! - Specifies a pre-defined format, these are supported [`FormatType`] |
| 54 | +//! |
| 55 | +//! #### Number |
| 56 | +//! - `minDigitsInteger` |
| 57 | +//! - Specifies minimum number of digits in the integer part of a numeric value. |
| 58 | +//! - `maxDigitsInteger` |
| 59 | +//! - Specifies maximum number of digits in the integer part of a numeric value. |
| 60 | +//! - `minDigitsFraction` |
| 61 | +//! - Constraints on minimum number of digits allowed in the fractional part of a numeric value. |
| 62 | +//! - `maxDigitsFraction` |
| 63 | +//! - Constraints on maximum number of digits allowed in the fractional part of a numeric value. |
| 64 | +//! - `minDigitsExponent` |
| 65 | +//! - Defines minimum number of digits in the exponent part of a scientific notation number. |
| 66 | +//! - `maxDigitsExponent` |
| 67 | +//! - Defines maximum number of digits in the exponent part of a scientific notation number. |
| 68 | +//! |
| 69 | +//! #### Integer |
| 70 | +//! - `minDigits` |
| 71 | +//! - Defines the minimum number of digits. |
| 72 | +//! - `maxDigits` |
| 73 | +//! - Defines the maximum number of digits. |
| 74 | +//! |
| 75 | +//! #### Logical |
| 76 | +//! - `allOf` |
| 77 | +//! - Combines multiple schemas; all must be valid. |
| 78 | +//! - `anyOf` |
| 79 | +//! - Combines multiple schemas; at least one must be valid. |
| 80 | +//! - `oneOf` |
| 81 | +//! - Combines multiple schemas; exactly one must be valid. |
| 82 | +//! |
| 83 | +//! ### Recursion |
| 84 | +//! |
| 85 | +//! Currently maximum recursion depth is cautiously defined at the level 3. |
| 86 | +//! |
| 87 | +//! Note, that in general recursion in regular expressions is not the best approach due to inherent limitations |
| 88 | +//! and inefficiencies, especially when applied to complex patterns or large input. |
| 89 | +//! |
| 90 | +//! But often, even simple referential JSON schemas will produce enormous regex size, since it increases |
| 91 | +//! exponentially in recursive case, which likely to introduce performance issues by consuming large |
| 92 | +//! amounts of time, resources and memory. |
| 93 | +//! |
| 94 | +//! ### References |
| 95 | +//! |
| 96 | +//! Only local references are currently being supported. |
| 97 | +//! |
| 98 | +//! ### Unconstrained objects |
| 99 | +//! |
| 100 | +//! An empty object means unconstrained, allowing any JSON type. |
8 | 101 |
|
9 | 102 | use serde_json::Value; |
10 | 103 |
|
|
0 commit comments