Skip to content

Function: analyzeSchema()

analyzeSchema(schema, options?): FormulaField[]

Defined in: analyzeSchema.ts:91

Scans a JSON Schema and returns descriptors for every field that carries a formula key.

Parameters

schema

RJSFSchema

The root RJSF schema to scan.

options?

AnalyzeSchemaOptions

Optional key overrides for locating formulas in the schema.

Returns

FormulaField[]

An array of FormulaField descriptors, one per computed field found.

Remarks

Traversal is depth-first. allOf, $ref, oneOf, and anyOf are all supported. allOf branches are merged with conflict detection. oneOf/anyOf branches are each recursed and fields are collected with the branch schema as the condition. Nested oneOf/anyOf conditions are composed via { allOf: [...] }. $ref is resolved synchronously using findSchemaDefinition (external refs will throw).

Example

ts
import { analyzeSchema } from '@a-ludi/rjsf-formulas'

const fields = analyzeSchema({
  type: 'object',
  properties: {
    price: { type: 'number' },
    total: { type: 'number', 'x-formula': 'price * 2' },
  },
})
// fields[0].path    => ['total']
// fields[0].formula => 'price * 2'

Released under the MIT License.