Registry / devops / flat-ajv-schema

flat-ajv-schema

JSON →
library1.0.1jsnpmunverified

Extracts a flattened JSON schema object from a compiled AJV validator instance by resolving all $ref references. Version 1.0.1 is the current stable release. This is a single-purpose utility with no updates since initial release. It differs from alternatives by working directly with AJV instances rather than schemas, making it useful for debugging and serialization of validated schemas.

npm install flat-ajv-schema
INSTALL
IMPORT
SIG · FLAT-AJV-SCHEMA
F
flat-ajv-schema
devopsjavascriptv1.0.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

flattenSchema
import flattenSchema from 'flat-ajv-schema'
import { flattenSchema } from 'flat-ajv-schema'
ESM default export; named import will not work.
flattenSchema
const flattenSchema = require('flat-ajv-schema')
const { flattenSchema } = require('flat-ajv-schema')
CJS default export; destructuring will result in undefined.
default
import flatFun from 'flat-ajv-schema'
No named exports. Use any local name for default import.

Shows how to flatten an AJV validator instance into a resolved schema object.

import Ajv from 'ajv'; import flattenSchema from 'flat-ajv-schema'; const defsSchema = { $id: 'defs', type: 'object', properties: { one: { type: 'string' } } }; const valSchema = { $id: 'valSchema', $ref: 'defs#/properties/one' }; const ajv = new Ajv({ schemas: [defsSchema, valSchema] }); const validator = ajv.getSchema('valSchema'); const flat = flattenSchema(validator); console.log(flat); // Output: { defs: { 'defs#/properties/one': { type: 'string' } }, valSchema: { $id: 'valSchema', $ref: 'defs#/properties/one' } }
Debug
Known issues
breakingOnly works with compiled AJV validator instances; passing raw schema objects or other validator libraries will throw.
fix
Ensure you pass the result of ajv.getSchema(...) or similar AJV compiled validator.
affects: >=0.0.0
gotchaThe flattened schema preserves $ref strings; it does not deep-resolve them inline. Consumers expecting fully resolved schema may be surprised.
fix
Use the output to understand reference structure, not as a standalone validated schema.
affects: >=0.0.0
gotchaOnly supports JSON Schema draft-07 and later; older drafts may not work correctly.
fix
Upgrade your schema to draft-07 or later.
affects: >=0.0.0
deprecatedNo TypeScript definitions included; users may need to create custom .d.ts or use @ts-ignore.
fix
Add 'declare module 'flat-ajv-schema';' in a .d.ts file.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: validator is not a function
Passed something other than a compiled AJV validator function.
fix
Ensure you pass the result of ajv.getSchema(schemaId) or new Ajv().compile(schema).
Cannot find module 'ajv'
Peer dependency AJV is not installed.
fix
Install ajv: npm install ajv
Schema with $id 'defs' is not present in validator's schemas
The internal schemas map is empty or does not contain referenced schemas.
fix
Make sure the AJV instance was created with the schemas option or addSchema was used.
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies
ajvrequiredProduces the compiled validator instance that this library consumes
Agent activity
2 hits · last 30 days
node
2
Resources
flat-ajv-schema — npm install flat-ajv-schema · libregistry