Skip to main content

Primitives and types

Route/ade/dashboard/primitives

Primitives & types is the registry of reusable JSON Schema 2020-12 types — the money, address and identifier shapes your classes and properties point at with $ref. Go to Build → Primitives & types. It has four tabs: Registry, Namespaces & scopes, Resolver and Settings.

Types come from two scopes: core system types every tenant can use (read-only), and your tenant types.

Registry​

Primitives & types, Registry tab: the facts line under the header, then type collections, Recent activity and the types tablePrimitives & types, Registry tab: the facts line under the header, then type collections, Recent activity and the types table
Route/ade/dashboard/primitives

Under the header, one line sums up the registry: how many core system types, tenant types, imported schemas and properties bound, and how many unresolved $ref there are. When any reference is unresolved, that count is a red chip — click it to open the Resolver tab. Click “Show stats” to open the full statistics in place; Apiome remembers the choice in this browser.

Beside the type collections, Recent activity lists the last eight imports. The table lists each type's Name, Namespace, Category, Description, Usage and Type; search it, pick a category, and tick Show system to include the core types.

How resolution works​

Click “How resolution works” in the page description to see how a relative $ref is resolved: against the type's import-source base URL, with a worked example. Click “Open reference resolver” to go to the Resolver tab, or “Got it” to close it.

The How resolution works dialog: how a relative $ref resolves against the type's base URL, with a worked exampleThe How resolution works dialog: how a relative $ref resolves against the type's base URL, with a worked example
Route/ade/dashboard/primitives

Click a type to open its page:

A type's page: its JSON Schema, metadata, where it is used, and its base chainA type's page: its JSON Schema, metadata, where it is used, and its base chain
Route/ade/dashboard/primitives/[id]

The page shows the type's JSON Schema (2020-12) (Copy, Download), Test this type, Reference resolution, an Example instance, its Dependents and Used by properties; on the right, Metadata, Used in and Base chain. “Edit”, “Export” and “Deprecate” are in the header.

To check a payload against the type, open Test this type, choose Single or Array and type the value — it is validated as you type.

Test this type: a payload validated against the type, with the problems foundTest this type: a payload validated against the type, with the problems found
Route/ade/dashboard/primitives/[id]

See what uses a type​

Before you change a type, check what depends on it. Scroll down a type's page to two cards:

The Dependents table with three referencing types, and the Used by properties table with two bound class propertiesThe Dependents table with three referencing types, and the Used by properties table with two bound class properties
Route/ade/dashboard/primitives/[id]
  • Dependents has one row for each $ref from another type to this one: the referencing type (click it to open it), the Property the $ref sits on (a dash when the whole type is a reference), and its Scope — System · core or Tenant · your workspace. A type that references this one from two properties has two rows.
  • Used by properties has one row for each class property bound to this type — the ones whose Primitive you chose in the Designer: the property as Class.property (click it to open that version in the Designer; without Designer access it is plain text), its Project · Version, and the registry $ref it is Bound as.

Used by properties covers only your workspace's projects: a system type is shared by every workspace, but you never see another workspace's properties. Properties in deleted classes, versions or projects are left out. When nothing is bound, the card reads No property in your projects uses this type.

The Properties figure under Used in is the type's running binding count, so it can be higher than the list: it also counts bindings removed since, and a system type's bindings in other workspaces.

Deprecate a type​

Deprecate a type when it should no longer be picked up — for example when a newer type replaces it. Check what uses it first.

  1. Open the type's page and click “Deprecate”.
  2. Optionally set a Sunset date (the date after which the type should no longer be used; today or later), write a Message saying why and what to do instead, and choose a Replacement type. The list leaves out the type itself and types that are already deprecated.
  3. Click “Deprecate type”.
The Deprecate dialog: Sunset date, Message and Replacement type, with Cancel and Deprecate typeThe Deprecate dialog: Sunset date, Message and Replacement type, with Cancel and Deprecate type
Route/ade/dashboard/primitives/[id]

The type's page now shows a deprecated badge, a notice with the sunset date, your message and a link to the replacement, and Lifecycle under Metadata reads deprecated · sunset <date>. In the Registry table the type's name carries a deprecated marker. Once the sunset date has passed, the notice turns red and reads Deprecated — sunset passed on date.

A deprecated type's page: the deprecated badge, the notice with its sunset date, message and replacement, and Edit deprecation and Restore in the headerA deprecated type's page: the deprecated badge, the notice with its sunset date, message and replacement, and Edit deprecation and Restore in the header
Route/ade/dashboard/primitives/[id]

Deprecation is a marker, not a lock:

