Featurevisor

Definitions in depth

Schemas

A schema says what a value may hold: a variable's, or data your application validates, such as a sign up form. This page writes schemas for variables first, then delivers one to an application and gives it issues, mutations and annotations, whose rules then change in a pull request without a deploy.

Describe a value

Every variable describes its value with the same fields. A global variable puts them at the root of its file, and a feature variable puts them under its key in variablesSchema. checkoutSettings from Variables is an object with a string and an array of strings:

variables/checkoutSettings.yml
description: Checkout settings
type: object
properties:
currency:
type: string
paymentMethods:
type: array
items:
type: string
required: [currency, paymentMethods]
defaultValue:
currency: EUR
paymentMethods: [card]
  • properties lists an object's keys, each with its own schema. Objects can nest.
  • required lists the keys that must be present. As in JSON Schema, any key it does not list is optional, so without required every key is. In an object that allows no other keys, lint checks that each key it lists is one of properties, so a misspelt emial fails.
  • items describes every element of an array. Without it, a variable's array holds strings, and a schema in schemas/ must have it.
  • An object without properties accepts a flat object of strings, numbers, booleans and null.

Featurevisor uses a subset of JSON Schema. Variables lists the types.

A schema in schemas/ reserves some names, and lint rejects them with reserved_name as a field name at any depth, as a schema's key and as the key of a mutation or an issues entry:

  • the names JavaScript objects inherit, which attributes reserve too, since a value would read differently in JavaScript than in the other SDKs: __proto__, constructor, prototype, toString, valueOf, hasOwnProperty, isPrototypeOf, propertyIsEnumerable, toLocaleString, __defineGetter__, __defineSetter__, __lookupGetter__ and __lookupSetter__
  • names no path can reach: an empty name, one with ., [, ] or *, and one of digits only, such as 2024, which a path reads as an index

Constrain values

These keywords narrow what a value may be. They act as guardrails: whoever changes a value in a pull request gets a lint error before an invalid one can ship.

KeywordApplies toRequires
enumAny typeOne of the listed values
constAny typeExactly this value
minimum, maximuminteger, numberA number in range
minLength, maxLengthstringA length in range
patternstringA match for a regular expression
formatstringA timestamp or a comparable version
minItems, maxItemsarrayA number of items in range
uniqueItemsarrayNo duplicate items

Limit checkoutSettings to two currencies and at least one distinct payment method:

variables/checkoutSettings.yml
# ...
type: object
properties:
currency:
type: string
enum: [EUR, GBP]
paymentMethods:
type: array
minItems: 1
uniqueItems: true
items:
type: string

An override that sets currency: USD now fails lint with Value at "currency" in variable "checkoutSettings" must be one of the allowed enum values (got "USD"), followed by the path of the offending override, such as overrides.0.mutate.currency.

pattern uses JavaScript regular expression syntax with the u flag, tested unanchored, so add ^ and $ to match a whole value. minLength and maxLength count characters as JSON Schema does, so an emoji counts one, and so does . in a pattern. enum values must match the declared type.

The u flag rejects escapes that mean nothing, so write [a-z_] rather than [a-z\_]. Lint says which rewrite to use, as a warning for a variable and as an error for a schema file.

Date strings

Store a timestamp as type: string with optional format: date-time to have lint validate portable timestamps:

variables/checkoutLaunch.yml
description: Checkout launch instant
type: string
format: date-time
defaultValue: "2026-11-27T00:00:00Z"

This checks defaults, disabled values, enum, const, override values and mutation results wherever values are validated against the schema. It works in feature variablesSchema, reusable schemas and nested properties, items, additionalProperties and oneOf branches. Formats apply only to strings. A variable with format: date-time compares only with before, after and the presence operators in conditions, like a timestamp attribute.

For a variable, the format is an authoring constraint, not a datafile field. Generated variable types stay string. Plain strings can still be compared with before and after without declaring a format. A schema delivered to an application keeps its format, and validation checks it there too.

Version strings

Use format: semver for a version that the version operators compare:

variables/minimumAppVersion.yml
description: Oldest app version that gets the new checkout
type: string
format: semver
defaultValue: 5.5.0

Lint rejects values these operators cannot compare, such as 5.5,0. Versions like 5.5 and v5.5.0 are accepted. date-time and semver are the only formats. Any other format is a lint error.

Reuse a schema

When several variables hold the same shape, define it once in schemas/. The file name is its key:

schemas/notice.yml
description: A notice shown to users
type: object
properties:
id:
type: string
label:
type: string
message:
type: string
required: [id, label, message]

Reference it with schema in place of type, properties and items. This global variable is the notice shown while the maintenanceMode kill switch from Conditions is on:

variables/maintenanceNotice.yml
description: Shown while paused
schema: notice
defaultValue:
id: maintenance
label: Maintenance
message: Checkout is back shortly

A feature variable references it the same way:

features/liveChat.yml
# ...
variablesSchema:
greeting:
schema: notice
defaultValue:
id: greeting
label: Chat
message: How can we help?

Schemas can reference other schemas, so a list of notices is a schema too:

schemas/notices.yml
description: A list of notices
type: array
items:
schema: notice

checkoutNotices from Mutations can now describe its items by name:

variables/checkoutNotices.yml
description: Notices shown during checkout
type: object
properties:
items:
schema: notices
required: [items]
defaultValue:
items:
- id: base
label: Base
message: Standard notice

A schema reference works anywhere a schema does: at the root, in properties, in items and in oneOf. It cannot be combined with inline fields at the same level.

The illustration shows the same idea with a different set of schemas: a feature's variables refer to schemas by name, and those schemas refer to further schemas.

