
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
@interledger/openapi
Advanced tools
Validates requests and responses according to an OpenAPI 3.1 schema
This package exposes functionality to validate requests and responses according to a given OpenAPI 3.1 schema.
You can install the package using:
npm install @interledger/openapi
First, instantiate an OpenAPI
validator object with a reference to your OpenAPI spec:
const openApi = await createOpenAPI(OPEN_API_URL_OR_FILE_PATH)
Then, validate requests and responses as such:
const validateRequest = openApi.createRequestValidator({
path: '/resource/{id}',
method: HttpMethod.GET
})
validateRequest(request) // throws or returns true
const validateResponse = openApi.createResponseValidator({
path: '/resource/{id}',
method: HttpMethod.GET
})
validateResponse({ body: response.body, status }) // throws or returns true
Note
The underlying response & request validator packages use the Ajv schema validator library. Each time validators are created via
createRequestValidator
andcreateResponseValidator
, anew Ajv()
instance is also created. Since Ajv recommends instantiating once at initialization, these validators should also be instantiated just once during the lifecycle of the application to avoid any issues.
Likewise, you can validate both requests and responses inside a Koa middleware method, using createValidatorMiddleware
:
const openApi = await createOpenAPI(OPEN_API_URL)
const router = new SomeRouter()
router.get(
'/resource/{id}',
createValidatorMiddleware(openApi, {
path: '/resource/{id}',
method: HttpMethod.GET
})
)
FAQs
Validates requests and responses according to an OpenAPI 3.1 schema
We found that @interledger/openapi demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.