Projet

Général

Profil

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

Benjamin Dauvergne, 25 mars 2022 12:17

Télécharger (4,74 ko)

Voir les différences:

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

 passerelle/apps/soap/models.py | 22 ++++++++++++----------
 tests/test_soap.py             | 19 +++++++++++--------
 2 files changed, 23 insertions(+), 18 deletions(-)
passerelle/apps/soap/models.py
190 190
            and compress
191 191
        ):
192 192
            if xsd_type.elements[0][1].max_occurs != 1:
193
                return {
193
                schema = {
194 194
                    'type': 'array',
195 195
                    'items': self.type2schema(xsd_type.elements[0][1].type, compress=compress),
196
                    'description': f'{xsd_type.qname}',
197 196
                }
198
            return self.type2schema(xsd_type.elements[0][1].type, compress=compress)
199
        if isinstance(xsd_type, zeep.xsd.ComplexType):
197
            else:
198
                schema = self.type2schema(xsd_type.elements[0][1].type, compress=compress)
199
        elif isinstance(xsd_type, zeep.xsd.ComplexType):
200 200
            properties = collections.OrderedDict()
201 201
            schema = {
202 202
                'type': 'object',
203 203
                'properties': properties,
204
                'description': f'{xsd_type.qname}',
205 204
            }
206 205
            for key, element in xsd_type.elements:
207 206
                if element.min_occurs > 0:
......
211 210
                    element_schema = {'type': 'array', 'items': element_schema}
212 211
                properties[key] = element_schema
213 212
            if not properties:
214
                return {'type': 'null', 'description': f'{xsd_type.qname}'}
215
            return schema
216
        if isinstance(xsd_type, zeep.xsd.BuiltinType):
217
            return {'type': 'string', 'description': f'{xsd_type.qname}'}
218
        return {'description': f'!!! convertible {xsd_type.qname} !!!'}
213
                schema = {'type': 'null'}
214
        elif isinstance(xsd_type, zeep.xsd.BuiltinType):
215
            schema = {'type': 'string'}
216
        else:
217
            schema = {}
218
        if xsd_type.qname:
219
            schema['description'] = str(xsd_type.qname).replace('{http://www.w3.org/2001/XMLSchema}', 'xsd:')
220
        return schema
tests/test_soap.py
110 110
    INPUT_SCHEMA = {
111 111
        'properties': {
112 112
            'firstName': {
113
                'description': '{http://www.examples.com/wsdl/HelloService.wsdl}firstName',
113 114
                'properties': {
114
                    'string': {'items': {'type': 'string'}, 'type': 'array'},
115
                    'string': {'items': {'type': 'string', 'description': 'xsd:string'}, 'type': 'array'},
115 116
                },
116 117
                'required': ['string'],
117 118
                'type': 'object',
118 119
            },
119
            'lastName': {'type': 'string'},
120
            'lastName': {'type': 'string', 'description': 'xsd:string'},
120 121
        },
121 122
        'required': ['firstName', 'lastName'],
122 123
        'type': 'object',
123 124
    }
124 125
    OUTPUT_SCHEMA = {
125 126
        'properties': {
126
            'greeting': {'type': 'string'},
127
            'who': {'type': 'string'},
127
            'greeting': {'type': 'string', 'description': 'xsd:string'},
128
            'who': {'type': 'string', 'description': 'xsd:string'},
128 129
        },
129 130
        'required': ['greeting', 'who'],
130 131
        'type': 'object',
......
226 227
    INPUT_SCHEMA = {
227 228
        'type': 'object',
228 229
        'properties': {
229
            'firstName': {'type': 'array', 'items': {'type': 'string'}},
230
            'lastName': {'type': 'string'},
230
            'firstName': {'type': 'array', 'items': {'type': 'string', 'description': 'xsd:string'}},
231
            'lastName': {'type': 'string', 'description': 'xsd:string'},
231 232
        },
232 233
        'required': ['firstName', 'lastName'],
234
        'description': '{urn:examples:helloservice}sayHello',
233 235
    }
234 236
    OUTPUT_SCHEMA = {
237
        'description': '{urn:examples:helloservice}sayHelloResponse',
235 238
        'properties': {
236
            'greeting': {'type': 'string'},
239
            'greeting': {'type': 'string', 'description': 'xsd:string'},
237 240
            'who': {
238 241
                'type': 'array',
239
                'items': {'type': 'string'},
242
                'items': {'type': 'string', 'description': 'xsd:string'},
240 243
            },
241 244
        },
242 245
        'required': ['greeting', 'who'],
243
-