In features/myFeature.yml, the hero variable uses the hero schema and the items of navLinks use link. In the hero schema, cta uses link and image uses the image schema.

A schema can reference itself, such as a list whose items are strings or further lists, as long as the reference sits under properties, items or additionalProperties, so each step reads deeper into the value. Lint rejects a reference that comes back to its schema at the same value, such as a oneOf branch naming its own schema, since no value could pass it. A value can nest such a schema at most 128 references deep, as How values are checked explains.

Choose between shapes

Use oneOf when a value may take one of several shapes. It must match exactly one of them:

variables/identifier.yml
description: ID from several systems
oneOf:
- type: string
- type: integer
defaultValue: anonymous

Give oneOf at least two branches. Each branch is a full schema, so it can use enum, const, nested objects or a schema reference, such as a string or a whole notice. A variable uses one of type, oneOf or schema, never two.

There is no null type. A value that may be null is a oneOf with const: null as one of its branches.

Allow any key

additionalProperties accepts any key, with one schema for every value. checkoutLabels maps locales to the label of the pay button:

variables/checkoutLabels.yml
description: Pay button label per locale
type: object
additionalProperties:
type: string
defaultValue:
en-GB: Pay now
nl-NL: Nu betalen

additionalProperties can be a schema reference, and can sit alongside fixed properties. additionalProperties: true accepts any other key with any value. Without additionalProperties, an object with properties rejects every key it does not list.

Hold raw JSON

The json type holds a JSON string that Featurevisor does not inspect:

variables/paymentProviderConfig.yml
description: Payment provider config
type: json
defaultValue: '{"provider": "adyen", "retries": 3}'

SDKs have a JSON getter that parses it. Prefer object whenever you know the shape, so linting can check it. json is for variables only, so a schema in schemas/ never has it.

Validate application data

Experimental

@featurevisor/schemas is experimental, so its API may change in a minor release.

A schema in schemas/ can also reach your application, which checks its own data against it: a form, an API request, a message from a queue. Its rules then live in your Featurevisor project, reviewed in pull requests, and change without a deploy.

A sign up form asks for an email address, a display name and a country. Declare the tag of the web app's datafile in your configuration, as Targets does:

featurevisor.config.js
module.exports = {
tags: ['web', 'mobile'],
}

Give the schema that tag:

schemas/signUp.yml
description: A sign up form
tags:
- web
type: object
properties:
email:
type: string
pattern: ^[^@\s]+@[^@\s]+$
displayName:
type: string
minLength: 2
maxLength: 40
country:
type: string
enum: [nl, de]
required: [email, displayName, country]

A target that selects web now delivers it, as it delivers the features and global variables tagged web:

targets/web.yml
description: Web app
tag: web

Nothing reaches a datafile unless you opt in. A schema without tags stays in your project, and a target with no tag selector or includeSchemas delivers none. Targets also selects schemas by key.

Say what the schema accepts in a spec, as you would for a feature:

tests/schemas/signUp.spec.yml
schema: signUp
assertions:
- description: A complete sign up passes
value:
email: user-[email protected]
displayName: Ada
country: nl
expectedToBeValid: true
- description: A one letter name is too short
value:
email: user-[email protected]
displayName: A
country: nl
expectedIssues:
- path: [displayName]
code: minLength

Testing lists what a schema spec can check. Lint, test and build as you do for flags:

Commands
npx featurevisor lint
npx featurevisor test
npx featurevisor build

datafiles/featurevisor-web.json now carries the schema in a schemas section, along with any schema it references. Deploy it as you deploy datafiles for flags, and validate in the app with the SDK instance it already has, through @featurevisor/schemas:

import { createFeaturevisor } from '@featurevisor/sdk'
import { createSchemas } from '@featurevisor/schemas'
const f = createFeaturevisor({ datafile })
const s = createSchemas(f)
const value = {
displayName: 'A',
country: 'nl',
}
s.validate('signUp', value).issues
// [{ path: ['displayName'], code: 'minLength', ... }]

To let Belgians sign up, add be to the enum in a pull request. Once it merges and the datafile is deployed, every application accepts it, with no release.

A schema file holds more than its rules, and only some of it reaches a datafile:

FieldIn a datafileExplained in
description, metadata, promotableNoMetadata, Promotable
tagsNo, it selects targetsThis section
The rules, such as typeYesDescribe a value
messagesYesWord the issues
issues, mutationsYes, compiledIssues, Mutations
annotationsUnless includeAnnotations: falseAnnotations
annotationsSchemaNoAdd your own annotations
optionSchemaNoGive choices their own fields

A variable can use a delivered schema too, with schema: signUp, as long as it has no mutations or issues, since a variable's schema stays the same for everyone.

Validating data follows a service from its first schema to a rule rolled out to a quarter of its users, and Rendering forms renders signUp with React, React Hook Form and TanStack Form. The JavaScript SDK is the reference for validating.

Word the issues

Every issue comes with a message, such as Value at "displayName" must be at least 2 characters long (got 1). messages beside an object's properties words its fields' issues instead, a field at a time, with a message for each issue code:

schemas/signUp.yml
# ...
required: [email, displayName, country]
messages:
email:
required: Tell us your email address
pattern: Enter an email such as user-[email protected]
displayName:
minLength: Use at least {minLength} characters

A sign up without an email address now says Tell us your email address, and a one letter name Use at least 2 characters.

  • A message is a template. Braces hold the issue's params, such as {minLength} and {length}, or {title} from the field's title. {{ and }} write literal braces.
  • "[]" holds the messages of an array's items, and "*" those of the values an open object allows.
  • A map can reach into a referenced schema, such as address: { city: { required: ... } }, and then words this schema's use of it only.
  • A field can carry messages beside its own rules too, keyed by code. A reusable schema words its own issues that way.

