Projet

Général

Profil

0009-wip-report-xsd-type-in-json-schema.patch

Benjamin Dauvergne, 24 mars 2022 17:42

Télécharger (2,53 ko)

Voir les différences:

Subject: [PATCH 9/9] wip : report xsd type in json schema

 passerelle/apps/soap/models.py | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
passerelle/apps/soap/models.py
183 183
        # simplify schema: when a type contains a unique element, it will try
184 184
        # to match any dict or list with it on input and will flatten the
185 185
        # schema on output.
186
        qname = str(xsd_type.qname).replace('{http://www.w3.org/2001/XMLSchema}', 'xsd:')
186 187
        if (
187 188
            isinstance(xsd_type, zeep.xsd.ComplexType)
188 189
            and len(xsd_type.elements) == 1
......
193 194
                return {
194 195
                    'type': 'array',
195 196
                    'items': self.type2schema(xsd_type.elements[0][1].type, compress=compress),
196
                    'description': f'{xsd_type.qname}',
197
                    'description': f'{qname}',
197 198
                }
198 199
            return self.type2schema(xsd_type.elements[0][1].type, compress=compress)
199 200
        if isinstance(xsd_type, zeep.xsd.ComplexType):
......
201 202
            schema = {
202 203
                'type': 'object',
203 204
                'properties': properties,
204
                'description': f'{xsd_type.qname}',
205
                'description': f'{qname}',
205 206
            }
206 207
            for key, element in xsd_type.elements:
207 208
                if element.min_occurs > 0:
......
211 212
                    element_schema = {'type': 'array', 'items': element_schema}
212 213
                properties[key] = element_schema
213 214
            if not properties:
214
                return {'type': 'null', 'description': f'{xsd_type.qname}'}
215
                return {'type': 'null', 'description': f'{qname}'}
215 216
            return schema
216 217
        if isinstance(xsd_type, zeep.xsd.BuiltinType):
217
            return {'type': 'string', 'description': f'{xsd_type.qname}'}
218
        return {'description': f'!!! convertible {xsd_type.qname} !!!'}
218
            return {'type': 'string', 'description': f'{qname}'}
219
        return {'description': f'!!! convertible {qname} !!!'}
219
-