Projet

Général

Profil

0001-misc-allow-pattern-description-in-json-schemas-54663.patch

Valentin Deniaud, 23 septembre 2021 14:29

Télécharger (3,65 ko)

Voir les différences:

Subject: [PATCH] misc: allow pattern description in json schemas (#54663)

 passerelle/apps/cmis/models.py             | 10 +++++++---
 passerelle/base/templatetags/passerelle.py |  5 ++++-
 tests/test_templatetags.py                 |  8 ++++++++
 3 files changed, 19 insertions(+), 4 deletions(-)
passerelle/apps/cmis/models.py
55 55
            'properties': {
56 56
                'filename': {
57 57
                    'type': 'string',
58
                    'description': _('Filename (numbers, letters and special caracters "%s" are allowed)')
59
                    % SPECIAL_CHARS,
58
                    'description': _('Filename'),
60 59
                    'pattern': FILE_NAME_PATTERN,
60
                    'pattern_description': _('Numbers, letters and special caracters "%s" are allowed.')
61
                    % SPECIAL_CHARS,
61 62
                },
62 63
                'content': {
63 64
                    'type': 'string',
......
74 75
            'type': 'string',
75 76
            'description': _('Filename (takes precendence over filename in "file" object)'),
76 77
            'pattern': FILE_NAME_PATTERN,
78
            'pattern_description': _('Numbers, letters and special caracters "%s" are allowed.')
79
            % SPECIAL_CHARS,
77 80
        },
78 81
        'path': {
79 82
            'type': 'string',
80
            'description': _('File path (with leading but not trailing slash)'),
83
            'description': _('File path'),
81 84
            'pattern': FILE_PATH_PATTERN,
85
            'pattern_description': _('Must include leading but not trailing slash.'),
82 86
        },
83 87
        'object_type': {
84 88
            'type': 'string',
passerelle/base/templatetags/passerelle.py
158 158
        min_length = schema.pop('minLength', '')
159 159
        max_length = schema.pop('maxLength', '')
160 160
        pattern = schema.pop('pattern', '')
161
        pattern_description = schema.pop('pattern_description', '')
161 162
        if enum:
162 163
            enum = mark_safe(' | '.join([format_html('<tt>{}</tt>', json.dumps(el)) for el in enum]))
163 164
        s = 'string'
......
166 167
        s = html_type(s)
167 168
        if enum:
168 169
            s += ' %s' % enum
169
        if pattern:
170
        if pattern_description:
171
            s += format_html(' <em>{}</em>', pattern_description)
172
        elif pattern:
170 173
            s += format_html(' /<tt>{}</tt>/', pattern)
171 174
        if schema:
172 175
            s += format_html('\n{!r}', schema)
tests/test_templatetags.py
69 69
        str(render_json_schema({'enum': [1, "aaa", [1]]}))
70 70
        == '<tt>1</tt> | <tt>&quot;aaa&quot;</tt> | <tt>[1]</tt>'
71 71
    )
72

  
73

  
74
def test_render_pattern_description():
75
    schema = {'type': 'object', 'properties': {'filename': {'type': 'string', 'pattern': 'abc'}}}
76
    assert 'abc' in render_json_schema(schema)
77

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