Lint checks that each key is an issue code or a field, and that each placeholder is a param of its code. A misspelt {minLenght} fails with Placeholder "{minLenght}" is not a param of "minLength". When a field and code are worded both beside the rule and in an enclosing object's messages, the outermost wins, and lint warns about the one that never shows.

Your application can give every schema its own wording, as the JavaScript SDK shows. In an application with translations, a message can be a key for your translation system rather than text, as Rendering forms shows.

Issues

An email address typed twice must match. An object carries issues for checks like this, each reporting an issue when its conditions match. Add the second field, then an issue that compares the two:

schemas/signUp.yml
# ...
properties:
email:
type: string
pattern: ^[^@\s]+@[^@\s]+$
confirmEmail:
type: string
# ...
required:
- email
- confirmEmail
- displayName
- country
issues:
- key: emailsDiffer
conditions:
- input: confirmEmail
operator: notEquals
valueFrom:
input: email
path: confirmEmail
message: The email addresses do not match
# ...
properties:
email:
type: string
pattern: ^[^@\s]+@[^@\s]+$
confirmEmail:
type: string
# ...
required:
- email
- confirmEmail
- displayName
- country
issues:
- key: emailsDiffer
conditions: input('confirmEmail') != input('email')
path: confirmEmail
message: The email addresses do not match

input reads a field of the value being validated, by its path from the node the issue sits on, such as confirmEmail here or address.country for a nested object. It takes the operators an attribute takes, and lint checks its values and regexFlags as it does an attribute's, with the stricter pattern rules of a schema. Only a schema's issues and mutations accept it, since everywhere else the context already carries what is known.

valueFrom takes the other side of a comparison from another field of the same node, in place of value. A condition has one of the two, never both. Versions read from two fields compare with the version operators, such as semverGreaterThan, and a pattern is never read from a field, since a pattern a user typed is one nobody reviewed, so matches and notMatches take no valueFrom.

FieldRequiredDescription
keyYesUnique in the schema, in the issue's params.refine
conditionsYesWhen the value fails
pathNoThe field the issue belongs to
messageUnless it nestsWhat the issue says, as a template
issuesNoEntries nested under it, which report only when both match
descriptionNoNotes for your team

Everywhere else, conditions say when something applies. Here what applies is an issue, so write the failure: notEquals for two fields that must agree. A sign up whose confirmEmail is [email protected] reports The email addresses do not match at confirmEmail, with code: refine and params: { refine: emailsDiffer }.

An entry runs after the object's own rules. It waits while a field it compares has an issue of shape, at its path or in a field its conditions read, since such a value cannot be compared:

  • a missing required field, or a key the object does not allow
  • a value of the wrong type, outside its enum or const, or matching no oneOf branch or more than one
  • a referenced schema the datafile does not have
  • text its format does not accept, so an entry comparing a checkOut with after waits for a timestamp

Without confirmEmail, only required reports. A missing display name or a one letter one holds nothing back, so it and two different emails both report. An entry without a path waits for the whole object, as a check in code at the root does.

Conditions take every kind of condition, so an entry meant for some users lists theirs beside the comparison, such as the netherlands segment. A user outside the Netherlands never gets it, and neither does a context without a country.

Several entries for the same users nest under one that names them. A display name shows beside reviews, so a check that it is not the email address starts with Dutch sign ups:

schemas/signUp.yml
# ...
issues:
# ...
- key: dutchPilot
description: Checks we try in the Netherlands first
conditions: netherlands
issues:
- key: nameIsEmail
description: Display names show beside reviews
conditions:
- input: displayName
operator: equals
valueFrom:
input: email
path: displayName
message: Choose a name other than your email address
# ...
issues:
# ...
- key: dutchPilot
description: Checks we try in the Netherlands first
conditions: netherlands
issues:
- key: nameIsEmail
description: Display names show beside reviews
conditions: input('displayName') == input('email')
path: displayName
message: Choose a name other than your email address

dutchPilot has no message, so it only groups, and nameIsEmail reports only when both match. With country: nl in the context, a display name of [email protected] beside the same email reports Choose a name other than your email address at displayName, with params: { refine: nameIsEmail }. Each description is a note for your team, and never reaches a datafile.

Checks that need your application, such as whether a username is free, are checks in code.

Mutations

A schema's rules can depend on who is asking and what was typed: a tax ID that only businesses give, longer names for paying accounts, a stricter rule rolled out to a share of users first. Where an issue reports a value that fails, a mutation changes the rules themselves under conditions, in the notation of Mutations. These steps add each of them to signUp.

Change a rule

A business account must give a tax ID, and a personal one need not. Add the two fields, then a mutation that changes the rules when the value says it is a business:

schemas/signUp.yml
# ...
properties:
# ...
accountType:
type: string
enum: [personal, business]
taxId:
type: string
required:
- email
- confirmEmail
- displayName
- country
- accountType
mutations:
- key: business
conditions:
- input: accountType
operator: equals
value: business
mutate:
required:appendUnique: taxId
# ...
properties:
# ...
accountType:
type: string
enum: [personal, business]
taxId:
type: string
required:
- email
- confirmEmail
- displayName
- country
- accountType
mutations:
- key: business
conditions: input('accountType') == 'business'
mutate:
required:appendUnique: taxId

A mutation has these fields:

FieldRequiredDescription
keyYesUnique in the schema, and named by the issues it causes
conditionsYesWhen it applies, as conditions
mutateUnless it nestsThe changes, in the notation of mutations
mutationsNoMutations nested under it
descriptionNoNotes for your team, never in a datafile