A deprecated type
Still resolves and validatesEvery $ref to it keeps working, before and after the sunset date.
Keeps its bindingsProperties bound to it are unchanged, and it can still be chosen for new ones.
Is exported unchangedIts JSON Schema is not modified.
Is recordedDeprecating, changing and restoring are written to the registry audit log.

To change the details, click “Edit deprecation”, change the fields and click “Save changes”; a field you clear is removed. To undo it, click “Restore”: the badge, the notice and the details are removed, and the type is active again.

Core system types cannot be deprecated: for them “Deprecate” is disabled. You need permission to edit types.

Create a type​

  1. Click “Create primitive” (or press N).
  2. On Form, enter a Name (for example currency-code) and choose its Type (string); the type cannot change after you create it.
  3. Add a Description, Tags, constraints (format, pattern, length), Allowed values (enum), a Default value and Examples. The Schema preview at the bottom shows the result. Advanced JSON edits the schema directly.
  4. Click “Create”.
The Create primitive dialog: name, type, description, string constraints, allowed values, default and examplesThe Create primitive dialog: name, type, description, string constraints, allowed values, default and examples
Route/ade/dashboard/primitives

Import types​

Importing brings types you already have into the registry instead of retyping them. One import can create many types, and the types keep pointing at each other afterwards.

When to import​

  • You have a JSON Schema 2020-12 document — one schema, or one with reusable types under $defs (or the older definitions).
  • You have an Apiome type-definition bundle: one .json or .yaml file holding many types under types.
  • You want the reusable types of an OpenAPI 3.1 description — its components/schemas.

To add a single new type by hand, create it instead.

Import at a glance​

StepWhereDetails
Choose what you are importingSource step, Source typeSource types
Give the documentSource step: File, URL or PasteRun an import
Choose where the types goTarget namespace (optional)Namespaces & scopes
Keep references workingDone for you when the types are savedHow references are kept
Settle clashes with existing typesReview stepReview and conflicts
Read what happenedResult stepThe result
Do it without the screenCLI or REST APIImport with the CLI, Import with the API

Source types​

Source typeWhat becomes a type
JSON SchemaEach entry under $defs or definitions. A document with neither is imported as one type.
Type-def bundleEach entry under types (or $defs / definitions). A bundle of 12 types imports 12 types.
OpenAPIEach entry under components/schemas — see From an OpenAPI 3.1 document.

Every type is checked as a JSON Schema 2020-12 schema before it is saved.

Run an import​

Click “Import from schema” (or press I). The Import primitives dialog has three steps: Source, Review and Result.

  1. Source — under Source type, choose JSON Schema, Type-def bundle or OpenAPI. Then give the document as a File (.json, .yaml or .yml), a URL or Paste.
  2. Under Options, enter a Target namespace (optional) if the types should not go to the default one, or tick Always extract namespace automatically to take it from the document. Two more options are ticked to begin with:
  3. Review — Apiome lists the types it found. Untick any you do not want, and for each one that clashes with an existing type choose Keep existing, Overwrite or Import as new name.
  4. Click “Import N selected”, then read the Result and click “Done”.
The Import primitives dialog on its Source step: source types, file, URL or paste, and namespace optionsThe Import primitives dialog on its Source step: source types, file, URL or paste, and namespace options
Route/ade/dashboard/primitives

How references are kept​

Inside a source document, types point at each other with references that only mean something in that document, such as #/$defs/Money. When the types are saved, Apiome rewrites each of these to a relative reference to the saved type:

In the sourceIn the registry
#/$defs/Money./money
#/definitions/Money./money
#/types/Money./money
#/components/schemas/Money./money
#/$defs/Money/properties/amount./money#/properties/amount

Relative references keep working when a namespace moves to another base URI, and the Resolver follows them like any other $ref.

With Map recognized formats to core JSON System types ticked, a string that only says "format": "email" (or uuid, uri, date, date-time, time) is also pointed at the matching core system type, so every imported email is the same type. A $ref you wrote yourself is never replaced.

Review and conflicts​

The Review step shows what the import would do before anything is saved. Each type has one status:

StatusMeaningWhat happens
NewNo type with this name exists in the target namespace.It is created.
IdenticalThe same type is already there.It is skipped, while Skip definitions identical to an existing type is ticked.
ConflictA type with this name exists and differs.You choose — see below.
InvalidIt is not a valid JSON Schema 2020-12 schema.It cannot be imported; the row lists what is wrong.

For a Conflict, choose one:

  • Keep existing — the type in the registry stays as it is. This is the default, so an import never replaces a type unless you say so.
  • Overwrite — the type in the registry is replaced by the imported one.
  • Import as new name — the imported type is saved beside the existing one under the name you enter.

A type that points at something Apiome cannot find is marked as having an unresolved reference. It still imports; fix the reference later on the Resolver tab.

