Skip to content

Commit b70715d

Browse files
committed
Update 'How to define a new compatibility rule' section of README
1 parent cf0397f commit b70715d

File tree

1 file changed

+8
-25
lines changed

1 file changed

+8
-25
lines changed

README.rst

+8-25
Original file line numberDiff line numberDiff line change
@@ -149,39 +149,22 @@ How to define a new compatibility rule
149149
150150
Use the following steps to define a new rule:
151151
152-
1. Define a new rule class in ``swagger_spec_compatibility/rules/``
152+
1. Generate the rules skeletons by running ``python -m create_new_rule``.
153+
The tool will be creating the detection rule class, tests, etc. Check the tool output for the exact list of created files.
153154
154-
.. code-block:: python
155+
2. Implement the rule logic (``swagger_spec_compatibility/rules/{filename}.py``) and ensure testing coverage (``tests/rules/{filename}_test.py``)
155156
156-
# Example of the file content (assume that the file will be named FILE.py)
157-
class RuleClassName(BaseRule):
158-
description = ''
159-
error_code = 'ERROR_CODE'
160-
error_level = Level.LEVEL
161-
rule_type = RuleType.TYPE
162-
short_name = ''
163157
164-
@classmethod
165-
def validate(cls, left_spec, right_spec):
166-
# type: (Spec, Spec) -> typing.Iterable[ValidationMessage]
167-
# Implement here your logic
168-
raise NotImplemented()
158+
3. Update ``docs/source/rules/examples/{rule_code}/(new|old).yaml`` example Swagger spec change and update ``docs/source/rules/examples/{rule_code}/tester.py`` tester file.
169159
170-
# Please make sure that:
171-
# * `description` and `short_name` are reasonably explicative to support `swagger_spec_compatibility explain` command
172-
# * `error_code` has REQ- prefix for `RuleType.REQUEST_CONTRACT`, RES- for `RuleType.RESPONSE_CONTRACT` and MIS- for `RuleType.MISCELLANEOUS`
160+
The objective of those files is to provide a simple speec change that triggers the backward incompatible detection rule through the usage of a bravado client (check the other testers for examples).
161+
to ensure that the example that triggers the newly created .
173162
163+
**NOTE**: The testers are executed by automated tests, so ``tester.py`` should complete without errors and that the spec changes are triggering the newly created rule.
174164
175-
3. Add tests to ensure that your rule behaves as expected (tests in ``tests/rules/FILE_test.py``)
176-
177-
3. Add documentation for the defined rule in ``docs/source/rules/ERROR_CODE.rst``. Try to be consistent with the style
165+
4. Add documentation for the defined rule in ``docs/source/rules/{error_code}.rst``. Try to be consistent with the style
178166
of the others documentation pages
179167
180-
4. Add example of a Swagger spec change that triggers the rule in ``docs/source/rules/examples/ERROR_CODE.rst``.
181-
Ensure to define a `tester.py` file that will make explicit the backward incompatible change through the usage of a
182-
`bravado <https://github.com/Yelp/bravado>`_ client (check the other testers for examples).
183-
**NOTE**: The testers are executed by automated tests, this is intended to ensure that documentation is in sync with
184-
the codebase.
185168
5. [Optional] Add integration tests to ensure that no regressions will be introduced and/or to validate edge cases of the new rule.
186169
Integration tests are defined as follow: ``case-<incremental number>-<number of expected reports>-reports-<short description>`` directory
187170
with two files: ``old.yaml`` and ``new.yaml``. The two files represent two versions of the swagger specs that need to be checked for

0 commit comments

Comments
 (0)