input reads accountType from the value being validated, as it reads the two emails in Issues.

required:appendUnique: taxId adds a key to required once, and properties.taxId.pattern would set one field's rule, with paths into the schema itself. Every mutation whose conditions match applies when a value is validated, in the order listed:

accountTypetaxIdIssues
personalmissingNone
businessmissingrequired at taxId, mutation: business

An issue that a mutation caused names it in mutation, so a form or a log can say why a field became required.

Nest mutations

Dutch and German businesses each give their own country's tax ID. Mutations nested under business check only once it matches, and apply after its change:

schemas/signUp.yml
# ...
mutations:
- key: business
conditions:
- input: accountType
operator: equals
value: business
mutate:
required:appendUnique: taxId
mutations:
- key: dutchBusiness
conditions:
- input: country
operator: equals
value: nl
mutate:
properties.taxId.pattern: ^NL[0-9]{9}B[0-9]{2}$
properties.taxId.messages:
pattern: Enter a Dutch VAT number
- key: germanBusiness
conditions:
- input: country
operator: equals
value: de
mutate:
properties.taxId.pattern: ^DE[0-9]{9}$
properties.taxId.messages:
pattern: Enter a German VAT number
# ...
mutations:
- key: business
conditions: input('accountType') == 'business'
mutate:
required:appendUnique: taxId
mutations:
- key: dutchBusiness
conditions: input('country') == 'nl'
mutate:
properties.taxId.pattern: ^NL[0-9]{9}B[0-9]{2}$
properties.taxId.messages:
pattern: Enter a Dutch VAT number
- key: germanBusiness
conditions: input('country') == 'de'
mutate:
properties.taxId.pattern: ^DE[0-9]{9}$
properties.taxId.messages:
pattern: Enter a German VAT number

A business now gives a tax ID in its own country's shape, with its own message:

countrytaxIdIssues
nlNL123456789B01None
nlDE123456789pattern at taxId, mutation: dutchBusiness
deDE123456789None
  • A child applies only when its parent does, after the parent's change, so it can change what its parent adds.
  • A parent without mutate only groups, and its children share its conditions without repeating them.
  • Keys are unique across the whole tree, since an issue names the mutation that set its rule.
  • A mutation can set a field's messages, so the wording follows the rule.

Change each row of a list

A mutation can sit on any node, beside the fields it changes, and its input paths start from that node. In a list's items, it checks each row on its own. An invite to an admin needs a name:

schemas/signUp.yml
# ...
properties:
# ...
invites:
type: array
items:
type: object
properties:
email:
type: string
name:
type: string
admin:
type: boolean
required: [email]
mutations:
- key: adminInvite
conditions:
- input: admin
operator: equals
value: true
mutate:
required:appendUnique: name
# ...
properties:
# ...
invites:
type: array
items:
type: object
properties:
email:
type: string
name:
type: string
admin:
type: boolean
required: [email]
mutations:
- key: adminInvite
conditions: input('admin') == true
mutate:
required:appendUnique: name
invitesIssues
[{ email: 'user-2@example.com' }]None
[{ email: 'user-2@example.com' }, { email: 'user-3@example.com', admin: true }]required at invites.1.name, mutation: adminInvite
  • input: admin reads the row's own admin field. A mutation in items sees nothing past its row, so input: country there names no field.
  • A mutation at the root changes every row alike, through items in its paths, such as properties.invites.items.properties.email.pattern.
  • No mutation changes mutations or issues, so each sits on the node whose fields its conditions read.
  • reads, the fields a form watches, names a row's field as invites[].admin, for every row. Rendering forms shows a form that follows it.

Read the context

Conditions are the ones features use, so a segment means the same in a schema as in a flag. payingAccounts from Segments gives paying accounts display names of up to 80 characters:

schemas/signUp.yml
# ...
mutations:
# ...
- key: longerNames
description: Room for a company name
conditions: payingAccounts
mutate:
properties.displayName.maxLength: 80

description says why, for your team, as on an issue. The context is the SDK instance's, with any you give to the call merged over it, as it is for isEnabled:

const context = {
plan: 'paid',
}
s.validate('signUp', value, context)
planA name of 60 characters
freemaxLength, up to 40
paidValid

Roll out a stricter rule

A rule that turns people away deserves a gradual rollout. A feature condition applies a mutation to the users a flag is enabled for, so it rolls out by percentage like any change. strictNames starts with a quarter of users:

features/strictNames.yml
description: Display names of letters and spaces only
bucketBy: userId
rules:
- key: everyone
conditions: "*"
percentage: 25
schemas/signUp.yml
# ...
mutations:
# ...
- key: strictNames
conditions:
- feature: strictNames
mutate:
properties.displayName.pattern: ^[A-Za-z ]+$
# ...
mutations:
# ...
- key: strictNames
conditions: feature('strictNames')
mutate:
properties.displayName.pattern: ^[A-Za-z ]+$

A display name of Ada 2 now fails for the users in the rollout:

UserBucketAda 2
user-141.9Valid
user-285.4Valid
user-40.4pattern, mutation: strictNames

The flag buckets as it does for isEnabled, so give the context its userId. Without one, every context shares the bucket 2.8, as Bucketing explains, so at 25% every anonymous sign up gets the stricter rule.

The flag comes along into every datafile that delivers the schema, with its own conditions and whatever they read, as a feature's dependencies do, so no target has to select it. Raise its percentage to reach more users, with no change to the schema.

Relax a rule fast

A global variable switches a rule off for everyone at once. taxIdOptional lets businesses sign up without a tax ID, for when the step costs more sign ups than it is worth:

