Skip to content

Commit

Permalink
Migrate failOnErrors
Browse files Browse the repository at this point in the history
  • Loading branch information
kalinchernev committed Mar 12, 2021
1 parent 7bebcd8 commit 70cffb9
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 5 deletions.
24 changes: 23 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
## Change Log

### v6.0.7 (2021/02/26 14:33 +00:00)
### upcoming (2021/03/12 08:24 +00:00)

- [#258](https://github.com/Surnet/swagger-jsdoc/pull/258) doc: Add article to materials to inspire you (#258) (@goldsziggy)

### v6.1.0 (2021/03/11 07:53 +00:00)

- [e85a78d](https://github.com/Surnet/swagger-jsdoc/commit/e85a78d836105ffc24a9db773a44639f8a544186) Provide an option to allow throwing on parsing errors (@kalinchernev)

### v6.0.9 (2021/03/07 10:34 +00:00)

- [ff80f64](https://github.com/Surnet/swagger-jsdoc/commit/ff80f642bd7f30ce861049d2a0b8701b1ea98ba6) Release 6.0.9 (@kalinchernev)
- [#256](https://github.com/Surnet/swagger-jsdoc/pull/256) fix(anchors): applied a fix for anchors living in seperate files with… (#256) (@goldsziggy)

### v7.0.0-rc.4 (2021/03/01 16:00 +00:00)

- [15bce04](https://github.com/Surnet/swagger-jsdoc/commit/15bce0415b4dfff7ca21d8931b5498e71a9013ff) correction: v6.0.8 (@kalinchernev)

### v6.0.8 (2021/03/01 15:20 +00:00)

- [fc3d62c](https://github.com/Surnet/swagger-jsdoc/commit/fc3d62c61a266b879fd8ab1531f77634645f0247) v6.0.7 (@kalinchernev)
- [#253](https://github.com/Surnet/swagger-jsdoc/pull/253) fix(specification): apply fix for multiple anchors (#253) (@goldsziggy)

### v7.0.0-rc.3 (2021/02/26 14:33 +00:00)

- [8873370](https://github.com/Surnet/swagger-jsdoc/commit/887337050ec3b2d246d2fa9a9bd3570b3746d379) Update docs (@kalinchernev)
- [#250](https://github.com/Surnet/swagger-jsdoc/pull/250) Update FIRST-STEPS.md (#250) (@azizkale)
Expand Down
3 changes: 2 additions & 1 deletion docs/FIRST-STEPS.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,11 @@ The following is an acceptable reference to information from `x-amazon-apigatewa

Additional materials to inspire you:

- [De-duping the Duplication in Services Featuring: Swagger/OpenAPI and AJV](https://medium.com/geekculture/de-duping-the-duplication-in-services-featuring-swagger-openapi-and-ajv-abd22c8c764e) - 09/03/2021
- [How to implement and use Swagger in Node.js](https://js.plainenglish.io/how-to-implement-and-use-swagger-in-nodejs-d0b95e765245) - 24/02/2021
- [Document your Javascript code with JSDoc](https://dev.to/paulasantamaria/document-your-javascript-code-with-jsdoc-2fbf) - 20/08/2019
- [Swagger: Time to document that Express API you built!](https://levelup.gitconnected.com/swagger-time-to-document-that-express-api-you-built-9b8faaeae563) - 25/05/2019
[Express API with autogenerated OpenAPI doc through Swagger](https://www.acuriousanimal.com/blog/2018/10/20/express-swagger-doc) - 20/10/2018
- [Express API with autogenerated OpenAPI doc through Swagger](https://www.acuriousanimal.com/blog/2018/10/20/express-swagger-doc) - 20/10/2018
- [Swaggerize your API Documentation](http://imaginativethinking.ca/swaggerize-your-api-documentation/) - 01/06/2018
- [Swagger and NodeJS](https://mherman.org/blog/swagger-and-nodejs/) 20/11/2017
- [Agile documentation for your API-driven project](https://kalinchernev.github.io/agile-documentation-api-driven-project) - 21/01/2017
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "7.0.0-rc.5",
"version": "7.0.0-rc.6",
"npmClient": "yarn",
"useWorkspaces": true
}
1 change: 1 addition & 0 deletions packages/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { validateOptions } from './src/utils.js';
* Main function
* @param {object} options - Configuration options
* @param {string} options.encoding Optional, passed to read file function options. Defaults to 'utf8'.
* @param {boolean} options.failOnErrors Whether or not to throw when parsing errors. Defaults to false.
* @param {string} options.format Optional, defaults to '.json' - target file format '.yml' or '.yaml'.
* @param {object} options.swaggerDefinition
* @param {object} options.definition
Expand Down
2 changes: 1 addition & 1 deletion packages/lib/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "swagger-jsdoc",
"description": "Generates swagger doc based on JSDoc",
"version": "7.0.0-rc.5",
"version": "7.0.0-rc.6",
"engines": {
"node": ">=12.0.0"
},
Expand Down
6 changes: 5 additions & 1 deletion packages/lib/src/specification.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import doctrine from 'doctrine';
import parser from 'swagger-parser';
import YAML from 'yaml';
import fs from 'fs';

import {
convertGlobPaths,
Expand Down Expand Up @@ -285,7 +286,10 @@ export async function extract(options) {
.filter((error) => !!error);

if (errReport.length) {
// Place to provide feedback for errors. Previously throwing, now reporting only.
if (options.failOnErrors) {
fs.writeFileSync('bump.txt', errReport);
throw new Error(errReport);
}
console.info(
'Not all input has been taken into account at your final specification.'
);
Expand Down
26 changes: 26 additions & 0 deletions packages/lib/test/specification.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,5 +431,31 @@ describe('Specification module', () => {
consoleInfo.mockClear();
consoleErr.mockClear();
});

it('should throw when failOnErrors is truthy', async () => {
const consoleInfo = jest.spyOn(console, 'info');
const consoleErr = jest.spyOn(console, 'error');

await expect(
extract({
apis: [`${__dirname}/fixtures/wrong/example.yaml`],
failOnErrors: true,
})
).rejects
.toThrow(`YAMLSemanticError: The !!! tag handle is non-default and was not declared. at line 2, column 3:
!!!title: Hello World
^^^^^^^^^^^^^^^^^^^^^…
YAMLSemanticError: Implicit map keys need to be on a single line at line 2, column 3:
!!!title: Hello World
^^^^^^^^^^^^^^^^^^^^^…
`);
expect(consoleInfo).not.toHaveBeenCalled();
expect(consoleInfo).not.toHaveBeenCalled();
consoleInfo.mockClear();
consoleErr.mockClear();
});
});
});

0 comments on commit 70cffb9

Please sign in to comment.