1

I've got a working Spyne/SOAP/WSDL server - how can I save the schema that it is generated? I want to be able to compare the generated schema against an existing schema but it looks from the logs like a schema is generated as a temporary document and then deleted.

Paul D Smith
  • 639
  • 5
  • 16

2 Answers2

1

I just added this functionality to neurons.

https://github.com/plq/neurons/blob/0f350bbdbcd0eda6a3132311a32548b7a8007b53/neurons/daemon/main.py#L106

Here's a cleaner version:

from lxml import etree

from spyne.interface.wsdl import Wsdl11
from spyne.test.sort_wsdl import sort_wsdl

app = Application(...) # a spyne.Application instance

# Hack to make WSDL generator happy
app.transport = "no_transport_at_all"

wsdl = Wsdl11(app.interface)

# A real URL can be passed here, if it's known in advance
wsdl.build_interface_document('hxxp://invalid_url')
doc = wsdl.get_interface_document()

# We need to do it via StringIO because sort_wsdl expects
# an ElementTree instance    
tree = etree.parse(StringIO(doc))
sort_wsdl(tree)

file_name = 'wsdl.%s.xml' % name

with open(file_name, 'w') as f:
    f.write(etree.tostring(elt, pretty_print=True))

If you just want the Xml Schema documents, use the XmlSchema class instead:

from spyne.interface.xml_schema import XmlSchema


app = Application(...) # a spyne.Application instance

document = XmlSchema(app.interface)
document.build_interface_document()

schemas = document.get_interface_document()

and you have a dict of namespace: schema_doc pairs in schemas.

Burak Arslan
  • 7,671
  • 2
  • 15
  • 24
0

There is a hacky way to do this, namely find the code in the Spyne libary that deletes the schema after using it and comment out the deletion. You can then grab the schema (the logging helpfully indicates where it is) and then re-enable the library code. However it would be much nicer if there were some flag or control which either generated a schema and at least said 'don't delete it, save me a copy here...'.

Papadeltasierra
  • 233
  • 1
  • 9