mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-07 13:52:54 +00:00
Validate EXAMPLES as YAML
This commit is contained in:
committed by
Toshio Kuratomi
parent
499d3a1b53
commit
7c00346714
@@ -71,12 +71,20 @@ class CaptureStd():
|
||||
return self.stdout.getvalue(), self.stderr.getvalue()
|
||||
|
||||
|
||||
def parse_yaml(value, lineno, module, name):
|
||||
def parse_yaml(value, lineno, module, name, load_all=False):
|
||||
traces = []
|
||||
errors = []
|
||||
data = None
|
||||
|
||||
if load_all:
|
||||
loader = yaml.safe_load_all
|
||||
else:
|
||||
loader = yaml.safe_load
|
||||
|
||||
try:
|
||||
data = yaml.safe_load(value)
|
||||
data = loader(value)
|
||||
if load_all:
|
||||
data = list(data)
|
||||
except yaml.MarkedYAMLError as e:
|
||||
e.problem_mark.line += lineno - 1
|
||||
e.problem_mark.name = '%s.%s' % (module, name)
|
||||
|
||||
@@ -471,6 +471,12 @@ class ModuleValidator(Validator):
|
||||
|
||||
if not bool(doc_info['EXAMPLES']['value']):
|
||||
self.errors.append('No EXAMPLES provided')
|
||||
else:
|
||||
_, errors, traces = parse_yaml(doc_info['EXAMPLES']['value'],
|
||||
doc_info['EXAMPLES']['lineno'],
|
||||
self.name, 'EXAMPLES', load_all=True)
|
||||
self.errors.extend(errors)
|
||||
self.traces.extend(traces)
|
||||
|
||||
if not bool(doc_info['RETURN']['value']):
|
||||
if self._is_new_module():
|
||||
|
||||
Reference in New Issue
Block a user