The result​

The Result step counts the types under Imported, Overwritten, Renamed, Identical (skipped), Skipped and Errors. A conflict you left on Keep existing is under Skipped. Every import is recorded: the last eight are under Recent activity on the Registry tab, and the imported schemas count in the facts line goes up.

From an OpenAPI 3.1 document​

Choose OpenAPI to import the reusable types of an API description. Each entry under components/schemas becomes one type, named after its component; the document's info, paths and other components are not types and are left out.

  • References. A $ref to another component, such as #/components/schemas/Money, is rewritten to a reference to that type in the registry (./money), so the imported types still point at each other. A reference to a type arriving in the same import is not reported as unresolved.
  • Versions. OpenAPI 3.1 schemas are JSON Schema 2020-12, so they are validated as written. An OpenAPI 3.0 document still imports, with a warning that 3.0-only keywords may not validate. A jsonSchemaDialect other than 2020-12 is warned about too.
  • Not OpenAPI. A document with no openapi version, with a version other than 3.x, or with no components/schemas is refused with a message saying why. A Swagger 2.0 document keeps its types under definitions: import it as JSON Schema instead.

Namespaces & scopes​

A namespace groups types under a base URI and version, such as tenant/acme/v1/types. The tab shows the system root and your tenant namespaces, and the order a $ref is resolved in: your tenant namespace, then imported vendor namespaces, then the core system types.

Click “New namespace” and enter a Namespace path, Base URI, Version root and Description, and choose a Root status; tick Default namespace to make new types land there. System namespaces are Read-only.

Namespaces & scopes: the system root, tenant namespaces, the namespaces table with a draft root and the All, Stable and Draft filter, and the resolution orderNamespaces & scopes: the system root, tenant namespaces, the namespaces table with a draft root and the All, Stable and Draft filter, and the resolution order
Route/ade/dashboard/primitives

Version roots: stable and draft​

The version root is the vN part of a namespace path — v1 in tenant/acme/v1/types. Each namespace says whether its root is settled:

Root statusUse it for
Stable (the default)Types that are settled and safe to build on.
DraftThe next version while it is still being worked on: its types may still change shape.

A draft root shows a draft marker beside its Version root in the table. To see draft roots apart from stable ones, use the All / Stable / Draft filter above the table; the footer counts the draft roots.

To start the next version, create a namespace for it — for example tenant/acme/v2/types — with Root status set to Draft. When it is ready, click “Edit” on its row, set Root status to Stable and click “Save changes”. The status is a label: it does not change how a $ref resolves. System namespaces are always stable.

Resolver​

The Resolver shows how every $ref in your types resolves — Resolved, Unresolved or Circular — as a list and a reference graph. Filter by Namespace, and click “Re-resolve” after fixing a reference.

The Resolver tab: resolution base, reference graph and the list of references with their statusThe Resolver tab: resolution base, reference graph and the list of references with their status
Route/ade/dashboard/primitives

Settings​

Settings chooses the JSON Schema dialect, how references resolve (the base URL and $ref style), Import defaults and Validation & publishing rules for this tenant. Click “Save settings”, or “Reset to defaults”.

The Settings tab: registry storage, JSON Schema dialect, validation switches and reference resolutionThe Settings tab: registry storage, JSON Schema dialect, validation switches and reference resolution
Route/ade/dashboard/primitives

With the CLI or the API​

  • CLI: apiome types list|show|search — see the CLI quick-start — and apiome primitives import — see Import primitives with the CLI.
  • REST: GET / POST /v1/primitives/{tenant}, GET /v1/primitives/{tenant}/{id} (with dependents and property_dependents), GET / POST /v1/types/{tenant}/namespaces, GET / PUT /v1/types/{tenant}/settings, POST /v1/types/{tenant}/resolve — see the API reference.

Deprecate types and manage version roots with the API​

CallWhat it does
POST /v1/primitives/{tenant}/{id}/deprecateDeprecates the type, or replaces a deprecated type's details. Body (all optional): sunset_date (YYYY-MM-DD), message (up to 500 characters), replacement_id.
DELETE /v1/primitives/{tenant}/{id}/deprecateRestores the type. Does nothing if it is not deprecated.
GET /v1/primitives/{tenant}/{id}Returns deprecated, deprecated_at, sunset_date, deprecation_message, replacement_id and replacement (id, name, schema_id). List and search rows carry all but replacement.
GET /v1/types/{tenant}/namespaces?root_status=draftLists only draft roots; root_status=stable lists only stable ones. Every namespace carries root_status.
POST / PUT /v1/types/{tenant}/namespacesAccept root_status: stable (the default) or draft.

