Skip to content

Commit 8f4a1b1

Browse files
authored
Merge pull request #209 from JaredCE/allow-configurable-redocly-rules
Allow configurable redocly rules
2 parents 7faab6a + a7f784a commit 8f4a1b1

7 files changed

+801
-606
lines changed

README.md

+22-7
Original file line numberDiff line numberDiff line change
@@ -942,16 +942,31 @@ This will set the `Cache-Control` Response Header to have a value of "no-store"
942942

943943
Validation for the OpenAPI Description is now (as of 0.0.90) done by [Redocly](https://redocly.com/). This is a slightly less opinionated validator for an OpenAPI Description, it should result in less errors around "YAML Anchors". It's also a maintained library, and has support for OpenAPI 3.1.0 which I hope to be able to support very soon.
944944

945+
I am making use of https://www.npmjs.com/package/@redocly/openapi-core, which I have been warned is likely to change. If you notice anything going wrong with validation of your OpenAPI Description, feel free to open an issue here. I make active use of this library, so will hopefully come across those issues too.
946+
947+
### Rules
948+
945949
I have configured the validator to use these Rules:
946950

947-
* [spec](https://redocly.com/docs/cli/rules/spec/)
948-
* [path-parameters-defined](https://redocly.com/docs/cli/rules/path-parameters-defined/)
949-
* [operation-2xx-response](https://redocly.com/docs/cli/rules/operation-2xx-response/)
950-
* [operation-4xx-response](https://redocly.com/docs/cli/rules/operation-4xx-response/)
951-
* [operation-operationId-unique](https://redocly.com/docs/cli/rules/operation-operationid-unique/)
952-
* [path-declaration-must-exist](https://redocly.com/docs/cli/rules/path-declaration-must-exist/)
951+
- [spec](https://redocly.com/docs/cli/rules/spec/)
952+
- [path-parameters-defined](https://redocly.com/docs/cli/rules/path-parameters-defined/)
953+
- [operation-2xx-response](https://redocly.com/docs/cli/rules/operation-2xx-response/)
954+
- [operation-4xx-response](https://redocly.com/docs/cli/rules/operation-4xx-response/)
955+
- [operation-operationId-unique](https://redocly.com/docs/cli/rules/operation-operationid-unique/)
956+
- [path-declaration-must-exist](https://redocly.com/docs/cli/rules/path-declaration-must-exist/)
953957

954-
I am making use of https://www.npmjs.com/package/@redocly/openapi-core, which I have been warned is likely to change. If you notice anything going wrong with validation of your OpenAPI Description, feel free to open an issue here. I make active use of this library, so will hopefully come across those issues too.
958+
However, you can configure your own rules from the [ruleset available on the Redocly site](https://redocly.com/docs/cli/rules/built-in-rules/). To do this, you will need to create a `redocly.json` file within an `options` folder. The file should look like:
959+
960+
```json
961+
{
962+
"spec": "error",
963+
"path-parameters-defined": "error",
964+
"operation-2xx-response": "error",
965+
"operation-4xx-response": "error",
966+
"operation-operationId-unique": "error",
967+
"path-declaration-must-exist": "error"
968+
}
969+
```
955970

956971
## Example configuration
957972

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "serverless-openapi-documenter",
3-
"version": "0.0.97",
3+
"version": "0.0.100",
44
"description": "Generate OpenAPI v3 documentation and Postman Collections from your Serverless Config",
55
"main": "index.js",
66
"keywords": [

src/definitionGenerator.js

+14-10
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,19 @@ class DefinitionGenerator {
6969
},
7070
};
7171

72+
try {
73+
this.REDOCLY_RULES = require(path.resolve("options", "redocly.json"));
74+
} catch (err) {
75+
this.REDOCLY_RULES = {
76+
spec: "error",
77+
"path-parameters-defined": "error",
78+
"operation-2xx-response": "error",
79+
"operation-4xx-response": "error",
80+
"operation-operationId-unique": "error",
81+
"path-declaration-must-exist": "error",
82+
};
83+
}
84+
7285
try {
7386
this.refParserOptions = require(path.resolve("options", "ref-parser.js"));
7487
} catch (err) {
@@ -1003,16 +1016,7 @@ class DefinitionGenerator {
10031016
async validate() {
10041017
const config = await createConfig({
10051018
apis: {},
1006-
// styleguide: {
1007-
rules: {
1008-
spec: "error",
1009-
"path-parameters-defined": "error",
1010-
"operation-2xx-response": "error",
1011-
"operation-4xx-response": "error",
1012-
"operation-operationId-unique": "error",
1013-
"path-declaration-must-exist": "error",
1014-
},
1015-
// },
1019+
rules: this.REDOCLY_RULES,
10161020
});
10171021

10181022
const apiDesc = stringifyYaml(this.openAPI);

test/helpers/redocly.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"spec": "error",
3+
"operation-2xx-response": "warn"
4+
}

0 commit comments

Comments
 (0)