Skip to content

Commit

Permalink
[1.0.6] Fix: add abilty for proper work with input references which h…
Browse files Browse the repository at this point in the history
…ave spaces between backtick and text (#4)

* feat(apireferences): change regular expression to trim initial and last spaces in input references

* test(test_reference): add test for initial and last spaces in input references

* docs(README): change default reg-ex in "Capturing References" section

* release: update changelog and setup to version 1.0.6

release: update changelog and setup to version 1.0.6
  • Loading branch information
Rainary authored Sep 21, 2022
1 parent 9bc15c4 commit f18d234
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ APIReferences uses regular expressions to capture *references* to API methods in
The default reg-ex is:

```re
`((?P<prefix>[\w-]+):\s*)?(?P<verb>OPTIONS|GET|HEAD|POST|PUT|DELETE|TRACE|CONNECT|PATCH|LINK|UNLINK)\s+(?P<command>\S+)`
`(\s*(?P<prefix>[\w-]+):\s*)?(?P<verb>OPTIONS|GET|HEAD|POST|PUT|DELETE|TRACE|CONNECT|PATCH|LINK|UNLINK)\s+(?P<command>[^`]+)\s*`
```

This expression accepts references like these:
Expand All @@ -907,7 +907,7 @@ For example, if you want to capture ONLY references with prefixes, you may use t
preprocessors:
- apireferences:
reference:
- regex: '((?P<prefix>[\w-]+):\s*)(?P<verb>POST|GET|PUT|UPDATE|DELETE)\s+(?P<command>\S+)`'
- regex: '(\s*(?P<prefix>[\w-]+):\s*)(?P<verb>POST|GET|PUT|UPDATE|DELETE)\s+(?P<command>[^`]+)`\s*'
```
> This example is for illustrative purposes only. You can achieve the same goal by just switching on the `only_with_prefixes` option.
Expand Down
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.0.6

- Fix: now the preprocessor works correctly with initial and last spaces in input references like ``` ` Client-API: GET user/info ` ```

# 1.0.5

- New: `use_multiproject_mode` option (default: `True`) to use cached API registries in multiproject
Expand Down
4 changes: 2 additions & 2 deletions foliant/preprocessors/apireferences/apireferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
from foliant.utils import output


DEFAULT_REF_REGEX = r'`((?P<prefix>[\w-]+):\s*)?' +\
DEFAULT_REF_REGEX = r'`(\s*(?P<prefix>[\w-]+):\s*)?' +\
rf'(?P<verb>{"|".join(HTTP_VERBS)})\s+' +\
r'(?P<command>\S+)`'
r'(?P<command>[^`]+)\s*`'
DEFAULT_IGNORING_PREFIX = 'Ignore'

DEFAULT_REF_DICT = {
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
description=SHORT_DESCRIPTION,
long_description=LONG_DESCRIPTION,
long_description_content_type='text/markdown',
version='1.0.5',
version='1.0.6',
author='Daniil Minukhin',
author_email='[email protected]',
url='https://github.com/foliant-docs/foliantcontrib.apireferences',
Expand Down
8 changes: 8 additions & 0 deletions tests/test_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ def test_init_from_match(self):
self.assertEqual(ref.verb, 'GET')
self.assertEqual(ref.command, '/user/status')

def test_source_with_backtick_spaces(self):
source = '` MyAPI: GET /user/status `'
pattern = re.compile(DEFAULT_REF_REGEX)
match = pattern.search(source)
ref = Reference()
ref.init_from_match(match)
self.assertEqual(ref.source, source)

def test_command_and_ep_slashes(self):
ref = Reference(
source='`MyAPI: GET /user/status`',
Expand Down

0 comments on commit f18d234

Please sign in to comment.