feat: support for custom assertions functions (#837)

* feat: support for custom assertions functions

* Comment

* Prettier fix

* Add test and doc

* Prettier fix

* Update .redocly.yaml

* Update packages/core/src/config/types.ts

Co-authored-by: Andrew Tatomyr <andrew.tatomyr@redocly.com>

* fix: show 'referenced from' in the lint error message

* Add Prettier changes

* Add e2e and change format

* Fixes after cross review

* Fixes after cross review

* Fixes after cross review

* Change custom assertion syntax

* Update test

* add unit test

* Add assertion to test

* Update packages/core/src/config/config-resolvers.ts

Co-authored-by: Andrew Tatomyr <andrew.tatomyr@redocly.com>

* Update packages/core/src/config/types.ts

Co-authored-by: Andrew Tatomyr <andrew.tatomyr@redocly.com>

* Update packages/core/src/rules/common/assertions/asserts.ts

Co-authored-by: Andrew Tatomyr <andrew.tatomyr@redocly.com>

* Update packages/core/src/types/redocly-yaml.ts

Co-authored-by: Andrew Tatomyr <andrew.tatomyr@redocly.com>

* Update packages/core/src/config/config-resolvers.ts

Co-authored-by: Andrew Tatomyr <andrew.tatomyr@redocly.com>

* Remove console.lo

* Fix types

* fix prettier

* fix prettier

* change assertion return type

* Group assertions message

* Change assertions logic

* Update docs/rules/assertions.md

Co-authored-by: Adam Altman <adam@redoc.ly>

* Update docs/rules/assertions.md

Co-authored-by: Adam Altman <adam@redoc.ly>

* Update documentation

* Update test

* fix comments

* Fix comments

* Fix assertId

* fix tests

* Fix tests

* Documentation update

* Update doc

* Fix comments

* Update snapshots

* Update code

* update assets messages

Co-authored-by: Andrew Tatomyr <andrew.tatomyr@redocly.com>
Co-authored-by: Anton Kozachuk <antonkozachuk@Antons-MacBook-Pro.local>
Co-authored-by: Adam Altman <adam@redoc.ly>
This commit is contained in:
Ivan Osypov
2022-09-20 19:42:14 +03:00
committed by GitHub
parent 45e5a7525a
commit a3f955768b
18 changed files with 1215 additions and 583 deletions

View File

@@ -0,0 +1,19 @@
module.exports = {
id: 'local',
assertions: {
checkWordsStarts: (value, opts, location) => {
const regexp = new RegExp(`^${opts.words.join('|')}`);
if (regexp.test(value)) {
return [];
}
return [{ message: `Should start with one of ${opts.words.join(', ')}`, location }];
},
checkWordsCount: (value, opts, location) => {
const words = value.split(' ');
if (words.length >= opts.min) {
return [];
}
return [{ message: `Should have at least ${opts.min} words`, location }];
},
},
};