variables/taxIdOptional.yml
description: Lets businesses sign up without a tax ID
type: boolean
defaultValue: false
schemas/signUp.yml
# ...
mutations:
# ...
- key: taxIdOptional
conditions:
- variable: taxIdOptional
operator: equals
value: true
mutate:
required:removeValue: taxId
# ...
mutations:
# ...
- key: taxIdOptional
conditions: variable('taxIdOptional') == true
mutate:
required:removeValue: taxId

Mutations apply in the order listed, so taxIdOptional removes what business added. Listed before business, it would remove nothing. Turn it on with an override, and every application has it at its next datafile:

variables/taxIdOptional.yml
# ...
overrides:
- key: incident
conditions: "*"
value: true

Removing the override ends it. The variable comes along into the datafile with the schema, as the flag does.

Change per environment

In a project with environments, a schema's root lists its mutations per environment, so a rule can reach staging a pull request before production. Environments shows how.

Test the rules

With every rule above, schemas/signUp.yml reads:

schemas/signUp.yml
description: A sign up form
tags:
- web
type: object
properties:
email:
type: string
pattern: ^[^@\s]+@[^@\s]+$
confirmEmail:
type: string
displayName:
type: string
minLength: 2
maxLength: 40
country:
type: string
enum: [nl, de]
accountType:
type: string
enum: [personal, business]
taxId:
type: string
invites:
type: array
items:
type: object
properties:
email:
type: string
name:
type: string
admin:
type: boolean
required: [email]
mutations:
- key: adminInvite
conditions:
- input: admin
operator: equals
value: true
mutate:
required:appendUnique: name
required:
- email
- confirmEmail
- displayName
- country
- accountType
mutations:
- key: business
conditions:
- input: accountType
operator: equals
value: business
mutate:
required:appendUnique: taxId
mutations:
- key: dutchBusiness
conditions:
- input: country
operator: equals
value: nl
mutate:
properties.taxId.pattern: ^NL[0-9]{9}B[0-9]{2}$
properties.taxId.messages:
pattern: Enter a Dutch VAT number
- key: germanBusiness
conditions:
- input: country
operator: equals
value: de
mutate:
properties.taxId.pattern: ^DE[0-9]{9}$
properties.taxId.messages:
pattern: Enter a German VAT number
- key: longerNames
description: Room for a company name
conditions: payingAccounts
mutate:
properties.displayName.maxLength: 80
- key: strictNames
conditions:
- feature: strictNames
mutate:
properties.displayName.pattern: ^[A-Za-z ]+$
- key: taxIdOptional
conditions:
- variable: taxIdOptional
operator: equals
value: true
mutate:
required:removeValue: taxId
issues:
- key: emailsDiffer
conditions:
- input: confirmEmail
operator: notEquals
valueFrom:
input: email
path: confirmEmail
message: The email addresses do not match
- key: dutchPilot
description: Checks we try in the Netherlands first
conditions: netherlands
issues:
- key: nameIsEmail
description: Display names show beside reviews
conditions:
- input: displayName
operator: equals
valueFrom:
input: email
path: displayName
message: Choose a name other than your email address
description: A sign up form
tags:
- web
type: object
properties:
email:
type: string
pattern: ^[^@\s]+@[^@\s]+$
confirmEmail:
type: string
displayName:
type: string
minLength: 2
maxLength: 40
country:
type: string
enum: [nl, de]
accountType:
type: string
enum: [personal, business]
taxId:
type: string
invites:
type: array
items:
type: object
properties:
email:
type: string
name:
type: string
admin:
type: boolean
required: [email]
mutations:
- key: adminInvite
conditions: input('admin') == true
mutate:
required:appendUnique: name
required:
- email
- confirmEmail
- displayName
- country
- accountType
mutations:
- key: business
conditions: input('accountType') == 'business'
mutate:
required:appendUnique: taxId
mutations:
- key: dutchBusiness
conditions: input('country') == 'nl'
mutate:
properties.taxId.pattern: ^NL[0-9]{9}B[0-9]{2}$
properties.taxId.messages:
pattern: Enter a Dutch VAT number
- key: germanBusiness
conditions: input('country') == 'de'
mutate:
properties.taxId.pattern: ^DE[0-9]{9}$
properties.taxId.messages:
pattern: Enter a German VAT number
- key: longerNames
description: Room for a company name
conditions: payingAccounts
mutate:
properties.displayName.maxLength: 80
- key: strictNames
conditions: feature('strictNames')
mutate:
properties.displayName.pattern: ^[A-Za-z ]+$
- key: taxIdOptional
conditions: variable('taxIdOptional') == true
mutate:
required:removeValue: taxId
issues:
- key: emailsDiffer
conditions: input('confirmEmail') != input('email')
path: confirmEmail
message: The email addresses do not match
- key: dutchPilot
description: Checks we try in the Netherlands first
conditions: netherlands
issues:
- key: nameIsEmail
description: Display names show beside reviews
conditions: input('displayName') == input('email')
path: displayName
message: Choose a name other than your email address

A spec checks the rules with a context, as a feature spec does, and an expected issue matches by the fields it gives, such as mutation or params:

