66# JSON Schema generation and validation from Julia types
77# Provides a simple, convenient interface for generating JSON Schema v7 specifications
88
9+ # Context for tracking type definitions during schema generation with $ref support
10+ mutable struct SchemaContext
11+ # Map from Type to definition name
12+ type_names:: Dict{Type, String}
13+ # Map from definition name to schema
14+ definitions:: Object{String, Any}
15+ # Stack to detect circular references during generation
16+ generation_stack:: Vector{Type}
17+ # Where to store definitions: :definitions (Draft 7) or :defs (Draft 2019+)
18+ defs_location:: Symbol
19+
20+ SchemaContext(defs_location:: Symbol = :definitions) = new(
21+ Dict{Type, String}(),
22+ Object{String, Any}(),
23+ Type[],
24+ defs_location
25+ )
26+ end
27+
928"""
1029 Schema{T}
1130
@@ -31,25 +50,6 @@ instance = User("alice", "alice@example.com", 25)
3150isvalid(schema, instance) # returns true
3251```
3352"""
34- # Context for tracking type definitions during schema generation with $ref support
35- mutable struct SchemaContext
36- # Map from Type to definition name
37- type_names:: Dict{Type, String}
38- # Map from definition name to schema
39- definitions:: Object{String, Any}
40- # Stack to detect circular references during generation
41- generation_stack:: Vector{Type}
42- # Where to store definitions: :definitions (Draft 7) or :defs (Draft 2019+)
43- defs_location:: Symbol
44-
45- SchemaContext(defs_location:: Symbol = :definitions) = new(
46- Dict{Type, String}(),
47- Object{String, Any}(),
48- Type[],
49- defs_location
50- )
51- end
52-
5353struct Schema{T}
5454 type:: Type{T}
5555 spec:: Object{String, Any}
0 commit comments