---
title: "JSON Schemas"
description: "Validate stored forges data, or generate types for another language, from a JSON Schema for each public type."
canonical_url: "https://forges.link/reference/json-schemas"
---
# JSON Schemas

> Validate stored forges data, or generate types for another language, from a JSON Schema for each public type.

`forges` describes its data model with JSON Schemas. They let you check data that you stored as JSON, and they let languages other than TypeScript generate the same types. The schemas are generated from the TypeScript types, so they always match.

## Use the schemas in code

`forges/schema` exports `schemas`, an object keyed by the names of the types. The schemas refer to each other in the OpenAPI form `#/components/schemas/<Type>`, which means you can use `schemas` directly as the `components.schemas` of an OpenAPI document.

```ts
import { schemas } from 'forges/schema'

// { type: 'object', properties: { ref: ..., kind: ... }, required: [...] }
schemas.Thread
```

## Use the schemas as files

If you need a file, `forges/schema/<Type>.json` contains one type as a standalone [draft-07](https://json-schema.org/draft-07) document. It carries the definitions that it refers to, so a validator needs nothing else. The following example validates stored data with Ajv:

```ts
import Ajv from 'ajv'
import { reviveDates } from 'forges'
import thread from 'forges/schema/Thread.json' with { type: 'json' }

const validate = new Ajv({ strict: false, validateFormats: false }).compile(thread)

const stored = JSON.parse(text)
if (!validate(stored)) {
  throw new Error('Not a Thread')
}

// JSON has no dates, so turn the ISO strings back into `Date`s.
const value = reviveDates(stored)
```

## What the schemas say

A few conventions apply to every schema:

- `Date` fields are `{ type: 'string', format: 'date-time' }`, because JSON has no dates. To turn them back into dates, use [`reviveDates()`](https://forges.link/reference/data-model#revivedates).
- JSON can't carry bytes, so `Uint8Array` fields, such as the content of a binary file, are described by a note and `x-forges-type: Uint8Array`.
- The `raw` and `payload` fields accept anything, because they hold the response of the forge as it was.
- Objects accept extra properties. This way, a newer version of `forges` can add a field without breaking data that you stored earlier.
- Every schema has an `x-forges-type` with the name of the type.

## Available schemas

`Actor`, `AddCollaboratorResult`, `AlertSupport`, `AuthKind`, `AuthorAssociation`, `Branch`, `ChangedFile`, `Check`, `CheckRef`, `CheckState`, `ChecksSummary`, `CiJob`, `CiJobRef`, `CiRun`, `CiRunRef`, `CodeFragment`, `CodeMatch`, `Collaborator`, `Comment`, `CommentRef`, `Commit`, `CommitRef`, `CommitSignature`, `Comparison`, `Contributor`, `ContributorStats`, `ContributorWeek`, `Cursor`, `EventAction`, `EventDetail`, `EventKind`, `FileContent`, `FileStatus`, `ForgeCapabilities`, `ForgeEvent`, `ForgeInstance`, `ForgeKind`, `ForgeWarning`, `ForgeWarningCode`, `GetManyResult`, `Installation`, `InstallationToken`, `KnownForgeKind`, `Label`, `MergeCommitDefaults`, `MergeMethod`, `MergeResult`, `Milestone`, `Notification`, `NotificationReason`, `NotificationRef`, `NotificationSubject`, `PerKind`, `PullBranches`, `PullStats`, `PushCommit`, `Reaction`, `ReactionContent`, `ReactionSummary`, `Release`, `ReleaseAsset`, `ReleaseAssetRef`, `ReleaseRef`, `Repo`, `RepoFeatures`, `RepoPermissions`, `RepoRef`, `RepoRole`, `RepoTemplate`, `RepoTemplateField`, `RepoVisibility`, `ResolvedCommentRef`, `ResolvedReviewRef`, `ResolvedThreadRef`, `Review`, `ReviewComment`, `ReviewCommentInput`, `ReviewRef`, `ReviewState`, `Reviewer`, `SecurityAlert`, `SecurityAlertKind`, `SecurityAlertRef`, `SecuritySeverity`, `SourceKind`, `SubscriptionState`, `Support`, `Tag`, `TextLimits`, `Thread`, `ThreadKind`, `ThreadRef`, `ThreadSnapshot`, `ThreadStack`, `ThreadState`, `TreeEntry`, `TreeEntryType`, `UpsertCommentResult`, `User`, `Webhook`, `WebhookDeliveryRecord`, `WebhookDeliveryRef`, `WebhookRef`


## Sitemap

See the full [sitemap](https://forges.link/sitemap.md) for all pages.