tests/schemas/signUp.spec.yml
schema: signUp
assertions:
- description: A Dutch business gives a Dutch tax ID
context:
userId: user-1
value:
email: user-[email protected]
confirmEmail: user-[email protected]
displayName: Ada
country: nl
accountType: business
taxId: DE123456789
expectedIssues:
- path: [taxId]
code: pattern
mutation: dutchBusiness
- description: Paying accounts get longer names
context:
userId: user-1
plan: paid
value:
email: user-[email protected]
confirmEmail: user-[email protected]
displayName: Augusta Ada King, Countess of Lovelace, Mathematician
country: nl
accountType: personal
expectedToBeValid: true
- description: The stricter names reach user-4
context:
userId: user-4
value:
email: user-[email protected]
confirmEmail: user-[email protected]
displayName: Ada 2
country: nl
accountType: personal
expectedIssues:
- path: [displayName]
code: pattern
mutation: strictNames
- description: An admin invite needs a name
context:
userId: user-1
value:
email: user-[email protected]
confirmEmail: user-[email protected]
displayName: Ada
country: nl
accountType: personal
invites:
- email: user-[email protected]
- email: user-[email protected]
admin: true
expectedIssues:
- path: [invites, 1, name]
code: required
mutation: adminInvite
- description: The email addresses must match
context:
userId: user-1
value:
email: user-[email protected]
confirmEmail: user-[email protected]
displayName: Ada
country: nl
accountType: personal
expectedIssues:
- path: [confirmEmail]
params:
refine: emailsDiffer
- description: Dutch display names are not email addresses
context:
userId: user-1
country: nl
value:
email: user-[email protected]
confirmEmail: user-[email protected]
displayName: user-[email protected]
country: nl
accountType: personal
expectedIssues:
- path: [displayName]
params:
refine: nameIsEmail

Testing covers schema specs in full.

Annotations

Annotations carry what a form needs beside a schema's rules: a title for each field, a placeholder, help text, the order fields come in and labels for choices. Validation never reads them, so these steps change what signUp says to people without changing what it accepts.

A form reads them from the schema's handle, the object your code holds for one schema: const signUp = s.get('signUp'). signUp.withInput(values) is the same handle for the values typed so far, with the mutations that match them and the context applied. Rendering forms renders a whole form from it.

Title the fields

annotations sit beside a node's rules. A title names a field for the people filling in the form:

schemas/signUp.yml
# ...
properties:
email:
type: string
pattern: ^[^@\s]+@[^@\s]+$
annotations:
title: Email address
displayName:
type: string
minLength: 2
maxLength: 40
annotations:
title: Display name
examples: [Ada, Grace Hopper]
country:
type: string
enum: [nl, de]
annotations:
title: Country
# ...

Every issue about a field with a title carries it in params.title, so one message can word every form. A {title} in a message such as {title} needs at least {minLength} characters reads Display name needs at least 2 characters.

Five annotations are built in, since Featurevisor uses them itself. Every schema file takes them, and no project can give them another meaning:

AnnotationMust beUsed for
titleTextparams.title on the field's issues
defaultA value that passes the field's own rulesThe value a form starts the field with
examplesA list of values that pass the field's own rulesLint only, and your placeholders or docs
orderA list of an object's field names, each onceThe order of its fields
optionsA map beside an enum, keyed by its valuesLabels and fields for its choices

Help text for the people filling in a form is an annotation of your own, below, since description never reaches a datafile.

Start a field with a value

default is the value a form starts a field with, such as the country most people choose:

schemas/signUp.yml
# ...
properties:
# ...
country:
type: string
enum: [nl, de]
annotations:
title: Country
default: nl

A form reads it as signUp.field('country').annotations.default, 'nl', and starts its select there. Lint checks the default against the field's rules, so default: be fails with Default be does not pass the field's own rules. Validation never fills it in, so a request without a country still reports Value at "country" is required.

A mutation can change a default as it changes any annotation, such as for people in Germany:

schemas/signUp.yml
# ...
mutations:
# ...
- key: germanDefault
conditions:
- attribute: country
operator: equals
value: de
mutate:
properties.country.annotations.default: de
# ...
mutations:
# ...
- key: germanDefault
conditions: country == 'de'
mutate:
properties.country.annotations.default: de

With country: de in the context, signUp.withInput({}).field('country').annotations.default is 'de', while a handle without withInput keeps the default as written. Lint checks a default again with each mutation applied, so one that narrows the enum past the default fails too.

Order the fields

order at an object's root lists its fields in the order a form shows them:

schemas/signUp.yml
# ...
annotations:
title: Create your account
order: [displayName, email, country]

A form that renders from the schema now asks for the display name first. Fields the list leaves out come after it in name order, by Unicode code point, the same in every SDK. Order is a list rather than the order keys are written in, since JavaScript, Go and Swift each read an object's keys in their own order, and formatting tools can reorder keys without anyone meaning to change a form.

Order nested fields

Every object has its own order. A postal address that signUp references lists its fields its own way, wherever it is used:

schemas/address.yml
description: A postal address
type: object
properties:
country:
type: string
enum: [nl, de]
street:
type: string
postcode:
type: string
city:
type: string
required: [country, street, postcode, city]
annotations:
order: [country, street, postcode, city]
schemas/signUp.yml
# ...
properties:
# ...
address:
schema: address

signUp.field('address').fields gives the country, street, postcode and city in that order, and a form renders them as a fieldset of their own. An order beside the reference, such as billingAddress: { schema: address, annotations: { order: [country, city, postcode, street] } }, orders that use alone, as other annotations beside a reference do. A list's rows order the same way, with order in its items, so every row from field('invites.0') follows it.

Change the order by condition

A Dutch address is found from its postcode, so a form asks for it first. A mutation can replace annotations.order like any rule:

schemas/address.yml
# ...
mutations:
- key: postcodeFirst
conditions:
- input: country
operator: equals
value: nl
mutate:
annotations.order: [country, postcode, street, city]
# ...
mutations:
- key: postcodeFirst
conditions: input('country') == 'nl'
mutate:
annotations.order: [country, postcode, street, city]

Once the Netherlands is chosen, signUp.withInput(values).field('address').fields lists the postcode before the street, and a German address keeps its own order. Validation never reads annotations, so the mutation changes what people see and never what passes. An order beside a reference stays whatever the referenced schema's mutations do.

Add your own annotations

Featurevisor ships no form vocabulary of its own, so nothing locks your project into one shape. annotationsSchema at a schema's root names what else its annotations can hold: an object schema, inline or referenced by key, whose properties are the annotation names:

schemas/formAnnotations.yml
description: What our forms say about a form and its fields
type: object
properties:
placeholder:
type: string
help:
type: string
input:
type: string
enum: [text, email, password, select, checkbox]
autocomplete:
type: string
hidden:
type: boolean
submitLabel:
type: string
schemas/signUp.yml
description: A sign up form
tags:
- web
annotationsSchema:
schema: formAnnotations
type: object
properties:
email:
type: string
pattern: ^[^@\s]+@[^@\s]+$
annotations:
title: Email address
placeholder: user-[email protected]
input: email
autocomplete: email
help: We send a link to confirm it
# ...
annotations:
title: Create your account
submitLabel: Sign up
order: [displayName, email, country]
  • Closed, so typos fail. placeholdr fails lint with Unknown annotation `placeholdr`. `annotationsSchema` declares `placeholder`, `help`, .... A vocabulary that should stay open says additionalProperties: true.
  • Every node in the file. The vocabulary covers the root and every field the file describes. A referenced schema uses its own, so one form can mix vocabularies, and a schema without one carries only the built in annotations.
  • Optional unless you say so. A name the vocabulary lists in required must be on the schema and on every field a form can reach in the file, so required: [help] fails lint for any field without help text, with `annotationsSchema` requires `help`, which this node does not have.
  • Never in a datafile. Lint checks every annotation against the vocabulary, so only the annotations travel. A vocabulary can never declare the built in names.

Web forms, mobile forms and a back office can each have their own vocabulary, and a schema that only checks API requests needs none.

Label the choices

A choice needs more than its value. The built in options annotation, beside an enum, gives each value a title:

schemas/signUp.yml
# ...
properties:
# ...
country:
type: string
enum: [nl, de]
annotations:
title: Country
input: select
options:
nl:
title: Netherlands
de:
title: Germany

A form lists the choices in the order of the enum, never of the map, and when every choice has a title, an enum issue names them, since those are what a person picks from:

Message
Value at "country" must be one of Netherlands, Germany.

A value without an entry is a choice like any other. Lint warns with option_without_title when some choices have a title and others do not, since a list would show titles beside raw values, and fails a key that is not one of the enum's values.

Give choices their own fields

A country choice can carry a flag and a region, as a plan can carry a price. An optionSchema sits with the choices, where options goes, and names what each choice holds other than its title, as annotationsSchema does for fields:

schemas/countryOption.yml
description: What a country choice carries
type: object
properties:
flag:
type: string
region:
type: string
enum: [benelux, dach]
hidden:
type: boolean
schemas/signUp.yml
# ...
properties:
# ...
country:
type: string
enum: [nl, de, be]
optionSchema:
schema: countryOption
annotations:
title: Country
input: select
options:
nl:
title: Netherlands
flag: nl
region: benelux
de:
title: Germany
flag: de
region: dach
be:
title: Belgium
hidden: true

Belgium is accepted, so a back office can open Belgian accounts before launch, and the hidden field of your vocabulary keeps it out of the public form until then. Featurevisor filters nothing and computes no label: hidden choices, groups, icons and prices are your vocabulary's, and a title can be text or a key for your own translations.

hidden changes only what a form shows. The web app's datafile lists Belgium for anyone who reads it, and its sign up accepts be from anyone who sends it. Removing be from the enum is what stops validation accepting it.

Each list of choices names its own optionSchema, and nothing inherits one:

  • A list without one carries titles only.
  • A plan beside the country can carry a price and no flag, and required: [price] in its vocabulary asks nothing of countries.
  • A multiple select puts it in the array's items, beside the enum, and a nullable list on the branch that holds the enum.
  • A shared list, such as country, keeps it at its root, and every field that references the list follows it. Lint rejects an optionSchema anywhere else, beside a schema reference too.
  • A choice holds only value, title and your fields, so optionSchema cannot declare title or value. Like every vocabulary, it never reaches a datafile, and generated types type each list's choices by their own.

Share a list of choices

A list such as country is a schema of its own, so every form that needs it references it. Move it into a file of its own, with its vocabulary at its root:

schemas/country.yml
description: Countries we sell to
optionSchema:
schema: countryOption
type: string
enum: [nl, de, be]
annotations:
options:
nl:
title: Netherlands
flag: nl
region: benelux
de:
title: Germany
flag: de
region: dach
be:
title: Belgium
hidden: true

Each form references it, with its own title beside the reference:

schemas/signUp.yml
# ...
properties:
# ...
country:
schema: country
annotations:
title: Country
input: select
billingCountry:
schema: country
annotations:
title: Billing country

Annotations beside a reference apply to that use only, over the referenced schema's own. One select component then serves every form that references country, and adding a country is one pull request.

Write choices as constants

The same list can be a oneOf of const branches, each with its own annotations, the way JSON Schema labels values. It suits choices that come and go with their wording, and a labelled null:

schemas/country.yml
description: Countries we sell to
optionSchema:
schema: countryOption
oneOf:
- const: nl
annotations:
title: Netherlands
flag: nl
region: benelux
- const: de
annotations:
title: Germany
flag: de
region: dach
- const: be
annotations:
title: Belgium
hidden: true
- const: null
annotations:
title: Prefer not to say

A value it does not list reports enum, as an enum does, and lint rejects a value given twice.

Leave them out of a backend

A target that serves only a backend, which validates but renders nothing, leaves annotations out with includeAnnotations: false, which keeps its datafiles small:

targets/api.yml
description: Our API
tag: web
includeAnnotations: false

Its applications validate the same, since validation never reads annotations. Their issues carry no titles, and with no order to follow, a handle's fields come in name order. A message with {title} reads without it there, so word a backend's messages without titles. Targets lists the other ways a target selects schemas.

Metadata

A reusable schema can have metadata at its top level, such as an owner, and never in a schema nested inside it. Metadata describes the definition, and is never part of the schema it defines.

Promotable

In a project that uses sets, a reusable schema can protect its existing destination definition from later promotions by setting promotable: false at the top level:

sets/production/schemas/notice.yml
description: A notice shown to users
promotable: false
type: object
properties:
id:
type: string
label:
type: string
message:
type: string

If the destination schema exists, it remains unchanged when either the source or destination schema has this field. A missing destination schema is still created and retains promotable: false. The field protects the whole file, so it cannot go inside properties, items or oneOf.

Lint and generate types

npx featurevisor lint checks every default, override and mutation against its schema, including referenced schemas, and every schema's own messages, mutations, issues and annotations. Code generation turns reusable schemas into named types for your application. allowedConditions can keep schema rules to segments and input.

Details

How values are checked

Validation in an application applies exactly the rules lint applies to variable values:

  • It never changes a value. It fills no defaults, coerces nothing and strips no keys, and reports every issue it finds at once.
  • An object is a plain object, as JSON has. A Date, a File or a class instance is not one.
  • A number that is not finite fails, and a key whose value is undefined counts as missing.
  • required applies with or without properties, so an object with only additionalProperties and required: [en-GB] must have an en-GB key.
  • When each branch of a oneOf takes a different type, the value's type picks the branch, so a nullable name that is too long reports maxLength rather than a oneOf issue.
  • A schema the datafile does not have fails closed, with a schemaNotFound issue, so a target that forgot to deliver one is noticed rather than letting everything through.
  • A datafile that lint never checked fails closed too. A pattern that does not compile fails every value with a pattern issue and a schema_pattern_unsupported diagnostic. A mutation that cannot be applied fails the value with refineError and a schema_mutation_error diagnostic.
  • A schema that references itself can nest at most 128 references deep in a value. A value nested deeper fails with refineError, and the SDK reports schema_reference_depth.
  • A check in code or a lookup that throws fails closed too, with refineError and a schema_check_error diagnostic.
  • -0 equals 0, and numbers compare as JavaScript reads them, so 9007199254740993 equals 9007199254740992.
  • A pattern a target delivers keeps to what every SDK reads alike. It has no lookaround and no named, noncapturing, atomic or inline mode groups, so ^(?:NL|DE)[0-9]+$ fails lint where ^(NL|DE)[0-9]+$ passes. It has no backreferences, possessive quantifiers or word boundaries, no Unicode properties, no \u, \c or \0 escapes, no [] or [^], and no characters beyond U+FFFF, such as emoji. $, . and \s mean in every SDK what they mean in JavaScript.
  • Applications test untrusted input against a delivered pattern, so lint checks it for backtracking more strictly than an attribute condition's. It fails a nested quantifier under an unbounded repeat, such as ^(a+)+$ or ^(a{1,3})+$, and alternatives that overlap, such as ^(a|b|ab)*c$, and names the targets that deliver it, as Targets explains. A pattern in matches on an input leaf is checked the same way.

Mutations and issues

  • What a form sees. A handle's constraints, choices and annotations describe the schema's own rules, which no condition changes. Validation applies the mutations, and the JavaScript SDK shows how a form follows the rules that apply to what was typed so far.
  • In datafiles. Mutations are compiled, so applications parse no notation, and nested ones are carried flat, each after its parent with the conditions of both. A condition that cannot be answered reports an evaluation_error diagnostic and does not match.
  • What counts as a change. A schema's hash covers its rules and the segments, flags and global variables its conditions read, so subscribe and the React hooks follow a datafile that changes payingAccounts or rolls out strictNames, as well as one that changes the schema.
  • Lint. It checks that each key is unique, each input and valueFrom names a field of its node and each operator suits the field compared, so greaterThan on accountType, a string, fails. The schema must stay valid with each mutation alone and with all of them together, a mutation never changes a node's type, every path in mutate must reach into the schema, since a mutation creates no objects on the way, and no mutation changes mutations or issues. A message for the type code, or a field named type, is not a node's type, so a mutation may write them. The annotations a mutation writes are checked against the file's vocabularies, as written ones are. issues go on objects only, and an entry with a message reads at least one input.

Annotations

  • Where annotations go. At a schema's root, on any field, in items, in a oneOf branch and beside a schema reference. They are never keyed by field at the object level, as messages are, since a field named title would meet the title annotation.
  • Keys of options are the values themselves, or for a value that is not text, its JSON text, such as 1, true or null. Lint rejects a key that names no value.
  • Delivery. Datafiles carry annotations inside each schema, and a schema's hash covers them, so a change of wording reaches applications at their next datafile.
  • Wrong annotations from elsewhere. A datafile Featurevisor did not build may hold annotations lint would reject. Applications then use what they can and ignore the rest, so an order that is not a list leaves the fields in name order rather than failing.
  • Catalog shows a schema's annotations on its Overview, each field's beside its rules, with its choices as labelled chips.
Previous
Mutations