@@ -61,50 +61,50 @@ module JSON
61
61
62
62
{% if klass <= Array || klass <= Set % }
63
63
{% if klass.type_vars.size == 1 % }
64
- has_items = ::JSON ::Schema .introspect {{klass.type_vars[0 ]}}
64
+ % has_items = ::JSON ::Schema .introspect({{klass.type_vars[0 ]}})
65
+ {type: " array" , items: % has_items}
65
66
{% else % }
66
67
# handle inheritance (no access to type_var / unknown value)
67
- has_items = NamedTuple .new
68
- {% end % }
69
- if has_items.empty?
70
- % klass = {{klass}}
68
+ % klass = {{klass.ancestors[0 ]}}
71
69
% klass.responds_to?(:json_schema ) ? % klass.json_schema : {type: " array" }
72
- else
73
- {type: " array" , items: has_items}
74
- end
70
+ {% end % }
75
71
{% elsif klass.union? % }
76
72
{ anyOf: [
77
73
{% for type in klass.union_types % }
78
74
::JSON ::Schema .introspect({{type }}),
79
75
{% end % }
80
76
]}
81
77
{% elsif klass_name.starts_with? " Tuple(" % }
82
- has_items = [
78
+ % has_items = [
83
79
{% for generic in klass.type_vars % }
84
80
::JSON ::Schema .introspect({{generic}}),
85
81
{% end % }
86
82
]
87
- {type: " array" , items: has_items}
83
+ {type: " array" , items: % has_items}
88
84
{% elsif klass_name.starts_with? " NamedTuple(" % }
89
- {type: " object" , properties: {
90
- {% for key in klass.keys % }
91
- {{key.id}}: ::JSON ::Schema .introspect({{klass[key].resolve.name}}),
92
- {% end % }
93
- },
94
- {% required = [] of String % }
95
- {% for key in klass.keys % }
96
- {% if ! klass[key].resolve.nilable? % }
97
- {% required << key.id.stringify % }
85
+ {% if klass.keys.empty? % }
86
+ {type: " object" , properties: {} of Symbol => Nil }
87
+ {% else % }
88
+ {type: " object" , properties: {
89
+ {% for key in klass.keys % }
90
+ {{key.id}}: ::JSON ::Schema .introspect({{klass[key].resolve.name}}),
98
91
{% end % }
99
- {% end % }
100
- {% if ! required.empty? % }
101
- required: [
102
- {% for key in required % }
103
- {{key}},
92
+ },
93
+ {% required = [] of String % }
94
+ {% for key in klass.keys % }
95
+ {% if ! klass[key].resolve.nilable? % }
96
+ {% required << key.id.stringify % }
97
+ {% end % }
104
98
{% end % }
105
- ]
106
- {% end % }
107
- }
99
+ {% if ! required.empty? % }
100
+ required: [
101
+ {% for key in required % }
102
+ {{key}},
103
+ {% end % }
104
+ ]
105
+ {% end % }
106
+ }
107
+ {% end % }
108
108
{% elsif klass < Enum % }
109
109
{type: " string" , enum: {{klass.constants.map(& .stringify.underscore)}} }
110
110
{% elsif klass <= String || klass <= Symbol % }
@@ -133,7 +133,7 @@ module JSON
133
133
% klass.json_schema
134
134
else
135
135
# anything will validate (JSON::Any)
136
- NamedTuple .new
136
+ { type: " object " }
137
137
end
138
138
{% end % }
139
139
{% end % }
0 commit comments