Skip to content

Commit afc0712

Browse files
committed
Add supported features in json_schema
1 parent e2f12b5 commit afc0712

File tree

2 files changed

+97
-4
lines changed

2 files changed

+97
-4
lines changed

src/index.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ pub struct Index {
7474
/// println!("Initial state is {}", initial_state);
7575
/// println!("Is initial state a final state? {}", index.is_final_state(&initial_state));
7676
///
77-
/// let allowed_tokens = index.allowed_tokens(&initial_state).unwrap();
77+
/// let allowed_tokens = index.allowed_tokens(&initial_state).expect("Some allowed tokens");
7878
/// println!("Allowed tokens at initial state are {:?}", allowed_tokens);
7979
///
80-
/// let token_id = allowed_tokens.first().unwrap();
80+
/// let token_id = allowed_tokens.first().expect("First token");
8181
/// println!("Next state for the token_id {} is {:?}", token_id, index.next_state(&initial_state, token_id));
8282
///
8383
/// println!("Final states are {:?}", index.final_states());

src/json_schema/mod.rs

Lines changed: 95 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,103 @@
11
//! Provides interfaces to generate a regular expression based on a given JSON schema.
22
//!
33
//! 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.
55
//!
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
77
//! 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.
8101
9102
use serde_json::Value;
10103

0 commit comments

Comments
 (0)