Merge "Add test for missing path params"

This commit is contained in:
Jenkins 2017-01-18 20:52:27 +00:00 committed by Gerrit Code Review
commit 4636482fa4
4 changed files with 60 additions and 0 deletions

View File

@ -14,6 +14,7 @@
from collections import OrderedDict
import os
import re
from docutils import nodes
from docutils.parsers.rst.directives.tables import Table
@ -179,6 +180,12 @@ class RestMethodDirective(Directive):
node['method'] = method
node['url'] = url
# Extract the path parameters from the url
env = self.state.document.settings.env
env.path_params = []
env.path_params = re.findall("{[a-zA-Z][a-zA-Z_0-9]*}", url)
node['target'] = self.state.parent.attributes['ids'][0]
node['css_classes'] = ""
if node['min_version']:
@ -324,6 +331,26 @@ class RestParametersDirective(Table):
("No field definition for ``%s`` found in ``%s``. "
" Skipping." % (ref, fpath)))
# Check for path params in stanza
for i, param in enumerate(self.env.path_params):
if (param.rstrip('}').lstrip('{')) == name:
del self.env.path_params[i]
break
else:
continue
if len(self.env.path_params) is not 0:
# Warn that path parameters are not set in rest_parameter
# stanza and will not appear in the generated table.
for param in self.env.path_params:
self.env.warn(
"%s:%s " % (
self.state_machine.node.source,
self.state_machine.node.line),
("No path parameter ``%s`` found in rest_parameter"
" stanza.\n"
% param.rstrip('}').lstrip('{')))
# self.app.info("New content %s" % new_content)
self.yaml = new_content

View File

@ -35,3 +35,21 @@ Nonexistent Parameter File
.. rest_parameters:: no_parameters.yaml
Check missing path parameters in stanza
---------------------------------------
.. rest_method:: GET /server/{server_id}/{new_id}/{new_id2}
.. rest_parameters:: parameters.yaml
- server_id: server_id
Check another missing path parameters in stanza
-----------------------------------------------
.. rest_method:: GET /server/{b_id}/{c_id2}/{server_id}
.. rest_parameters:: parameters.yaml
- server_id: server_id

View File

@ -1,3 +1,10 @@
# valid path parameter
server_id:
description: |
ID for server.
in: path
required: true
type: string
# These are out of order, this should be a warning.
name2:
in: body

View File

@ -93,3 +93,11 @@ class TestWarnings(base.TestCase):
("ERROR: No parameters defined\n\n.."
+ " rest_parameters:: no_parameters.yaml\n"),
self.warning)
def test_missing_path_parameter_in_stanza(self):
"""Warning when path param not found in rest_parameter stanza."""
self.assertIn(
("WARNING: No path parameter ``b_id`` found in"
+ " rest_parameter stanza.\n"),
self.warning)