133 |
133 |
return mark_safe(s)
|
134 |
134 |
|
135 |
135 |
def html_type(s):
|
136 |
136 |
return '<span class="type">%s</span>' % s
|
137 |
137 |
|
138 |
138 |
if 'anyOf' in schema:
|
139 |
139 |
return many_of('anyOf', schema['anyOf'])
|
140 |
140 |
|
141 |
|
if 'oneOf' in schema:
|
|
141 |
if 'oneOf' in schema and not schema.get('type') == 'object':
|
142 |
142 |
return many_of('oneOf', schema['oneOf'])
|
143 |
143 |
|
144 |
144 |
if 'allOf' in schema:
|
145 |
145 |
return many_of('allOf', schema['allOf'])
|
146 |
146 |
|
147 |
147 |
original_schema = schema
|
148 |
148 |
schema = schema.copy()
|
149 |
149 |
schema.pop('$schema', None)
|
... | ... | |
188 |
188 |
if typ == 'object':
|
189 |
189 |
s = html_type('object')
|
190 |
190 |
unflatten = schema.pop('unflatten', False)
|
191 |
191 |
merge_extra = schema.pop('merge_extra', False)
|
192 |
192 |
properties = schema.pop('properties', {})
|
193 |
193 |
pattern_properties = schema.pop('patternProperties', {})
|
194 |
194 |
required_keys = schema.pop('required', [])
|
195 |
195 |
additional_properties = schema.pop('additionalProperties', True)
|
|
196 |
one_of = schema.pop('oneOf', [])
|
196 |
197 |
if unflatten:
|
197 |
198 |
s += format_html(', <em class="unflatten">{}</em>', _('unflatten'))
|
198 |
199 |
if merge_extra:
|
199 |
200 |
s += format_html(', <em class="merge-extra">{}</em>', _('merge extra'))
|
200 |
201 |
if not additional_properties:
|
201 |
202 |
s += format_html(
|
202 |
203 |
', <em class="additional-properties-false">{}</em>', _('no additional properties')
|
203 |
204 |
)
|
... | ... | |
235 |
236 |
|
236 |
237 |
if properties:
|
237 |
238 |
keys = properties
|
238 |
239 |
if not isinstance(properties, collections.OrderedDict):
|
239 |
240 |
keys = sorted(properties, key=lambda key: key.lower())
|
240 |
241 |
for key in keys:
|
241 |
242 |
sub = properties.get(key, {}).copy()
|
242 |
243 |
render_property_schema(format_html('<tt>{0}</tt>', key), sub)
|
|
244 |
if one_of and one_of[0].get('required'):
|
|
245 |
s += many_of('oneOf', one_of)
|
243 |
246 |
|
244 |
247 |
if pattern_properties:
|
245 |
248 |
s += format_html('<li><span>{0}</span>', _('Pattern properties'))
|
246 |
249 |
s += '\n<ul>'
|
247 |
250 |
for key, sub in pattern_properties.items():
|
248 |
251 |
if key:
|
249 |
252 |
pattern_key = format_html('/<tt>{0}</tt>/', key)
|
250 |
253 |
else:
|
... | ... | |
257 |
260 |
|
258 |
261 |
return mark_safe(s)
|
259 |
262 |
if typ == 'boolean':
|
260 |
263 |
if not schema:
|
261 |
264 |
return mark_safe(html_type('boolean'))
|
262 |
265 |
enum = schema.pop('enum', [])
|
263 |
266 |
if enum and not schema:
|
264 |
267 |
return mark_safe(' | '.join([format_html('<tt>{}</tt>', json.dumps(el)) for el in enum]))
|
|
268 |
required_keys = schema.pop('required', [])
|
|
269 |
if required_keys and not schema:
|
|
270 |
return format_html('<em>{0} {1!r}</em>', _('required'), ', '.join(required_keys))
|
265 |
271 |
return format_html('<em>{0} {1!r}</em>', _('unknown validation'), original_schema)
|
266 |
272 |
|
267 |
273 |
|
268 |
274 |
@register.simple_tag(takes_context=False)
|
269 |
275 |
def render_body_schemas(body_schemas):
|
270 |
276 |
if not body_schemas:
|
271 |
277 |
return ''
|
272 |
278 |
|