From 9dd9223244691ed821fa628609b82f802d3b1fb3 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Thu, 24 Mar 2022 17:42:20 +0100 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(-) diff --git a/passerelle/apps/soap/models.py b/passerelle/apps/soap/models.py index 19cef471..07751065 100644 --- a/passerelle/apps/soap/models.py +++ b/passerelle/apps/soap/models.py @@ -190,18 +190,17 @@ class SOAPConnector(BaseResource, HTTPResource): and compress ): if xsd_type.elements[0][1].max_occurs != 1: - return { + schema = { 'type': 'array', 'items': self.type2schema(xsd_type.elements[0][1].type, compress=compress), - 'description': f'{xsd_type.qname}', } - return self.type2schema(xsd_type.elements[0][1].type, compress=compress) - if isinstance(xsd_type, zeep.xsd.ComplexType): + else: + schema = self.type2schema(xsd_type.elements[0][1].type, compress=compress) + elif isinstance(xsd_type, zeep.xsd.ComplexType): properties = collections.OrderedDict() schema = { 'type': 'object', 'properties': properties, - 'description': f'{xsd_type.qname}', } for key, element in xsd_type.elements: if element.min_occurs > 0: @@ -211,8 +210,11 @@ class SOAPConnector(BaseResource, HTTPResource): element_schema = {'type': 'array', 'items': element_schema} properties[key] = element_schema if not properties: - return {'type': 'null', 'description': f'{xsd_type.qname}'} - return schema - if isinstance(xsd_type, zeep.xsd.BuiltinType): - return {'type': 'string', 'description': f'{xsd_type.qname}'} - return {'description': f'!!! convertible {xsd_type.qname} !!!'} + schema = {'type': 'null'} + elif isinstance(xsd_type, zeep.xsd.BuiltinType): + schema = {'type': 'string'} + else: + schema = {} + if xsd_type.qname: + schema['description'] = str(xsd_type.qname).replace('{http://www.w3.org/2001/XMLSchema}', 'xsd:') + return schema diff --git a/tests/test_soap.py b/tests/test_soap.py index 6695f5a6..b0cda693 100644 --- a/tests/test_soap.py +++ b/tests/test_soap.py @@ -110,21 +110,22 @@ xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> INPUT_SCHEMA = { 'properties': { 'firstName': { + 'description': '{http://www.examples.com/wsdl/HelloService.wsdl}firstName', 'properties': { - 'string': {'items': {'type': 'string'}, 'type': 'array'}, + 'string': {'items': {'type': 'string', 'description': 'xsd:string'}, 'type': 'array'}, }, 'required': ['string'], 'type': 'object', }, - 'lastName': {'type': 'string'}, + 'lastName': {'type': 'string', 'description': 'xsd:string'}, }, 'required': ['firstName', 'lastName'], 'type': 'object', } OUTPUT_SCHEMA = { 'properties': { - 'greeting': {'type': 'string'}, - 'who': {'type': 'string'}, + 'greeting': {'type': 'string', 'description': 'xsd:string'}, + 'who': {'type': 'string', 'description': 'xsd:string'}, }, 'required': ['greeting', 'who'], 'type': 'object', @@ -226,17 +227,19 @@ class SOAP12(SOAP11): INPUT_SCHEMA = { 'type': 'object', 'properties': { - 'firstName': {'type': 'array', 'items': {'type': 'string'}}, - 'lastName': {'type': 'string'}, + 'firstName': {'type': 'array', 'items': {'type': 'string', 'description': 'xsd:string'}}, + 'lastName': {'type': 'string', 'description': 'xsd:string'}, }, 'required': ['firstName', 'lastName'], + 'description': '{urn:examples:helloservice}sayHello', } OUTPUT_SCHEMA = { + 'description': '{urn:examples:helloservice}sayHelloResponse', 'properties': { - 'greeting': {'type': 'string'}, + 'greeting': {'type': 'string', 'description': 'xsd:string'}, 'who': { 'type': 'array', - 'items': {'type': 'string'}, + 'items': {'type': 'string', 'description': 'xsd:string'}, }, }, 'required': ['greeting', 'who'], -- 2.35.1