Releases: BRIKEV/express-oas-validator
v3.0.1
v3.0.0
This new release contains a number of significant changes which are summarized in the "What's changed" section below. Check the referenced PRs or the full changelog for more details.
⚠️ Important warning ⚠️
As this release fixes an important performance issue, updating your projects to use this version is strongly recommended.
Keep in mind, however, that this release also contains breaking changes, as the way to initialize the library and access to its methods is now different. This means that upgrading won't be as straightforward as just updating your package.json
files and will require you to make changes into your application's code.
Please, refer to the migration instructions below shall you need more information on how to change your code to work with the latest release.
What's changed
🐛 Bugfixes
- Fix memory leak issue (#28)
☁️ Codeclimate
- Remove unneeded parameter in
paramsValidator
function (#25)
✨ Features
- Add support for multiple instances (#26)
📦 Dependencies
- Upgrade
openapi-validator-utils
to its latest version (#28)
Migration instructions
As stated above, this release includes breaking changes that modify the way in which the library is initialized and how the validation middleware are imported. If you were already using 2.0.2
or other previous version on your project, you'll need to make some changes to the code to adjust to the new way of using the library.
❔ What's the breaking change?
Previously, the library consisted on a singleton instance that was initialized upon the init
method execution, and the provided validateRequest
and validateResponse
methods could be directly imported from the library and used from anywhere else.
There was an issue with this, though, and it's that it was not possible to create multiple instances based upon different open api definition objects within the same project.
In order to cope with this user case and allow for more flexibility, changes introduced in #26 used an entirely different approach: the library will no longer store and handle the validator instances itself. Instead, it's the clients using it who will be in charge of generating and storing as many instances as they need.
As a consequence of this, validateRequest
and validateResponse
middlewares will no longer be exported at global level. Instead, they'll be provided at instance level.
❌ Compliant code for version 2
In version 2, the init
method initialized a validator instance that was stored in the library's inner state.
const { init } = require('express-oas-validator');
init(swaggerDefinition);
This is no longer the case in version 3: init
won't be initializing a global instance stored by the library itself, meaning directly importing validateRequest
and validateResponse
will not work anymore.
const { validateRequest, validateResponse } = require('express-oas-validator');
✔️ Updating our code to work with version 3
- Step 1: Store validation instance in application state
The init
method in this new version returns an instance of the validator. That instance provides both validateRequest
and validateResponse
methods. This means that, in order to use them, you need to store that instance and make it accessible to any source file where you may need to use the validation middlewares.
The easiest way to go would be to create a global variable to store the instance and export its value, as in the example below:
const { init } = require('express-oas-validator');
// Each instance of the validator will provide two methods to perform validation
const myValidatorInstance = init(swaggerDefinition);
module.exports = myValidatorInstance;
This approach will make it very simple for you to reuse the validateRequest
and validateResponse
among multiple files, so you'll be able to migrate with hardly no effort to version 3.
- Step 2: Store validation instance in application state
In order to use validateRequest
or validateResponse
methods, you'll need to directly get them from your instance. If you followed the example described above, this process should be as simple as replacing your import stataments to reference the file with your instance instead of the library.
const { validateRequest, validateResponse } = require('./my-validator-instance');
v2.0.2
v2.0.1
v2.0.0
This release contains:
Bugfixes
- Exclude additional options from content type validation (#14)
- Exclude
undefined
values from additional props validation (#13)
Codeclimate
None
Features
- Rename validate methods to
validateRequest
andvalidateResponse
(#15)
Dependencies
- Bump openapi-validator-utils to v1.1.4
v1.0.4
This release contains:
Bugfixes
None
Codeclimate
None
Features
None
Dependencies
- Bump openapi-validator-utils to v1.1.3
v1.0.3
This release contains:
Bugfixes
None
Codeclimate
None
Features
None
Dependencies
- Bump openapi-validator-utils to v1.0.4
v1.0.2
This release contains:
Bugfixes
None
Codeclimate
None
Features
None
Dependencies
- Bump openapi-validator-utils to v1.0.3
v1.0.1
This release contains:
Bugfixes
None
Codeclimate
- Remove duplicate license and .gitignore files (#8). Thanks to @LonelyPrincess
- Remove deprecated body-parser (#6). Thanks to @LonelyPrincess
- fix: lines code smell (#9)
Features
- improve error messages (#7)
Dependencies
- Bump openapi-validator-utils to v1.0.2
v1.0.0
express-oas-validator first version of the package.