Projet

Général

Profil

0001-templatetags-display-required-fields-on-json-schema-.patch

Nicolas Roche, 12 octobre 2022 15:24

Télécharger (2,44 ko)

Voir les différences:

Subject: [PATCH] templatetags: display required fields on json schema (#70174)

 passerelle/base/templatetags/passerelle.py | 2 +-
 tests/test_templatetags.py                 | 7 +++++++
 2 files changed, 8 insertions(+), 1 deletion(-)
passerelle/base/templatetags/passerelle.py
206 206
            s += format_html('<tt class="raw">{!r}</tt>', schema)
207 207
        if description:
208 208
            s += format_html('\n<p class="description">{}</p>', description)
209 209
        s += ' '
210 210

  
211 211
        def render_property_schema(key, sub):
212 212
            nonlocal s
213 213

  
214
            required = key in required_keys
214
            required = any(k in key for k in required_keys)
215 215
            sub_description = sub.pop('description', '')
216 216
            sub_title = sub.pop('title', '')
217 217
            s += format_html('<li>{0}', key)
218 218
            if required:
219 219
                s += format_html('<span title="{}" class="required">*</span>', _('required'))
220 220
            if description or sub:
221 221
                s += ' :'
222 222
            if sub_title:
tests/test_templatetags.py
73 73
def test_render_pattern_description():
74 74
    schema = {'type': 'object', 'properties': {'filename': {'type': 'string', 'pattern': 'abc'}}}
75 75
    assert 'abc' in render_json_schema(schema)
76 76

  
77 77
    schema['properties']['filename']['pattern_description'] = 'efg'
78 78
    assert 'abc' not in render_json_schema(schema) and 'efg' in render_json_schema(schema)
79 79

  
80 80

  
81
def test_render_required_properties():
82
    schema = {'type': 'object', 'required': ['filename'], 'properties': {'filename': {'type': 'string'}}}
83
    assert '<li><tt>filename</tt><span title="required" class="required">*</span>' in render_json_schema(
84
        schema
85
    )
86

  
87

  
81 88
def test_render_oneof_property_required():
82 89
    schema = {
83 90
        'type': 'object',
84 91
        'properties': {
85 92
            'a': {'type': 'string'},
86 93
            'b': {'type': 'string'},
87 94
        },
88 95
        'oneOf': [
89
-