mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Validate DOCUMENTATION schema
This commit is contained in:
parent
10d683a962
commit
a103f81513
2 changed files with 50 additions and 1 deletions
|
@ -18,6 +18,8 @@ from ansible.module_utils import basic as module_utils_basic
|
||||||
from ansible.plugins import module_loader
|
from ansible.plugins import module_loader
|
||||||
from ansible.utils.module_docs import BLACKLIST_MODULES, get_docstring
|
from ansible.utils.module_docs import BLACKLIST_MODULES, get_docstring
|
||||||
|
|
||||||
|
from schema import doc_schema, option_schema
|
||||||
|
|
||||||
from utils import CaptureStd, find_globals
|
from utils import CaptureStd, find_globals
|
||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
|
@ -345,6 +347,26 @@ class ModuleValidator(Validator):
|
||||||
|
|
||||||
return docs
|
return docs
|
||||||
|
|
||||||
|
def _validate_docs_schema(self, doc):
|
||||||
|
errors = []
|
||||||
|
try:
|
||||||
|
doc_schema(doc)
|
||||||
|
except Exception as e:
|
||||||
|
errors.extend(e.errors)
|
||||||
|
|
||||||
|
for key, option in doc.get('options', {}).iteritems():
|
||||||
|
try:
|
||||||
|
option_schema(option)
|
||||||
|
except Exception as e:
|
||||||
|
for error in e.errors:
|
||||||
|
error.path[:0] = ['options', key]
|
||||||
|
errors.extend(e.errors)
|
||||||
|
|
||||||
|
for error in errors:
|
||||||
|
path = [str(p) for p in error.path]
|
||||||
|
self.errors.append('DOCUMENTATION.%s: %s' %
|
||||||
|
('.'.join(path), error.error_message))
|
||||||
|
|
||||||
def _validate_docs(self):
|
def _validate_docs(self):
|
||||||
doc_info = self._get_docs()
|
doc_info = self._get_docs()
|
||||||
try:
|
try:
|
||||||
|
@ -378,6 +400,7 @@ class ModuleValidator(Validator):
|
||||||
self.errors.append('Unknown DOCUMENTATION error, see '
|
self.errors.append('Unknown DOCUMENTATION error, see '
|
||||||
'TRACE')
|
'TRACE')
|
||||||
|
|
||||||
|
self._validate_docs_schema(doc)
|
||||||
self._check_version_added(doc)
|
self._check_version_added(doc)
|
||||||
self._check_for_new_args(doc)
|
self._check_for_new_args(doc)
|
||||||
|
|
||||||
|
@ -451,7 +474,6 @@ class ModuleValidator(Validator):
|
||||||
'TRACE')
|
'TRACE')
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
mod_version_added = StrictVersion(
|
mod_version_added = StrictVersion(
|
||||||
str(existing_doc.get('version_added', '0.0'))
|
str(existing_doc.get('version_added', '0.0'))
|
||||||
|
|
27
ansible_testing/schema.py
Normal file
27
ansible_testing/schema.py
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
from voluptuous import ALLOW_EXTRA, Any, Required, Schema
|
||||||
|
|
||||||
|
option_schema = Schema(
|
||||||
|
{
|
||||||
|
Required('description'): Any(basestring, [basestring]),
|
||||||
|
'required': bool,
|
||||||
|
'choices': Any(list, basestring),
|
||||||
|
'aliases': list,
|
||||||
|
'version_added': Any(basestring, float)
|
||||||
|
},
|
||||||
|
extra=ALLOW_EXTRA
|
||||||
|
)
|
||||||
|
|
||||||
|
doc_schema = Schema(
|
||||||
|
{
|
||||||
|
Required('module'): basestring,
|
||||||
|
'short_description': Any(basestring, [basestring]),
|
||||||
|
'description': Any(basestring, [basestring]),
|
||||||
|
'version_added': Any(basestring, float),
|
||||||
|
'author': Any(None, basestring, [basestring]),
|
||||||
|
'notes': Any(None, [basestring]),
|
||||||
|
'requirements': [basestring],
|
||||||
|
'options': Any(None, dict),
|
||||||
|
'extends_documentation_fragment': Any(basestring, [basestring])
|
||||||
|
},
|
||||||
|
extra=ALLOW_EXTRA
|
||||||
|
)
|
Loading…
Reference in a new issue