Security News
pnpm 9.5 Introduces Catalogs: Shareable Dependency Version Specifiers
pnpm 9.5 introduces a Catalogs feature, enabling shareable dependency version specifiers, reducing merge conflicts and improving support for monorepos.
@apideck/better-ajv-errors
Advanced tools
Readme
Human-friendly JSON Schema validation for APIs
$ yarn add @apideck/better-ajv-errors
or
$ npm i @apideck/better-ajv-errors
Also make sure that you've installed ajv at version 8 or higher.
After validating some data with ajv, pass the errors to betterAjvErrors
import Ajv from 'ajv';
import { betterAjvErrors } from '@apideck/better-ajv-errors';
// Without allErrors: true, ajv will only return the first error
const ajv = new Ajv({ allErrors: true });
const valid = ajv.validate(schema, data);
if (!valid) {
const betterErrors = betterAjvErrors({ schema, data, errors: ajv.errors });
}
Function that formats ajv validation errors in a human-friendly format.
options: BetterAjvErrorsOptions
errors: ErrorObject[] | null | undefined
Your ajv errors, you will find these in the errors
property of your ajv instance (ErrorObject
is a type from the ajv package).data: Object
The data you passed to ajv to be validated.schema: JSONSchema
The schema you passed to ajv to validate against.basePath?: string
An optional base path to prefix paths returned by betterAjvErrors
. For example, in APIs, it could be useful to use '{requestBody}'
or '{queryParemeters}'
as a basePath. This will make it clear to users where exactly the error occurred.ValidationError[]
Array of formatted errors (properties of ValidationError
below)
message: string
Formatted error messagesuggestion?: string
Optional suggestion based on provided data and schemapath: string
Object path where the error occurred (example: .foo.bar.0.quz
)context: { errorType: DefinedError['keyword']; [additionalContext: string]: unknown }
errorType
is error.keyword
proxied from ajv
. errorType
can be used as a key for i18n if needed. There might be additional properties on context, based on the type of error.FAQs
Unknown package
We found that @apideck/better-ajv-errors demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 7 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
pnpm 9.5 introduces a Catalogs feature, enabling shareable dependency version specifiers, reducing merge conflicts and improving support for monorepos.
Security News
A threat actor on BreachForums is selling an unverified npm vulnerability for account takeover, but npm has not officially confirmed the existence of this security concern.
Security News
Cyber insurance rates are dropping as the market matures, according to a new report projecting global premiums to reach $43 billion by 2030, driven by international market uptake and growth in the SME sector.