Projet

Général

Profil

0001-templates-don-t-display-param-types-as-something-imp.patch

Valentin Deniaud, 10 décembre 2019 13:56

Télécharger (4,11 ko)

Voir les différences:

Subject: [PATCH] templates: don't display param types as something important
 (#38276)

 passerelle/base/templatetags/passerelle.py    | 19 +++++++++++--------
 passerelle/static/css/style.css               |  4 ++++
 .../passerelle/manage/service_view.html       |  2 +-
 3 files changed, 16 insertions(+), 9 deletions(-)
passerelle/base/templatetags/passerelle.py
128 128
            s += ' [ ' + ' | '.join(parts) + ' ]'
129 129
        return mark_safe(s)
130 130

  
131
    def html_type(s):
132
        return '<i class="type">%s</i>' % s
133

  
131 134
    if 'anyOf' in schema:
132 135
        return many_of('anyOf', schema['anyOf'])
133 136

  
......
145 148
    description = schema.pop('description', None)
146 149
    typ = schema.pop('type', None)
147 150
    if typ == 'null':
148
        return mark_safe('<b>null</b>')
151
        return mark_safe(html_type('null'))
149 152
    if typ == 'string':
150 153
        enum = schema.pop('enum', [])
151 154
        min_length = schema.pop('minLength', '')
......
154 157
        if enum:
155 158
            enum = mark_safe(' | '.join(
156 159
                [format_html('"<tt>{}</tt>"', el) for el in enum]))
157
        s = '<b>string'
160
        s = 'string'
158 161
        if max_length or min_length:
159 162
            s += format_html('[{0}:{1}]', min_length, max_length)
160
        s += '</b>'
163
        s = html_type(s)
161 164
        if enum:
162 165
            s += ' %s' % enum
163 166
        if pattern:
......
167 170
        return mark_safe(s)
168 171
    if typ == 'integer':
169 172
        if not schema:
170
            return mark_safe('<b>integer</b>')
173
            return mark_safe(html_type('integer'))
171 174
    if typ == 'number':
172 175
        if not schema:
173
            return mark_safe('<b>number</b>')
176
            return mark_safe(html_type('number'))
174 177
    if typ == 'array':
175
        s = '<b>array</b> '
178
        s = html_type('array') + ' '
176 179
        if 'items' in schema:
177 180
            s += render_json_schema(schema['items'])
178 181
        return mark_safe(s)
179 182
    if typ == 'object':
180
        s = '<b>object</b>'
183
        s = html_type('object')
181 184
        unflatten = schema.pop('unflatten', False)
182 185
        merge_extra = schema.pop('merge_extra', False)
183 186
        properties = schema.pop('properties', {})
......
224 227
        return mark_safe(s)
225 228
    if typ == 'boolean':
226 229
        if not schema:
227
            return mark_safe('<b>boolean</b>')
230
            return mark_safe(html_type('boolean'))
228 231
    return format_html('<em>{0} {1!r}</em>', _('unknown validation'), original_schema)
229 232

  
230 233

  
passerelle/static/css/style.css
204 204
.sftp-widget label {
205 205
	display: block;
206 206
}
207

  
208
ul li .type {
209
    color: grey;
210
}
passerelle/templates/passerelle/manage/service_view.html
74 74
                     {% if param.optional %}({% trans 'optional' %}{% if param.default_value %},
75 75
                       {% trans 'default value:' %} {{param.default_value}}{% endif %}){% endif %}
76 76
                       {% if param.description %}{% trans ':' %} {{param.description}}{% endif %}
77
                       <b class="type">{% if param.type %}{{ param.type }}{% else %}string{% endif %}</b>
77
                       <i class="type">({% if param.type %}{{ param.type }}{% else %}string{% endif %})</i>
78 78
                 </li>
79 79
               {% endfor %}
80 80
             </ul>
81
-