Deprecating returns 422 when the sunset date is in the past, or when the replacement is not found, is the type itself or is deprecated; 403 for a core system type. The calls are on the Primitives and Type registry REST references, and the audit entries (primitive.deprecate, primitive.restore) on the Registry audit reference.

Import primitives with the CLI​

apiome primitives import <file> adds a file of primitives to your tenant in one go — for example the loyalty IDs, SKU formats and region codes a new tenant starts with. All flags are on the apiome primitives reference.

  1. Write the file, in JSON or YAML: one primitive, or a list of them. Each has a name, a base (a JSON Schema type: string, number, integer, boolean, object, array or null) and any other JSON Schema keyword, such as pattern, format, enum, description or examples.

    acme-primitives.yaml
    - name: acme-loyalty-id
    base: string
    pattern: ^LM-[0-9]{8}$
    examples: [LM-00000001, LM-12345678]
    - name: acme-region-code
    base: string
    pattern: ^(EU|US|APAC)$
    - name: acme-internal-sku
    base: string
    pattern: ^SKU-[A-Z0-9]{10}$
  2. See what the import would do. Nothing is saved:

    apiome primitives import ./acme-primitives.yaml --dry-run
    Would import 2 primitives:
    + acme-region-code (string, pattern ^(EU|US|APAC)$)
    + acme-internal-sku (string, pattern ^SKU-[A-Z0-9]{10}$)
    Conflicts (skipped without --update):
    ~ acme-loyalty-id (already exists, would be overwritten with --update)
  3. Import. In a terminal the command shows the same plan and asks before it saves; --yes skips the question:

    apiome primitives import ./acme-primitives.yaml --yes
    ✔ Imported 2 new, updated 0 existing primitives.
    Skipped 1 conflict (pass --update to overwrite).

Without a terminal — in a script or a CI job — nothing is saved unless you pass --yes.

ToPass
Overwrite a primitive that already exists with a different schema--update
Leave existing primitives alone (the default)--skip-conflicts
Import the good rows when others fail--continue-on-error
Keep a JSON record of every row--report report.json
Read the primitives from stdinNo file, or -

What is checked. Before anything is sent, each row is checked on your machine: it has a name no other row uses, base is a JSON Schema type, pattern is a regular expression, the schema is valid JSON Schema 2020-12 and every example matches it. A file with more than 50 rows shows a progress bar while it is checked. Apiome then reviews the rows the same way the Import primitives dialog does — see Review and conflicts. A primitive identical to an existing one is left as it is.

When a row fails. Each failed row is listed with its row number and the reason. Nothing is imported and the command exits with code 7. With --continue-on-error the other rows are imported and the command exits with 0. The rows go to Apiome in one request and are saved one by one, so a row that fails while saving does not undo the rows saved before it.

The report. --report <path> writes one entry for each row — row, name, status and message — and a summary that counts the rows by status. After a dry run the statuses are new, overwrite, conflict and unchanged; after an import they are imported, updated, skipped and unchanged. A row that was not imported is invalid, failed, system (a read-only core system type) or aborted (left out because another row failed). apiome --json primitives import … prints the same report.

Copy primitives back in. A row can also be a primitive as apiome types list --json prints it — a name and a schema — so the list can be saved, edited and imported again:

apiome --json types list | apiome primitives import --update --yes

Core system types in the list are skipped. Each row keeps the $id in its schema, so it updates the primitive it came from; to copy a primitive to another tenant as a new type, remove $id from its schema first.

Import types with the API​

The dialog uses the same endpoints, so an API import gives the same result. All of them are on the Primitives REST reference.

CallWhat it does
POST /v1/primitives/{tenant}/import/reviewDry run: returns each type's status, validation report and reference rewrites. Saves nothing.
POST /v1/primitives/{tenant}/importSaves the types and returns the report with an import_id.
POST /v1/primitives/{tenant}/import/stageFetches and parses a source — pasted text, a file's text, a URL, or a file in a public GitHub repository — and lists the types it found. Saves no types.
GET /v1/primitives/{tenant}/importsLists past imports.
GET /v1/primitives/{tenant}/imports/{import_id}One past import, with its report.

In the body of /import/review and /import:

FieldValue
schemaThe document, as JSON.
source_kindjson-schema (the default), type-def-bundle or openapi.
import_all / selected_definitionsImport every type, or only the named ones.
target_namespaceThe namespace the types go to.
map_core_formatstrue by default — see How references are kept.
dedupetrue by default: an identical type is skipped.
resolutionsFor /import only. One entry for each conflicting type: {"action": "keep"}, {"action": "overwrite"} or {"action": "rename", "new_name": "money-v2"}.

Review needs permission to view types; importing and staging need permission to create them.

Where next​