Sanity checks: make sure that required
in argument spec coincides with documentation (#65437)
* Add sanity test for required parameters, update ignore.txt, and add changelog.
This commit is contained in:
parent
c19949706f
commit
4be8b2134f
4 changed files with 918 additions and 3 deletions
|
@ -0,0 +1,2 @@
|
||||||
|
minor_changes:
|
||||||
|
- "ansible-test - the module validation code now checks whether ``requirement`` for options is documented correctly."
|
|
@ -68,6 +68,7 @@ Codes
|
||||||
doc-default-does-not-match-spec Documentation Error Value for "default" from the argument_spec does not match the documentation
|
doc-default-does-not-match-spec Documentation Error Value for "default" from the argument_spec does not match the documentation
|
||||||
doc-default-incompatible-type Documentation Error Default value from the documentation is not compatible with type defined in the argument_spec
|
doc-default-incompatible-type Documentation Error Default value from the documentation is not compatible with type defined in the argument_spec
|
||||||
doc-missing-type Documentation Error Documentation doesn't specify a type but argument in ``argument_spec`` use default type (``str``)
|
doc-missing-type Documentation Error Documentation doesn't specify a type but argument in ``argument_spec`` use default type (``str``)
|
||||||
|
doc-required-mismatch Documentation Error argument in argument_spec is required but documentation says it is not, or vice versa
|
||||||
doc-type-does-not-match-spec Documentation Error Argument_spec defines type different than documentation does
|
doc-type-does-not-match-spec Documentation Error Argument_spec defines type different than documentation does
|
||||||
documentation-error Documentation Error Unknown ``DOCUMENTATION`` error
|
documentation-error Documentation Error Unknown ``DOCUMENTATION`` error
|
||||||
documentation-syntax-error Documentation Error Invalid ``DOCUMENTATION`` schema
|
documentation-syntax-error Documentation Error Invalid ``DOCUMENTATION`` schema
|
||||||
|
|
|
@ -1435,6 +1435,22 @@ class ModuleValidator(Validator):
|
||||||
msg=msg
|
msg=msg
|
||||||
)
|
)
|
||||||
|
|
||||||
|
doc_required = doc_options_arg.get('required', False)
|
||||||
|
data_required = data.get('required', False)
|
||||||
|
if (doc_required or data_required) and not (doc_required and data_required):
|
||||||
|
msg = "Argument '%s' in argument_spec" % arg
|
||||||
|
if context:
|
||||||
|
msg += " found in %s" % " -> ".join(context)
|
||||||
|
if doc_required:
|
||||||
|
msg += " is not required, but is documented as being required"
|
||||||
|
else:
|
||||||
|
msg += " is required, but is not documented as being required"
|
||||||
|
self.reporter.error(
|
||||||
|
path=self.object_path,
|
||||||
|
code='doc-required-mismatch',
|
||||||
|
msg=msg
|
||||||
|
)
|
||||||
|
|
||||||
spec_suboptions = data.get('options')
|
spec_suboptions = data.get('options')
|
||||||
doc_suboptions = doc_options_arg.get('suboptions', {})
|
doc_suboptions = doc_options_arg.get('suboptions', {})
|
||||||
if spec_suboptions:
|
if spec_suboptions:
|
||||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue