aptu_coder_core/
schema_helpers.rs1#![cfg(feature = "schemars")]
4
5use schemars::Schema;
6use serde_json::json;
7
8pub fn integer_schema(_gen: &mut schemars::SchemaGenerator) -> Schema {
11 let map = json!({
12 "type": "integer",
13 "minimum": 0
14 })
15 .as_object()
16 .expect("json! object literal is always a Value::Object")
17 .clone();
18 Schema::from(map)
19}
20
21pub fn option_integer_schema(_gen: &mut schemars::SchemaGenerator) -> Schema {
23 let map = json!({
24 "type": ["integer", "null"],
25 "minimum": 0
26 })
27 .as_object()
28 .expect("json! object literal is always a Value::Object")
29 .clone();
30 Schema::from(map)
31}
32
33pub const SUPPORTED_FILE_EXT_PATTERN: &str = r"(?i)\.(rs|py|go|ts|tsx|js|mjs|cjs|java|kt|kts|cs|cpp|cc|cxx|c|h|hpp|hxx|f|f77|f90|f95|f03|f08|for|ftn|html|htm|md|mdx|astro|css|yaml|yml|json|toml)$";
40
41pub fn supported_file_path_schema(_gen: &mut schemars::SchemaGenerator) -> Schema {
44 let map = serde_json::json!({
45 "type": "string",
46 "pattern": SUPPORTED_FILE_EXT_PATTERN
47 })
48 .as_object()
49 .expect("json! object literal is always a Value::Object")
50 .clone();
51 Schema::from(map)
52}
53
54pub fn option_page_size_schema(_gen: &mut schemars::SchemaGenerator) -> Schema {
58 let map = json!({
59 "type": ["integer", "null"],
60 "minimum": 1
61 })
62 .as_object()
63 .expect("json! object literal is always a Value::Object")
64 .clone();
65 Schema::from(map)
66}