serverless-openapi-documenter 0.0.100 → 0.0.101
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/package.json +1 -1
- package/src/definitionGenerator.js +1 -7
- package/src/openAPIGenerator.js +33 -21
package/README.md
CHANGED
|
@@ -48,7 +48,7 @@ Options:
|
|
|
48
48
|
--format -f Whether to output the OpenAPI Description as json or yaml. Default: json
|
|
49
49
|
--indent -i File indentation in spaces. Default: 2
|
|
50
50
|
--openApiVersion -a OpenAPI version to generate for. Default: 3.0.0
|
|
51
|
-
--postmanCollection -p Will generate a postman collection (from the generated OpenAPI Description), in json only, if passed in. Default postman.json
|
|
51
|
+
--postmanCollection -p Will generate a postman collection (from the generated OpenAPI Description), in json only, if passed in. Default: postman.json
|
|
52
52
|
--validationWarn -w Warn about validation errors only. Will write the OpenAPI file if generation is successful. Default: false
|
|
53
53
|
```
|
|
54
54
|
|
|
@@ -968,6 +968,8 @@ However, you can configure your own rules from the [ruleset available on the Red
|
|
|
968
968
|
}
|
|
969
969
|
```
|
|
970
970
|
|
|
971
|
+
Since rules can be set to "warn", you no longer are required to tell the plugin to ignore errors with the `--validationWarn` flag.
|
|
972
|
+
|
|
971
973
|
## Example configuration
|
|
972
974
|
|
|
973
975
|
Please view the example [serverless.yml](test/serverless-tests/best/serverless.yml).
|
package/package.json
CHANGED
|
@@ -1021,19 +1021,13 @@ class DefinitionGenerator {
|
|
|
1021
1021
|
|
|
1022
1022
|
const apiDesc = stringifyYaml(this.openAPI);
|
|
1023
1023
|
|
|
1024
|
-
|
|
1024
|
+
return await lintFromString({
|
|
1025
1025
|
source: apiDesc,
|
|
1026
1026
|
config: config,
|
|
1027
1027
|
}).catch((err) => {
|
|
1028
1028
|
console.error(err);
|
|
1029
1029
|
throw err;
|
|
1030
1030
|
});
|
|
1031
|
-
|
|
1032
|
-
if (results.length) {
|
|
1033
|
-
throw results;
|
|
1034
|
-
}
|
|
1035
|
-
|
|
1036
|
-
return true;
|
|
1037
1031
|
}
|
|
1038
1032
|
}
|
|
1039
1033
|
|
package/src/openAPIGenerator.js
CHANGED
|
@@ -195,23 +195,29 @@ class OpenAPIGenerator {
|
|
|
195
195
|
|
|
196
196
|
this.log(`Validating generated OpenAPI Description`, this.logTypes.NOTICE);
|
|
197
197
|
|
|
198
|
-
await generator.validate().catch((err) => {
|
|
198
|
+
const validationResults = await generator.validate().catch((err) => {
|
|
199
199
|
this.log(
|
|
200
200
|
`ERROR: An error was thrown validating the OpenAPI v3 Description`,
|
|
201
201
|
this.logTypes.ERROR
|
|
202
202
|
);
|
|
203
203
|
|
|
204
|
-
this.
|
|
204
|
+
throw new this.serverless.classes.Error(err);
|
|
205
|
+
});
|
|
205
206
|
|
|
206
|
-
|
|
207
|
-
let message = "Error validating OpenAPI Description:\r\n";
|
|
208
|
-
for (const errorMessage of err) {
|
|
209
|
-
message += `${errorMessage.message}\r\n`;
|
|
210
|
-
}
|
|
207
|
+
this.validationErrorDetails(validationResults);
|
|
211
208
|
|
|
212
|
-
|
|
209
|
+
if (validationResults.length && this.config.validationWarn === false) {
|
|
210
|
+
let message = "Error validating OpenAPI Description:\r\n";
|
|
211
|
+
let shouldThrow = false;
|
|
212
|
+
for (const error of validationResults) {
|
|
213
|
+
message += `${error.message}\r\n`;
|
|
214
|
+
if (error.severity === "error") {
|
|
215
|
+
shouldThrow = true;
|
|
216
|
+
}
|
|
213
217
|
}
|
|
214
|
-
|
|
218
|
+
|
|
219
|
+
if (shouldThrow) throw new this.serverless.classes.Error(message);
|
|
220
|
+
}
|
|
215
221
|
|
|
216
222
|
this.log(
|
|
217
223
|
"OpenAPI v3 Description Successfully Generated",
|
|
@@ -306,24 +312,30 @@ class OpenAPIGenerator {
|
|
|
306
312
|
this.config = config;
|
|
307
313
|
}
|
|
308
314
|
|
|
309
|
-
validationErrorDetails(
|
|
310
|
-
|
|
311
|
-
`${chalk.bold.yellow(
|
|
312
|
-
"[VALIDATION]"
|
|
313
|
-
)} Validation errors found in OpenAPI Description: \n`,
|
|
314
|
-
this.logTypes.ERROR
|
|
315
|
-
);
|
|
316
|
-
|
|
317
|
-
for (const error of validationError) {
|
|
315
|
+
validationErrorDetails(validationErrors) {
|
|
316
|
+
if (validationErrors.length) {
|
|
318
317
|
this.log(
|
|
319
|
-
`${chalk.bold.yellow(
|
|
318
|
+
`${chalk.bold.yellow(
|
|
319
|
+
"[VALIDATION]"
|
|
320
|
+
)} Validation errors found in OpenAPI Description: \n`,
|
|
320
321
|
this.logTypes.ERROR
|
|
321
322
|
);
|
|
322
|
-
|
|
323
|
+
|
|
324
|
+
for (const error of validationErrors) {
|
|
323
325
|
this.log(
|
|
324
|
-
`${chalk.bold.
|
|
326
|
+
`${chalk.bold.red("Severity:")} ${error.severity}`,
|
|
325
327
|
this.logTypes.ERROR
|
|
326
328
|
);
|
|
329
|
+
this.log(
|
|
330
|
+
`${chalk.bold.yellow("Message:")} ${error.message}`,
|
|
331
|
+
this.logTypes.ERROR
|
|
332
|
+
);
|
|
333
|
+
for (const location of error.location) {
|
|
334
|
+
this.log(
|
|
335
|
+
`${chalk.bold.yellow("found at location:")} ${location.pointer}`,
|
|
336
|
+
this.logTypes.ERROR
|
|
337
|
+
);
|
|
338
|
+
}
|
|
327
339
|
}
|
|
328
340
|
}
|
|
329
341
|
}
|