@@ -131,3 +131,117 @@ def subresources_of(self, resource):
131
131
yield from items
132
132
else :
133
133
yield items
134
+
135
+
136
+ class Draft6 :
137
+
138
+ _SUBRESOURCE = {"not" }
139
+ _SUBRESOURCE_ITEMS = {"allOf" }
140
+ _SUBRESOURCE_VALUES = {"definitions" , "properties" }
141
+
142
+ def id_of (self , resource ):
143
+ if resource is True or resource is False or "$ref" in resource :
144
+ return None
145
+ id = resource .get ("$id" )
146
+ if id is not None and not id .startswith ("#" ):
147
+ return id
148
+
149
+ def anchors_in (self , resource ):
150
+ anchor = resource .get ("$id" , "" )
151
+ if anchor .startswith ("#" ):
152
+ yield Anchor (name = anchor [1 :], resource = resource )
153
+
154
+ def subresources_of (self , resource ):
155
+ for each in self ._SUBRESOURCE :
156
+ if each in resource :
157
+ yield resource [each ]
158
+ for each in self ._SUBRESOURCE_ITEMS :
159
+ if each in resource :
160
+ yield from resource [each ]
161
+ for each in self ._SUBRESOURCE_VALUES :
162
+ if each in resource :
163
+ yield from resource [each ].values ()
164
+
165
+ items = resource .get ("items" )
166
+ if items is None :
167
+ return
168
+ elif isinstance (items , list ):
169
+ yield from items
170
+ else :
171
+ yield items
172
+
173
+
174
+ class Draft4 :
175
+
176
+ _SUBRESOURCE = {"not" }
177
+ _SUBRESOURCE_ITEMS = {"allOf" }
178
+ _SUBRESOURCE_VALUES = {"definitions" , "properties" }
179
+
180
+ def id_of (self , resource ):
181
+ if resource is True or resource is False or "$ref" in resource :
182
+ return None
183
+ id = resource .get ("id" )
184
+ if id is not None and not id .startswith ("#" ):
185
+ return id
186
+
187
+ def anchors_in (self , resource ):
188
+ anchor = resource .get ("id" , "" )
189
+ if anchor .startswith ("#" ):
190
+ yield Anchor (name = anchor [1 :], resource = resource )
191
+
192
+ def subresources_of (self , resource ):
193
+ for each in self ._SUBRESOURCE :
194
+ if each in resource :
195
+ yield resource [each ]
196
+ for each in self ._SUBRESOURCE_ITEMS :
197
+ if each in resource :
198
+ yield from resource [each ]
199
+ for each in self ._SUBRESOURCE_VALUES :
200
+ if each in resource :
201
+ yield from resource [each ].values ()
202
+
203
+ items = resource .get ("items" )
204
+ if items is None :
205
+ return
206
+ elif isinstance (items , list ):
207
+ yield from items
208
+ else :
209
+ yield items
210
+
211
+
212
+ class Draft3 :
213
+
214
+ _SUBRESOURCE = {"not" }
215
+ _SUBRESOURCE_ITEMS = {"allOf" }
216
+ _SUBRESOURCE_VALUES = {"definitions" , "properties" }
217
+
218
+ def id_of (self , resource ):
219
+ if resource is True or resource is False or "$ref" in resource :
220
+ return None
221
+ id = resource .get ("id" )
222
+ if id is not None and not id .startswith ("#" ):
223
+ return id
224
+
225
+ def anchors_in (self , resource ):
226
+ anchor = resource .get ("id" , "" )
227
+ if anchor .startswith ("#" ):
228
+ yield Anchor (name = anchor [1 :], resource = resource )
229
+
230
+ def subresources_of (self , resource ):
231
+ for each in self ._SUBRESOURCE :
232
+ if each in resource :
233
+ yield resource [each ]
234
+ for each in self ._SUBRESOURCE_ITEMS :
235
+ if each in resource :
236
+ yield from resource [each ]
237
+ for each in self ._SUBRESOURCE_VALUES :
238
+ if each in resource :
239
+ yield from resource [each ].values ()
240
+
241
+ items = resource .get ("items" )
242
+ if items is None :
243
+ return
244
+ elif isinstance (items , list ):
245
+ yield from items
246
+ else :
247
+ yield items
0 commit comments