Fix for issue #54.
Fix for method description when request has query and header params. Added dict and xsd:dict types (volume_api).
This commit is contained in:
parent
e53cb209b0
commit
52135c8142
|
@ -588,6 +588,25 @@ class APIChapterContentHandler(xml.sax.ContentHandler, TableMixin):
|
|||
self.nesting = 0 # no indent for blank lines
|
||||
self.content.append('\n\n')
|
||||
|
||||
def visit_link(self, attrs):
|
||||
if attrs:
|
||||
self.inline_markup_stack.append(attrs['xlink:href'])
|
||||
self.no_space = True
|
||||
|
||||
def depart_link(self):
|
||||
content = ' `'
|
||||
# anonymous link
|
||||
if len(self.inline_markup_stack) is 1:
|
||||
content += ('<%s>`__' % self.inline_markup_stack[0])
|
||||
else:
|
||||
content += ' '.join(self.inline_markup_stack[1:None])
|
||||
content += (' <%s>`_' % self.inline_markup_stack[0])
|
||||
|
||||
self.content.append(content)
|
||||
self.inline_markup_stack[:] = []
|
||||
self.no_space = False
|
||||
self.hyperlink_end = True
|
||||
|
||||
|
||||
class APIRefContentHandler(xml.sax.ContentHandler):
|
||||
|
||||
|
|
|
@ -47,7 +47,9 @@ TYPE_MAP = {
|
|||
'xsd:datetime': 'string',
|
||||
'regexp': 'string',
|
||||
'xsd:datetime': 'string',
|
||||
'xsd:date': 'string',
|
||||
'xsd:dict': 'object',
|
||||
'dict': 'object',
|
||||
'alarm': 'string',
|
||||
'xsd:timestamp': 'string',
|
||||
'xsd:char': 'string',
|
||||
|
@ -585,6 +587,8 @@ class WADLHandler(xml.sax.ContentHandler):
|
|||
status_codes = status_code.split(' ')
|
||||
if '200' in status_codes:
|
||||
status_code = '200'
|
||||
elif '201' in status_codes:
|
||||
status_code = '201'
|
||||
# TODO(arrsim) need to do something with the other status
|
||||
# codes
|
||||
param = self.search_stack_for('param')
|
||||
|
@ -809,6 +813,8 @@ class WADLHandler(xml.sax.ContentHandler):
|
|||
status_codes = status_code.split(' ')
|
||||
if '200' in status_codes:
|
||||
status_code = '200'
|
||||
elif '201' in status_codes:
|
||||
status_code = '201'
|
||||
# TODO(arrsim) need to do something with the other status codes
|
||||
name = attrs['name']
|
||||
parameter = create_parameter(
|
||||
|
|
|
@ -92,6 +92,7 @@ class JSONTranslator(nodes.GenericNodeVisitor):
|
|||
self.listitem = False
|
||||
self.lit_block = False
|
||||
self.list_indent = 0
|
||||
self.text_res_desc = ''
|
||||
|
||||
def search_stack_for(self, tag_name):
|
||||
for node in self.node_stack:
|
||||
|
@ -506,6 +507,7 @@ class JSONTranslator(nodes.GenericNodeVisitor):
|
|||
'required': True})
|
||||
node.clear()
|
||||
elif name == 'query':
|
||||
self.text_res_desc = self.text
|
||||
param_name = node[0].astext()
|
||||
self.text = ''
|
||||
description = ''
|
||||
|
@ -516,9 +518,10 @@ class JSONTranslator(nodes.GenericNodeVisitor):
|
|||
'type': 'string',
|
||||
'required': False})
|
||||
elif name == 'reqheader':
|
||||
self.text_res_desc = self.text
|
||||
param_name = node[0].astext()
|
||||
description = ''
|
||||
self.text = ''
|
||||
description = ''
|
||||
resource['parameters'].append(
|
||||
{'name': param_name,
|
||||
'description': description,
|
||||
|
@ -550,7 +553,7 @@ class JSONTranslator(nodes.GenericNodeVisitor):
|
|||
= self.text[len(param_name):]
|
||||
else:
|
||||
resource['parameters'][-1]['description'] = self.text
|
||||
self.text = ''
|
||||
self.text = self.text_res_desc
|
||||
|
||||
def visit_field_name(self, node):
|
||||
self.node_stack[-1]['name'] = node.astext()
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<chapter>
|
||||
<section xml:id="link-v1">
|
||||
<para>
|
||||
To create a keypair, make a <link
|
||||
xlink:href="http://developer.openstack.org/#createKeypair">
|
||||
create keypair</link> request.
|
||||
</para>
|
||||
<para>
|
||||
To test a link that ends the sentence, make a <link
|
||||
xlink:href="http://developer.openstack.org/#createKeypair">
|
||||
create keypair</link>.
|
||||
</para>
|
||||
</section>
|
||||
</chapter>
|
|
@ -125,3 +125,31 @@ class TestChapterParaParser(TestCase):
|
|||
"\nsome more para text"
|
||||
}]
|
||||
)
|
||||
|
||||
def test_link(self):
|
||||
filename = "test-file.xml"
|
||||
test_filename = os.path.dirname(os.path.abspath(__file__))
|
||||
test_filename += "/ch_test-link.xml"
|
||||
|
||||
file_content = """<?xml version="1.0" encoding="UTF-8"?>
|
||||
<book xml:id="link-v1" version="1">
|
||||
<xi:include href="%s"/>
|
||||
</book>
|
||||
""" % (test_filename)
|
||||
|
||||
ch = docbkx_to_json.APIRefContentHandler(filename)
|
||||
xml.sax.parse(StringIO(file_content), ch)
|
||||
|
||||
self.assertEqual(
|
||||
ch.tags,
|
||||
[{
|
||||
'name': 'link-v1',
|
||||
'summary': "To create a keypair, make a "
|
||||
"`create keypair"
|
||||
"\n<http://developer.openstack.org/#createKeypair>`_"
|
||||
" request.\n\n"
|
||||
"To test a link that ends the sentence, make a "
|
||||
"`create keypair\n"
|
||||
"<http://developer.openstack.org/#createKeypair>`_."
|
||||
}]
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue