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:
description: Checkout settingstype: objectproperties: currency: type: string paymentMethods: type: array items: type: stringrequired: [currency, paymentMethods]defaultValue: currency: EUR paymentMethods: [card]propertieslists an object's keys, each with its own schema. Objects can nest.requiredlists the keys that must be present. As in JSON Schema, any key it does not list is optional, so withoutrequiredevery key is. In an object that allows no other keys, lint checks that each key it lists is one ofproperties, so a misspeltemialfails.itemsdescribes every element of an array. Without it, a variable's array holds strings, and a schema inschemas/must have it.- An object without
propertiesaccepts a flat object of strings, numbers, booleans andnull.
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 as2024, 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.
| Keyword | Applies to | Requires |
|---|---|---|
enum | Any type | One of the listed values |
const | Any type | Exactly this value |
minimum, maximum | integer, number | A number in range |
minLength, maxLength | string | A length in range |
pattern | string | A match for a regular expression |
format | string | A timestamp or a comparable version |
minItems, maxItems | array | A number of items in range |
uniqueItems | array | No duplicate items |
Limit checkoutSettings to two currencies and at least one distinct payment method:
# ...type: objectproperties: currency: type: string enum: [EUR, GBP] paymentMethods: type: array minItems: 1 uniqueItems: true items: type: stringAn 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:
description: Checkout launch instanttype: stringformat: date-timedefaultValue: "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:
description: Oldest app version that gets the new checkouttype: stringformat: semverdefaultValue: 5.5.0Lint 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:
description: A notice shown to userstype: objectproperties: id: type: string label: type: string message: type: stringrequired: [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:
description: Shown while pausedschema: noticedefaultValue: id: maintenance label: Maintenance message: Checkout is back shortlyA feature variable references it the same way:
# ...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:
description: A list of noticestype: arrayitems: schema: noticecheckoutNotices from Mutations can now describe its items by name:
description: Notices shown during checkouttype: objectproperties: items: schema: noticesrequired: [items]defaultValue: items: - id: base label: Base message: Standard noticeA 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.

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:
description: ID from several systemsoneOf: - type: string - type: integerdefaultValue: anonymousGive 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:
description: Pay button label per localetype: objectadditionalProperties: type: stringdefaultValue: en-GB: Pay now nl-NL: Nu betalenadditionalProperties 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:
description: Payment provider configtype: jsondefaultValue: '{"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:
module.exports = { tags: ['web', 'mobile'],}Give the schema that tag:
description: A sign up formtags: - webtype: objectproperties: 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:
description: Web apptag: webNothing 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:
schema: signUpassertions: - description: A complete sign up passes value: displayName: Ada country: nl expectedToBeValid: true - description: A one letter name is too short value: displayName: A country: nl expectedIssues: - path: [displayName] code: minLengthTesting lists what a schema spec can check. Lint, test and build as you do for flags:
npx featurevisor lintnpx featurevisor testnpx featurevisor builddatafiles/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:
| Field | In a datafile | Explained in |
|---|---|---|
description, metadata, promotable | No | Metadata, Promotable |
tags | No, it selects targets | This section |
The rules, such as type | Yes | Describe a value |
messages | Yes | Word the issues |
issues, mutations | Yes, compiled | Issues, Mutations |
annotations | Unless includeAnnotations: false | Annotations |
annotationsSchema | No | Add your own annotations |
optionSchema | No | Give 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:
# ...required: [email, displayName, country]messages: email: required: Tell us your email address displayName: minLength: Use at least {minLength} charactersA 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
messagesbeside 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:
# ...properties: email: type: string pattern: ^[^@\s]+@[^@\s]+$ confirmEmail: type: string # ...required: - email - confirmEmail - displayName - countryissues: - 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 - countryissues: - key: emailsDiffer conditions: input('confirmEmail') != input('email') path: confirmEmail message: The email addresses do not matchinput 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.
| Field | Required | Description |
|---|---|---|
key | Yes | Unique in the schema, in the issue's params.refine |
conditions | Yes | When the value fails |
path | No | The field the issue belongs to |
message | Unless it nests | What the issue says, as a template |
issues | No | Entries nested under it, which report only when both match |
description | No | Notes 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
enumorconst, or matching nooneOfbranch or more than one - a referenced schema the datafile does not have
- text its
formatdoes not accept, so an entry comparing acheckOutwithafterwaits 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:
# ...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 addressdutchPilot 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:
# ...properties: # ... accountType: type: string enum: [personal, business] taxId: type: stringrequired: - email - confirmEmail - displayName - country - accountTypemutations: - key: business conditions: - input: accountType operator: equals value: business mutate: required:appendUnique: taxId# ...properties: # ... accountType: type: string enum: [personal, business] taxId: type: stringrequired: - email - confirmEmail - displayName - country - accountTypemutations: - key: business conditions: input('accountType') == 'business' mutate: required:appendUnique: taxIdA mutation has these fields:
| Field | Required | Description |
|---|---|---|
key | Yes | Unique in the schema, and named by the issues it causes |
conditions | Yes | When it applies, as conditions |
mutate | Unless it nests | The changes, in the notation of mutations |
mutations | No | Mutations nested under it |
description | No | Notes 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:
accountType | taxId | Issues |
|---|---|---|
personal | missing | None |
business | missing | required 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:
# ...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 numberA business now gives a tax ID in its own country's shape, with its own message:
country | taxId | Issues |
|---|---|---|
nl | NL123456789B01 | None |
nl | DE123456789 | pattern at taxId, mutation: dutchBusiness |
de | DE123456789 | None |
- A child applies only when its parent does, after the parent's change, so it can change what its parent adds.
- A parent without
mutateonly 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:
# ...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: nameinvites | Issues |
|---|---|
[{ 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: adminreads the row's ownadminfield. A mutation initemssees nothing past its row, soinput: countrythere names no field.- A mutation at the root changes every row alike, through
itemsin its paths, such asproperties.invites.items.properties.email.pattern. - No mutation changes
mutationsorissues, so each sits on the node whose fields its conditions read. reads, the fields a form watches, names a row's field asinvites[].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:
# ...mutations: # ... - key: longerNames description: Room for a company name conditions: payingAccounts mutate: properties.displayName.maxLength: 80description 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)plan | A name of 60 characters |
|---|---|
free | maxLength, up to 40 |
paid | Valid |
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:
description: Display names of letters and spaces onlybucketBy: userIdrules: - key: everyone conditions: "*" percentage: 25# ...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:
| User | Bucket | Ada 2 |
|---|---|---|
user-1 | 41.9 | Valid |
user-2 | 85.4 | Valid |
user-4 | 0.4 | pattern, 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:
description: Lets businesses sign up without a tax IDtype: booleandefaultValue: false# ...mutations: # ... - key: taxIdOptional conditions: - variable: taxIdOptional operator: equals value: true mutate: required:removeValue: taxId# ...mutations: # ... - key: taxIdOptional conditions: variable('taxIdOptional') == true mutate: required:removeValue: taxIdMutations 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:
# ...overrides: - key: incident conditions: "*" value: trueRemoving 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:
description: A sign up formtags: - webtype: objectproperties: 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: namerequired: - email - confirmEmail - displayName - country - accountTypemutations: - 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: taxIdissues: - 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 addressdescription: A sign up formtags: - webtype: objectproperties: 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: namerequired: - email - confirmEmail - displayName - country - accountTypemutations: - 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: taxIdissues: - 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 addressA 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:
schema: signUpassertions: - description: A Dutch business gives a Dutch tax ID context: userId: user-1 value: 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: 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: 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: displayName: Ada country: nl accountType: personal invites: admin: true expectedIssues: - path: [invites, 1, name] code: required mutation: adminInvite - description: The email addresses must match context: userId: user-1 value: 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: country: nl accountType: personal expectedIssues: - path: [displayName] params: refine: nameIsEmailTesting 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:
# ...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:
| Annotation | Must be | Used for |
|---|---|---|
title | Text | params.title on the field's issues |
default | A value that passes the field's own rules | The value a form starts the field with |
examples | A list of values that pass the field's own rules | Lint only, and your placeholders or docs |
order | A list of an object's field names, each once | The order of its fields |
options | A map beside an enum, keyed by its values | Labels 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:
# ...properties: # ... country: type: string enum: [nl, de] annotations: title: Country default: nlA 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:
# ...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: deWith 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:
# ...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:
description: A postal addresstype: objectproperties: country: type: string enum: [nl, de] street: type: string postcode: type: string city: type: stringrequired: [country, street, postcode, city]annotations: order: [country, street, postcode, city]# ...properties: # ... address: schema: addresssignUp.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:
# ...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:
description: What our forms say about a form and its fieldstype: objectproperties: placeholder: type: string help: type: string input: type: string enum: [text, email, password, select, checkbox] autocomplete: type: string hidden: type: boolean submitLabel: type: stringdescription: A sign up formtags: - webannotationsSchema: schema: formAnnotationstype: objectproperties: email: type: string pattern: ^[^@\s]+@[^@\s]+$ annotations: title: Email address 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.
placeholdrfails lint withUnknown annotation `placeholdr`. `annotationsSchema` declares `placeholder`, `help`, .... A vocabulary that should stay open saysadditionalProperties: 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
requiredmust be on the schema and on every field a form can reach in the file, sorequired: [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:
# ...properties: # ... country: type: string enum: [nl, de] annotations: title: Country input: select options: nl: title: Netherlands de: title: GermanyA 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:
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:
description: What a country choice carriestype: objectproperties: flag: type: string region: type: string enum: [benelux, dach] hidden: type: boolean# ...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: trueBelgium 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
planbeside the country can carry apriceand noflag, andrequired: [price]in its vocabulary asks nothing of countries. - A multiple select puts it in the array's
items, beside theenum, and a nullable list on the branch that holds theenum. - A shared list, such as
country, keeps it at its root, and every field that references the list follows it. Lint rejects anoptionSchemaanywhere else, beside aschemareference too. - A choice holds only
value,titleand your fields, sooptionSchemacannot declaretitleorvalue. 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:
description: Countries we sell tooptionSchema: schema: countryOptiontype: stringenum: [nl, de, be]annotations: options: nl: title: Netherlands flag: nl region: benelux de: title: Germany flag: de region: dach be: title: Belgium hidden: trueEach form references it, with its own title beside the reference:
# ...properties: # ... country: schema: country annotations: title: Country input: select billingCountry: schema: country annotations: title: Billing countryAnnotations 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:
description: Countries we sell tooptionSchema: schema: countryOptiononeOf: - 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 sayA 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:
description: Our APItag: webincludeAnnotations: falseIts 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:
description: A notice shown to userspromotable: falsetype: objectproperties: id: type: string label: type: string message: type: stringIf 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, aFileor a class instance is not one. - A number that is not finite fails, and a key whose value is
undefinedcounts as missing. requiredapplies with or withoutproperties, so an object with onlyadditionalPropertiesandrequired: [en-GB]must have anen-GBkey.- When each branch of a
oneOftakes a different type, the value's type picks the branch, so a nullable name that is too long reportsmaxLengthrather than aoneOfissue. - A schema the datafile does not have fails closed, with a
schemaNotFoundissue, 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
patternissue and aschema_pattern_unsupporteddiagnostic. A mutation that cannot be applied fails the value withrefineErrorand aschema_mutation_errordiagnostic. - 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 reportsschema_reference_depth. - A check in code or a lookup that throws fails closed too, with
refineErrorand aschema_check_errordiagnostic. -0equals0, and numbers compare as JavaScript reads them, so9007199254740993equals9007199254740992.- 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,\cor\0escapes, no[]or[^], and no characters beyond U+FFFF, such as emoji.$,.and\smean 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 inmatcheson aninputleaf 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_errordiagnostic and does not match. - What counts as a change. A schema's
hashcovers its rules and the segments, flags and global variables its conditions read, sosubscribeand the React hooks follow a datafile that changespayingAccountsor rolls outstrictNames, as well as one that changes the schema. - Lint. It checks that each key is unique, each
inputandvalueFromnames a field of its node and each operator suits the field compared, sogreaterThanonaccountType, a string, fails. The schema must stay valid with each mutation alone and with all of them together, a mutation never changes a node'stype, every path inmutatemust reach into the schema, since a mutation creates no objects on the way, and no mutation changesmutationsorissues. A message for thetypecode, or a field namedtype, is not a node'stype, so a mutation may write them. The annotations a mutation writes are checked against the file's vocabularies, as written ones are.issuesgo on objects only, and an entry with a message reads at least oneinput.
Annotations#
- Where annotations go. At a schema's root, on any field, in
items, in aoneOfbranch and beside aschemareference. They are never keyed by field at the object level, asmessagesare, since a field namedtitlewould meet thetitleannotation. - Keys of
optionsare the values themselves, or for a value that is not text, its JSON text, such as1,trueornull. Lint rejects a key that names no value. - Delivery. Datafiles carry annotations inside each schema, and a schema's
hashcovers 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
orderthat 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.

