typia.json.schemas โ emit JSON Schema / OpenAPI from a TypeScript type
If youโve ever hand-written a JSON Schema or an OpenAPI components block, you know how mechanical it is. typia generates it from the TypeScript type at compile time. Same model as the validators โ no extra schema file to maintain.
namespace json {
function schema<T, Version extends "3.0" | "3.1" = "3.1">(): IJsonSchemaUnit<Version, T>;
function schemas<Schemas extends unknown[], Version extends "3.0" | "3.1" = "3.1">(): IJsonSchemaCollection<Version, Schemas>;
function application<Class extends object, Version extends "3.0" | "3.1" = "3.1">(): IJsonSchemaApplication<Version, Class>;
}| Function | Use case |
|---|---|
json.schema<T>() | A single top-level schema, plus a components map for any $refs the type pulls in |
json.schemas<[T1, T2, ...]>() | Multiple top-level types sharing one components map (the common case for an OpenAPI components.schemas) |
json.application<Class>() | Class methods โ a list of {name, parameters, output} JSON Schemas โ handy for framework-neutral tooling that wants per-method schemas without typiaโs LLM-specific config |
In json.application, each parameterโs required flag follows its selected TypeScript signature. A question token or default initializer permits omission, including a default before a later required parameter; that later argument still must be provided. A required public overload or contextual function type remains required even when its implementation has a default. Return schemas use the inferred return type as well as explicit annotations.
For the LLM-specific shape (with $defs, additionalProperties: false, strict mode, โฆ), use typia.llm.parameters or typia.llm.application instead.
Version selects the JSON Schema dialect:
"3.1"(default) โ OpenAPI 3.1, which is JSON Schema 2020-12. Supports tuples, pattern properties,nullas a primitive."3.0"โ OpenAPI 3.0 / Swagger compatibility. No tuples, no pattern properties.
Stick with "3.1" unless a downstream consumer demands the older dialect.
First example
import typia, { tags } from "typia";
interface User {
id: string & tags.Format<"uuid">;
age: number & tags.Type<"uint32">;
email?: string & tags.Format<"email">;
}
const schemas = typia.json.schemas<[User]>();
// โ an IJsonSchemaCollection with `User` under components.schemasThe output is a plain object. Use it directly with typia and @typia/utils, hand it to ajv when your JSON Schema consumer accepts typiaโs emended shape, or save it to disk for tooling that wants schemas at rest.
When index-signature values are combined into a schema, their template-literal alternatives remain in the resulting value union.
When validating a schema with @typia/utilsโs OpenApiValidator, supported string formats apply their registered checks. Unknown format names are annotations and impose no format check; string type, pattern and length constraints still apply. This also holds for custom names such as constructor or __proto__.
typia.json.schema, typia.json.schemas, and typia.json.application return typiaโs emended schema representation. It is designed for typia and @typia/utils converters first, not for direct assignment to every third-party OpenAPI SchemaObject type. When a tool expects raw OpenAPI 3.1 schemas, convert the components with OpenApiConverter.downgradeComponents:
import typia from "typia";
import { OpenApiConverter } from "@typia/utils";
const collection = typia.json.schemas<[User]>();
const components = OpenApiConverter.downgradeComponents(
collection.components,
"3.1",
);
// Use components.schemas in an OpenAPI 3.1 document or plugin option.This matters for schema-level examples: typia keeps tags.Examples<T> as named examples in the emended schema, while OpenAPI 3.1โs Schema Object uses JSON Schemaโs array-shaped examples keyword. The converter drops the names and emits the raw OpenAPI form.
The same boundary applies to tags.Format<"byte">. Typia keeps format: "byte" in its emended schema, OpenAPI 3.0 output retains that spelling, and raw OpenAPI 3.1 output uses contentEncoding: "base64". An explicitly supplied tags.ContentMediaType<...> is retained in the OpenAPI 3.1 Schema Object; typia does not invent a media type when none was declared.
For tuples, raw OpenAPI 3.1 uses prefixItems for positional schemas and items for the remaining elements. The converter writes typiaโs emended rest constraint into items and preserves the required prefix length through minItems. When upgrading a raw schema, items: true or omitted items permits unconstrained elements, while items: false forbids them; without a prefix, false permits only an empty array, subject to the schemaโs length bounds.
Swagger 2 document conversion
For Swagger 2 documents, OpenApiConverter.upgradeDocument composes each server URL from schemes, host, and basePath and rejects endpoint fields containing queries or fragments. Equivalent host casing and root URL spellings with and without a trailing slash normalize to one Swagger endpoint. An operationโs schemes, consumes, and produces override the document defaults; when neither media list is present, the converter uses application/json for compatibility. An explicit empty media list clears the inherited default, but it cannot accompany a body or response payload because the emended content model has no media key under which to retain that schema or example. Swagger formData parameters become one object-shaped request body; scalar enums, nullable scalar or array fields, and recursively nested arrays of those scalar shapes remain simple form fields. File-field validation metadata and x-* extensions remain on the binary property schema, and response examples remain associated with their MIME types.
OpenApiConverter.downgradeDocument(document, "2.0") keeps media types on each operation instead of guessing shared document defaults. Schema constants become typed Swagger enums, and supported annotations on individual constant branches, including nullable branches and their default: null, survive a downgrade and re-upgrade. An empty response content map normalizes to a response without a payload. Swagger 2 can express only one host and base path and one schema shared by a responseโs media types, so the converter throws a TypeError when server descriptions, variables, credentials, unsupported schemes, different authorities or paths, streaming item schemas, encrypted bodies or responses, request bodies without at least one defined media type and schema, non-empty response media without a schema or example, mixed form and non-form request media, forms without a defined field, aggregate form-object constraints, non-simple form fields, mismatched form-body and field requiredness, media-specific schemas, or named examples would otherwise be lost. File form fields support both multipart/form-data and application/x-www-form-urlencoded, as defined by Swagger 2. Response examples may still differ by MIME type because Swagger represents them as a keyed map.
TypeScript Source
import typia, { tags } from "typia";
export const MemberSchema = typia.json.schemas<[IMember], "3.0">();
interface IMember {
/** Unique user ID generated by server. */
id: string & tags.Format<"uuid">;
/** Email address of the member. */
email: string & tags.Format<"email">;
/**
* Age of the member.
*
* For reference, only adult can be a member.
*/
age: number &
tags.Type<"uint32"> &
tags.ExclusiveMinimum<19> &
tags.Maximum<100>;
}Compiled JavaScript
import typia from "typia";
export const MemberSchema = {
components: {
schemas: {
IMember: {
type: "object",
properties: {
id: {
type: "string",
format: "uuid",
description: "Unique user ID generated by server.",
},
email: {
type: "string",
format: "email",
description: "Email address of the member.",
},
age: {
type: "integer",
minimum: 19,
exclusiveMinimum: true,
maximum: 100,
description:
"Age of the member.\n\nFor reference, only adult can be a member.",
},
},
required: ["id", "email", "age"],
additionalProperties: false,
},
},
},
schemas: [
{
$ref: "#/components/schemas/IMember",
},
],
version: "3.0",
};undefined
export namespace json {
export function schemas<
Schemas extends unknown[],
Version extends "3.0" | "3.1" = "3.1",
>(): IJsonSchemaCollection<Version>;
}undefined
import { OpenApi } from "../openapi/OpenApi";
import { OpenApiV3 } from "../openapi/OpenApiV3";
/**
* Collection of JSON schemas generated from multiple TypeScript types.
*
* `IJsonSchemaCollection` holds JSON schemas for multiple TypeScript types
* generated at compile time by `typia.json.schemas<[T1, T2, ...]>()`. The
* schemas share a common components pool to avoid duplication when types
* reference each other.
*
* This is useful when you need schemas for multiple related types and want to
* share component definitions between them. For single types, use
* {@link IJsonSchemaUnit} instead. For function schemas, see
* {@link IJsonSchemaApplication}.
*
* The collection contains:
*
* - {@link IV3_1.schemas | schemas}: Array of schemas, one per input type
* - {@link IV3_1.components | components}: Shared `$ref` definitions
* - {@link IV3_1.__types | __types}: Phantom property for type inference
*
* @author Jeongho Nam - https://github.com/samchon
*
* @template Version OpenAPI version ("3.0" or "3.1")
* @template Types Tuple of original TypeScript types
*
* @evidence contracts/common.md#principled-implementation A distributive conditional selects the version-literal variant and its matching OpenApiV3 or normalized OpenApi schema types; Types is carried only by an optional phantom member. A version union therefore remains a union of correlated versioned records.
* @evidence contracts/common.md#clear-and-simple-design The alias owns dialect selection while the namespace owns the two result shapes. It does not duplicate schema definitions or a runtime converter.
* @evidence contracts/common.md#prohibited-implementation-shortcuts The 3.0 and 3.1 literals are supported wire dialects, not fixture exceptions. This type neither validates schemas nor requires a runtime phantom value.
* @evidence contracts/common.md#meaningful-documentation The native comment explains ordered root schemas, shared components, the generic parameters and adjacent single/multiple/application APIs; member comments identify phantom inference and generator omission.
*/
export type IJsonSchemaCollection<
Version extends "3.0" | "3.1" = "3.1",
Types = unknown[],
> = Version extends "3.0"
? IJsonSchemaCollection.IV3_0<Types>
: IJsonSchemaCollection.IV3_1<Types>;
/** Version-specific collections of JSON schemas and their shared definitions. */
export namespace IJsonSchemaCollection {
/**
* JSON Schema collection for OpenAPI v3.0 specification.
*
* Uses OpenAPI v3.0 compatible JSON Schema format. In v3.0, nullable types
* are expressed with `nullable: true` rather than v3.1's `type` arrays.
*
* @template Types Tuple of original TypeScript types for phantom type
* preservation
*
* @evidence contracts/common.md#principled-implementation The 3.0 literal discriminator accompanies ordered root schemas and components typed in the OpenApiV3 dialect. The optional Types member preserves generic inference; the generator omits it rather than serializing TypeScript values.
* @evidence contracts/common.md#clear-and-simple-design The record separates ordered roots from shared component definitions, enabling recursive references without duplicating the component graph. Dialect-specific field types remain local to this variant.
* @evidence contracts/common.md#prohibited-implementation-shortcuts The wire version and schema fields express the supported 3.0 result contract. Optional phantom typing is not a runtime guard and does not prevent callers from constructing a value with that property.
* @evidence contracts/common.md#meaningful-documentation Member comments explain input order, reference ownership and generator omission of the phantom property; the variant comment identifies dialect differences and its inference generic.
*/
export interface IV3_0<Types = unknown[]> {
/**
* OpenAPI specification version.
*
* Always `"3.0"` for this variant. Use this discriminator to determine
* which schema format is in use.
*/
version: "3.0";
/**
* Generated JSON schemas, one per input type.
*
* Array of schemas in the same order as the input type tuple. Each schema
* may reference definitions in {@link components}.
*/
schemas: OpenApiV3.IJsonSchema[];
/**
* Shared schema definitions for `$ref` references.
*
* Contains named schemas used across multiple types in the collection.
* Reduces duplication when types share common structures.
*/
components: OpenApiV3.IComponents;
/**
* Phantom property for TypeScript generic type preservation.
*
* The generated result omits this property. It preserves the `Types`
* generic parameter for type inference and should not be read as schema
* data.
*/
__types?: Types | undefined;
}
/**
* JSON Schema collection for OpenAPI v3.1 specification.
*
* Uses OpenAPI v3.1 compatible JSON Schema format. v3.1 aligns more closely
* with JSON Schema draft 2020-12, supporting features like `type` arrays for
* nullable types and `const` values.
*
* @template Types Tuple of original TypeScript types for phantom type
* preservation
*
* @evidence contracts/common.md#principled-implementation The 3.1 literal discriminator accompanies ordered root schemas and components typed in the normalized OpenApi dialect. The optional Types member preserves generic inference; the generator omits it rather than serializing TypeScript values.
* @evidence contracts/common.md#clear-and-simple-design The record separates ordered roots from shared component definitions, enabling recursive references without duplicating the component graph. Dialect-specific field types remain local to this variant.
* @evidence contracts/common.md#prohibited-implementation-shortcuts The wire version and schema fields express the supported 3.1 result contract. Optional phantom typing is not a runtime guard and does not prevent callers from constructing a value with that property.
* @evidence contracts/common.md#meaningful-documentation Member comments explain input order, reference ownership and generator omission of the phantom property; the variant comment identifies dialect differences and its inference generic.
*/
export interface IV3_1<Types = unknown[]> {
/**
* OpenAPI specification version.
*
* Always `"3.1"` for this variant. Use this discriminator to determine
* which schema format is in use.
*/
version: "3.1";
/**
* Shared schema definitions for `$ref` references.
*
* Contains named schemas used across multiple types in the collection.
* Reduces duplication when types share common structures.
*/
components: OpenApi.IComponents;
/**
* Generated JSON schemas, one per input type.
*
* Array of schemas in the same order as the input type tuple. Each schema
* may reference definitions in {@link components}.
*/
schemas: OpenApi.IJsonSchema[];
/**
* Phantom property for TypeScript generic type preservation.
*
* The generated result omits this property. It preserves the `Types`
* generic parameter for type inference and should not be read as schema
* data.
*/
__types?: Types | undefined;
}
}undefined
import { IJsonSchemaAttribute } from "../schema/IJsonSchemaAttribute";
import * as tags from "../tags";
/**
* Emended OpenAPI v3.2 specification.
*
* `OpenApi` is a refined OpenAPI v3.2 specification that normalizes ambiguous
* and redundant expressions from various OpenAPI versions (Swagger 2.0, OpenAPI
* 3.0, 3.1, 3.2). This unified format simplifies schema processing for `typia`
* and `@nestia/sdk`.
*
* Key simplifications:
*
* - Schema `$ref` references are unified to `#/components/schemas/{name}` format
* - Non-schema references (parameters, responses) are resolved inline
* - `nullable` is converted to `{ oneOf: [schema, { type: "null" }] }`
* - `allOf` compositions are merged into single schemas
* - Schema attributes are normalized across all versions
*
* Use `HttpLlm.application()` from `@typia/utils` to convert
* `OpenApi.IDocument` into {@link IHttpLlmApplication} for LLM function
* calling.
*
* @author Jeongho Nam - https://github.com/samchon
*
* @evidence contracts/common.md#principled-implementation The namespace is typia's single normalized target for every OpenAPI input version: references to schemas use one path form, other references are inlined, nullable and allOf are rewritten to oneOf and merged forms, and every consumer is written once against this one shape. The marker field on the document records that this normalization has run.
* @evidence contracts/common.md#clear-and-simple-design One namespace holding the document and its parts so a consumer imports one name; version-specific shapes live in separate namespaces and are converted by the utils package.
* @evidence contracts/common.md#prohibited-implementation-shortcuts The type describes the normalized form and does not itself convert or patch any input document.
* @evidence contracts/common.md#meaningful-documentation The comment lists the simplifications, names the marker used by the converters and points to the LLM conversion that consumes it.
*/
export namespace OpenApi {
/**
* HTTP method supported by OpenAPI operations.
*
* Standard HTTP methods used in REST APIs. Each path can have multiple
* operations, one per HTTP method.
*
* @evidence contracts/common.md#principled-implementation A closed union of the HTTP method names that a path item can hold, including `trace` and the newer `query`, so a path's operation record is keyed by exactly these.
* @evidence contracts/common.md#clear-and-simple-design One alias that IPath reuses as its key set.
* @evidence contracts/common.md#prohibited-implementation-shortcuts A literal union; unknown methods go through IPath.additionalOperations.
* @evidence contracts/common.md#meaningful-documentation The comment says it lists the standard methods that carry operations.
*/
export type Method =
| "get"
| "post"
| "put"
| "delete"
| "options"
| "head"
| "patch"
| "trace"
| "query";
/**
* Root document structure for emended OpenAPI v3.2.
*
* Contains all API metadata, paths, operations, and reusable components. The
* `x-typia-emended-v12` marker indicates this document has been processed by
* `samchon/typia` to normalize schema formats.
*
* @evidence contracts/common.md#principled-implementation Version is a template literal `3.2.${number}`, so a 3.2 patch release is accepted and other versions are rejected; components is required because normalized schemas live there, while paths and webhooks are optional as in the specification. The marker literal true distinguishes an emended document.
* @evidence contracts/common.md#clear-and-simple-design One flat document record with info, tag and contact records in its own namespace.
* @evidence contracts/common.md#prohibited-implementation-shortcuts The literal marker is a contract between producer and consumer and not a test hook.
* @evidence contracts/common.md#meaningful-documentation The comment explains the role of the marker field and each member has a one-line comment.
*/
export interface IDocument {
/** OpenAPI version. */
openapi: `3.2.${number}`;
/** List of servers providing the API. */
servers?: IServer[];
/** API metadata. */
info?: IDocument.IInfo;
/** Reusable components (schemas, security schemes). */
components: IComponents;
/** Available API paths and operations. */
paths?: Record<string, IPath>;
/** Webhook definitions. */
webhooks?: Record<string, IPath>;
/** Global security requirements. */
security?: Record<string, string[]>[];
/** Tag definitions for grouping operations. */
tags?: IDocument.ITag[];
/** Marker for emended document by `typia` */
"x-typia-emended-v12": true;
}
export namespace IDocument {
/**
* API metadata and identification.
*
* Contains essential information about the API including title, version,
* contact information, and licensing details.
*
* @evidence contracts/common.md#principled-implementation Title and version are required, as the specification requires, and the rest is optional descriptive metadata including a summary.
* @evidence contracts/common.md#clear-and-simple-design One record; contact and license are separate records.
* @evidence contracts/common.md#prohibited-implementation-shortcuts A data record.
* @evidence contracts/common.md#meaningful-documentation The comment summarizes what the record identifies and each field is documented.
*/
export interface IInfo {
/** API title. */
title: string;
/** Short summary. */
summary?: string;
/** Full description. */
description?: string;
/** Terms of service URL. */
termsOfService?: string;
/** Contact information. */
contact?: IContact;
/** License information. */
license?: ILicense;
/** API version. */
version: string;
}
/**
* Tag for grouping operations.
*
* @evidence contracts/common.md#principled-implementation A tag has a required name and optional summary, description, parent and kind, which reflects the hierarchical tag fields of version 3.2.
* @evidence contracts/common.md#clear-and-simple-design One record.
* @evidence contracts/common.md#prohibited-implementation-shortcuts A data record.
* @evidence contracts/common.md#meaningful-documentation Each field has a one-line comment, with example kinds.
*/
export interface ITag {
/** Tag name. */
name: string;
/** Short summary for display in tag lists. */
summary?: string;
/** Tag description. */
description?: string;
/** Parent tag name for hierarchical organization. */
parent?: string;
/** Tag classification (e.g., "nav", "badge"). */
kind?: string;
}
/**
* Contact information.
*
* @evidence contracts/common.md#principled-implementation Name, URL and email are all optional; the email is typed with the Format email tag, so a typia validation of a document checks its syntax.
* @evidence contracts/common.md#clear-and-simple-design One record.
* @evidence contracts/common.md#prohibited-implementation-shortcuts The format tag is a declared constraint and no check is performed in the declaration.
* @evidence contracts/common.md#meaningful-documentation Each field has a one-line comment.
*/
export interface IContact {
/** Contact name. */
name?: string;
/** Contact URL. */
url?: string;
/** Contact email. */
email?: string & tags.Format<"email">;
}
/**
* License information.
*
* @evidence contracts/common.md#principled-implementation A name is required and the SPDX identifier and URL are optional, as in the specification.
* @evidence contracts/common.md#clear-and-simple-design One record.
* @evidence contracts/common.md#prohibited-implementation-shortcuts A data record.
* @evidence contracts/common.md#meaningful-documentation Each field has a one-line comment.
*/
export interface ILicense {
/** License name. */
name: string;
/** SPDX license identifier. */
identifier?: string;
/** License URL. */
url?: string;
}
}
/**
* Server providing the API.
*
* @evidence contracts/common.md#principled-implementation The URL is required and variables are optional named values for URL templates.
* @evidence contracts/common.md#clear-and-simple-design One record, with the variable record in its namespace.
* @evidence contracts/common.md#prohibited-implementation-shortcuts A data record that does not substitute variables.
* @evidence contracts/common.md#meaningful-documentation Each field has a one-line comment.
*/
export interface IServer {
/** Server URL. */
url: string;
/** Server description. */
description?: string;
/** URL template variables. */
variables?: Record<string, IServer.IVariable>;
}
export namespace IServer {
/**
* URL template variable.
*
* @evidence contracts/common.md#principled-implementation Each variable has a required default and optional enum and description, which is how the specification defines a server variable.
* @evidence contracts/common.md#clear-and-simple-design One record.
* @evidence contracts/common.md#prohibited-implementation-shortcuts A data record.
* @evidence contracts/common.md#meaningful-documentation Each field has a one-line comment.
*/
export interface IVariable {
/** Default value. */
default: string;
/** Allowed values. */
enum?: string[];
/** Variable description. */
description?: string;
}
}
/**
* Path item containing operations by HTTP method.
*
* @evidence contracts/common.md#principled-implementation The path item extends a partial record of method to operation, so each method is optional, and adds servers, summary, description and a map of operations for non-standard methods; this represents a path with any subset of operations.
* @evidence contracts/common.md#clear-and-simple-design Inheriting from Partial<Record<Method, IOperation>> avoids listing the methods twice.
* @evidence contracts/common.md#prohibited-implementation-shortcuts A data record; no inference of missing methods.
* @evidence contracts/common.md#meaningful-documentation Each field has a comment, with LINK and PURGE as examples of additional methods.
*/
export interface IPath extends Partial<Record<Method, IOperation>> {
/** Path-level servers. */
servers?: IServer[];
/** Path summary. */
summary?: string;
/** Path description. */
description?: string;
/**
* Additional non-standard HTTP method operations (e.g., LINK, UNLINK,
* PURGE).
*/
additionalOperations?: Record<string, IOperation>;
}
/**
* API operation metadata.
*
* @evidence contracts/common.md#principled-implementation Operation fields mirror the specification, with typia's three `x-samchon-*` extension fields for LLM exclusion, accessor naming and controller naming; `responses` is a record keyed by status code string.
* @evidence contracts/common.md#clear-and-simple-design One record; parameters, bodies, responses, content and media types are in the namespace.
* @evidence contracts/common.md#prohibited-implementation-shortcuts Extension fields are documented contract keys, and not special cases for a consumer.
* @evidence contracts/common.md#meaningful-documentation Each field has a one-line comment, including what each extension does.
*/
export interface IOperation {
/** Unique operation identifier. */
operationId?: string;
/** Operation parameters. */
parameters?: IOperation.IParameter[];
/** Request body. */
requestBody?: IOperation.IRequestBody;
/** Response definitions by status code. */
responses?: Record<string, IOperation.IResponse>;
/** Operation-level servers. */
servers?: IServer[];
/** Short summary. */
summary?: string;
/** Full description. */
description?: string;
/** Security requirements. */
security?: Record<string, string[]>[];
/** Operation tags for grouping. */
tags?: string[];
/** Whether deprecated. */
deprecated?: boolean;
/** Excludes from LLM function calling when `true`. */
"x-samchon-human"?: boolean;
/** Custom accessor path for migration. */
"x-samchon-accessor"?: string[];
/** Controller name for code generation. */
"x-samchon-controller"?: string;
}
export namespace IOperation {
/**
* Operation parameter.
*
* @evidence contracts/common.md#principled-implementation Location is a closed union including `querystring`, whose content is described by media type instead of a schema style; style and explode record serialization. Name is optional because querystring parameters have none.
* @evidence contracts/common.md#clear-and-simple-design One record with serialization fields flattened in.
* @evidence contracts/common.md#prohibited-implementation-shortcuts A data record; the style defaults are applied by consumers.
* @evidence contracts/common.md#meaningful-documentation Each field has a one-line comment, including the content-backed querystring case.
*/
export interface IParameter {
/** Parameter name. */
name?: string;
/** Parameter location. */
in: "path" | "query" | "querystring" | "header" | "cookie";
/** Normalized parameter schema. */
schema: IJsonSchema;
/** Source media types for a content-backed querystring parameter. */
content?: IContent;
/** Whether required. */
required?: boolean;
/** OpenAPI parameter serialization style. */
style?:
| "matrix"
| "label"
| "form"
| "cookie"
| "simple"
| "spaceDelimited"
| "pipeDelimited"
| "deepObject";
/** Whether arrays and objects are exploded during serialization. */
explode?: boolean;
/** Parameter description. */
description?: string;
/** Example value. */
example?: any;
/** Named examples. */
examples?: Record<string, IExample>;
}
/**
* Request body.
*
* @evidence contracts/common.md#principled-implementation Content is a map from media type to its definition; description, required and the Nestia encryption flag are optional.
* @evidence contracts/common.md#clear-and-simple-design One record.
* @evidence contracts/common.md#prohibited-implementation-shortcuts The encryption flag is a documented extension and not behavior in this type.
* @evidence contracts/common.md#meaningful-documentation Each field has a one-line comment.
*/
export interface IRequestBody {
/** Body content by media type. */
content?: IContent;
/** Body description. */
description?: string;
/** Whether required. */
required?: boolean;
/** Nestia encryption flag. */
"x-nestia-encrypted"?: boolean;
}
/**
* Response definition.
*
* @evidence contracts/common.md#principled-implementation A response has optional headers, content and description; headers reuse the parameter shape so serialization fields are expressed once.
* @evidence contracts/common.md#clear-and-simple-design One record that reuses IParameter.
* @evidence contracts/common.md#prohibited-implementation-shortcuts A data record.
* @evidence contracts/common.md#meaningful-documentation Each field has a one-line comment.
*/
export interface IResponse {
/** Response headers. */
headers?: Record<string, IOperation.IParameter>;
/** Response content by media type. */
content?: IContent;
/** Response description. */
description?: string;
/** Nestia encryption flag. */
"x-nestia-encrypted"?: boolean;
}
/**
* Content by media type.
*
* @evidence contracts/common.md#principled-implementation A partial record keyed by the content type union lets a body or response have any subset of media types.
* @evidence contracts/common.md#clear-and-simple-design An empty interface extending a partial record, giving the map a name.
* @evidence contracts/common.md#prohibited-implementation-shortcuts A data record.
* @evidence contracts/common.md#meaningful-documentation The one-line comment names it as content by media type.
*/
export interface IContent extends Partial<
Record<ContentType, IMediaType>
> {}
/**
* Media type definition.
*
* @evidence contracts/common.md#principled-implementation A media type holds an optional schema, an optional item schema for streaming media and examples, which together describe both whole-body and per-item payloads.
* @evidence contracts/common.md#clear-and-simple-design One record.
* @evidence contracts/common.md#prohibited-implementation-shortcuts A data record.
* @evidence contracts/common.md#meaningful-documentation Each field has a one-line comment, naming SSE and JSON Lines for the item schema.
*/
export interface IMediaType {
/** Content schema. */
schema?: IJsonSchema;
/** Schema for streaming items (SSE, JSON Lines, etc.). */
itemSchema?: IJsonSchema;
/** Example value. */
example?: any;
/** Named examples. */
examples?: Record<string, IExample>;
}
/**
* Supported content types.
*
* @evidence contracts/common.md#principled-implementation Known media types are literal suggestions and string & {} admits arbitrary media types. The URL-encoded suggestion uses application/x-www-form-urlencoded, matching the HTTP migration and fetcher contract.
* @evidence contracts/common.md#clear-and-simple-design One alias.
* @evidence contracts/common.md#prohibited-implementation-shortcuts A literal union; no content negotiation is implemented here.
* @evidence contracts/common.md#meaningful-documentation The one-line comment says it lists supported content types.
*/
export type ContentType =
| "text/plain"
| "application/json"
| "application/x-www-form-urlencoded"
| "multipart/form-data"
| "*/*"
| (string & {});
}
/**
* Example value definition.
*
* @evidence contracts/common.md#principled-implementation An example has optional summary, description, inline value and external value, matching the specification's example object.
* @evidence contracts/common.md#clear-and-simple-design One record.
* @evidence contracts/common.md#prohibited-implementation-shortcuts A data record.
* @evidence contracts/common.md#meaningful-documentation Each field has a one-line comment.
*/
export interface IExample {
/** Example summary. */
summary?: string;
/** Example description. */
description?: string;
/** Example value. */
value?: any;
/** External value URL. */
externalValue?: string;
}
/**
* Reusable components storage.
*
* @evidence contracts/common.md#principled-implementation Only schemas and security schemes are kept, because the emended form inlines other component kinds.
* @evidence contracts/common.md#clear-and-simple-design Optional maps.
* @evidence contracts/common.md#prohibited-implementation-shortcuts A data record.
* @evidence contracts/common.md#meaningful-documentation The comment says it is a reusable component store and each field has a comment.
*/
export interface IComponents {
/** Named schemas. */
schemas?: Record<string, IJsonSchema>;
/** Named security schemes. */
securitySchemes?: Record<string, ISecurityScheme>;
}
/**
* JSON Schema type for emended OpenAPI v3.1.
*
* Represents all possible JSON Schema types in the normalized OpenAPI format.
* This is a discriminated union - check the `type` property or use type
* guards to narrow to specific schema types.
*
* Unlike raw JSON Schema, this format:
*
* - Uses `oneOf` instead of `anyOf` for union types
* - Separates `IArray` (homogeneous) from `ITuple` (heterogeneous)
* - Normalizes nullable types to `oneOf` with null schema
*
* @evidence contracts/common.md#principled-implementation A union of variants discriminated by `type`, `const`, `$ref`, `oneOf` or their absence, where tuples are separated from arrays and unions use oneOf, so a schema consumer narrows structurally with no ambiguity between old spellings.
* @evidence contracts/common.md#clear-and-simple-design One alias over variants declared in the same-named namespace.
* @evidence contracts/common.md#prohibited-implementation-shortcuts It expresses the normalized form only; legacy spellings are not accepted by the type.
* @evidence contracts/common.md#meaningful-documentation The comment states how the format differs from raw JSON Schema.
*/
export type IJsonSchema =
| IJsonSchema.IConstant
| IJsonSchema.IBoolean
| IJsonSchema.IInteger
| IJsonSchema.INumber
| IJsonSchema.IString
| IJsonSchema.IArray
| IJsonSchema.ITuple
| IJsonSchema.IObject
| IJsonSchema.IReference
| IJsonSchema.IOneOf
| IJsonSchema.INull
| IJsonSchema.IUnknown;
export namespace IJsonSchema {
/**
* Constant value type.
*
* @evidence contracts/common.md#principled-implementation A `const` of boolean, number or string; it extends the attribute record without a type discriminator because the value determines the type.
* @evidence contracts/common.md#clear-and-simple-design One field on the shared attribute record.
* @evidence contracts/common.md#prohibited-implementation-shortcuts A data record.
* @evidence contracts/common.md#meaningful-documentation One-line comments on the type and the field.
*/
export interface IConstant extends IJsonSchemaAttribute {
/** Constant value. */
const: boolean | number | string;
}
/**
* Boolean type.
*
* @evidence contracts/common.md#principled-implementation The boolean variant adds only an optional default to the boolean attribute record, because boolean admits no further constraints.
* @evidence contracts/common.md#clear-and-simple-design One optional field.
* @evidence contracts/common.md#prohibited-implementation-shortcuts A data record.
* @evidence contracts/common.md#meaningful-documentation One-line comments on the type and the field.
*/
export interface IBoolean extends IJsonSchemaAttribute.IBoolean {
/** Default value. */
default?: boolean;
}
/**
* Integer type.
*
* @evidence contracts/common.md#principled-implementation Bounds and default are typed as int64 numbers, and multipleOf is a number above zero, matching the JSON Schema integer keywords while limiting numbers to the 64-bit range typia generates.
* @evidence contracts/common.md#clear-and-simple-design Optional keywords on the integer attribute record.
* @evidence contracts/common.md#prohibited-implementation-shortcuts The type tags declare ranges and no check is performed in the declaration.
* @evidence contracts/common.md#meaningful-documentation Each field has a one-line comment.
*/
export interface IInteger extends IJsonSchemaAttribute.IInteger {
/** Default value. */
default?: number & tags.Type<"int64">;
/** Minimum value. */
minimum?: number & tags.Type<"int64">;
/** Maximum value. */
maximum?: number & tags.Type<"int64">;
/** Exclusive minimum. */
exclusiveMinimum?: number & tags.Type<"int64">;
/** Exclusive maximum. */
exclusiveMaximum?: number & tags.Type<"int64">;
/** Multiple of constraint. */
multipleOf?: number & tags.ExclusiveMinimum<0>;
}
/**
* Number (double) type.
*
* @evidence contracts/common.md#principled-implementation Bounds, default and multipleOf use plain numbers, with multipleOf above zero.
* @evidence contracts/common.md#clear-and-simple-design Optional keywords on the number attribute record.
* @evidence contracts/common.md#prohibited-implementation-shortcuts A data record.
* @evidence contracts/common.md#meaningful-documentation Each field has a one-line comment.
*/
export interface INumber extends IJsonSchemaAttribute.INumber {
/** Default value. */
default?: number;
/** Minimum value. */
minimum?: number;
/** Maximum value. */
maximum?: number;
/** Exclusive minimum. */
exclusiveMinimum?: number;
/** Exclusive maximum. */
exclusiveMaximum?: number;
/** Multiple of constraint. */
multipleOf?: number & tags.ExclusiveMinimum<0>;
}
/**
* String type.
*
* @evidence contracts/common.md#principled-implementation Format is the known set or any string, pattern and content keywords are strings, and length bounds are unsigned 64-bit; the content encoding field is included in the normalized form.
* @evidence contracts/common.md#clear-and-simple-design Optional keywords on the string attribute record.
* @evidence contracts/common.md#prohibited-implementation-shortcuts A data record that does not validate pattern or format.
* @evidence contracts/common.md#meaningful-documentation Each field has a one-line comment.
*/
export interface IString extends IJsonSchemaAttribute.IString {
/** Default value. */
default?: string;
/** String format. */
format?:
| "binary"
| "byte"
| "password"
| "regex"
| "uuid"
| "email"
| "hostname"
| "idn-email"
| "idn-hostname"
| "iri"
| "iri-reference"
| "ipv4"
| "ipv6"
| "uri"
| "uri-reference"
| "uri-template"
| "url"
| "date-time"
| "date"
| "time"
| "duration"
| "json-pointer"
| "relative-json-pointer"
| (string & {});
/** Regex pattern. */
pattern?: string;
/** Content media type. */
contentMediaType?: string;
/** Content encoding. */
contentEncoding?: string;
/** Minimum length. */
minLength?: number & tags.Type<"uint64">;
/** Maximum length. */
maxLength?: number & tags.Type<"uint64">;
}
/**
* Array type.
*
* @evidence contracts/common.md#principled-implementation A required item schema and optional uniqueness and size bounds describe homogeneous arrays; tuples have their own variant so `items` is never an array here.
* @evidence contracts/common.md#clear-and-simple-design Fields on the array attribute record.
* @evidence contracts/common.md#prohibited-implementation-shortcuts A data record.
* @evidence contracts/common.md#meaningful-documentation Each field has a one-line comment.
*/
export interface IArray extends IJsonSchemaAttribute.IArray {
/** Element type. */
items: IJsonSchema;
/** Whether elements must be unique. */
uniqueItems?: boolean;
/** Minimum items. */
minItems?: number & tags.Type<"uint64">;
/** Maximum items. */
maxItems?: number & tags.Type<"uint64">;
}
/**
* Tuple type.
*
* @evidence contracts/common.md#principled-implementation The normalized tuple has an array discriminator, ordered prefixItems, optional additionalItems for its rest and its own bounds. additionalItems is typia's normalized rest field; JSON Schema 2020-12 uses items alongside prefixItems instead. Converters own that dialect mapping.
* @evidence contracts/common.md#clear-and-simple-design Separate from IArray so a consumer distinguishes tuple from array by shape.
* @evidence contracts/common.md#prohibited-implementation-shortcuts A data record.
* @evidence contracts/common.md#meaningful-documentation Each field has a one-line comment.
*/
export interface ITuple extends IJsonSchemaAttribute {
/** Type discriminator. */
type: "array";
/** Tuple element types. */
prefixItems: IJsonSchema[];
/** Rest element type or `true` for any. */
additionalItems?: boolean | IJsonSchema;
/** Whether elements must be unique. */
uniqueItems?: boolean;
/** Minimum items. */
minItems?: number & tags.Type<"uint64">;
/** Maximum items. */
maxItems?: number & tags.Type<"uint64">;
}
/**
* Object type.
*
* @evidence contracts/common.md#principled-implementation Properties, additional properties and required names are all optional, and additionalProperties is a boolean or a schema as in JSON Schema.
* @evidence contracts/common.md#clear-and-simple-design Optional fields on the object attribute record.
* @evidence contracts/common.md#prohibited-implementation-shortcuts A data record.
* @evidence contracts/common.md#meaningful-documentation Each field has a one-line comment.
*/
export interface IObject extends IJsonSchemaAttribute.IObject {
/** Property schemas. */
properties?: Record<string, IJsonSchema>;
/** Additional properties schema or `true` for any. */
additionalProperties?: boolean | IJsonSchema;
/** Required property names. */
required?: string[];
}
/**
* Reference to named schema.
*
* @evidence contracts/common.md#principled-implementation The key type parameter defaults to string and is the type of `$ref`, which lets a stricter key shape be used by callers that need it.
* @evidence contracts/common.md#clear-and-simple-design One generic field on the attribute record.
* @evidence contracts/common.md#prohibited-implementation-shortcuts A data record that does not resolve references.
* @evidence contracts/common.md#meaningful-documentation The comment gives the reference path format.
*/
export interface IReference<Key = string> extends IJsonSchemaAttribute {
/** Reference path (e.g., `#/components/schemas/TypeName`). */
$ref: Key;
}
/**
* Union type (`oneOf`).
*
* @evidence contracts/common.md#principled-implementation Union members exclude nested oneOf so unions are flat, with an optional discriminator, which is how the normalized form represents unions.
* @evidence contracts/common.md#clear-and-simple-design Two fields.
* @evidence contracts/common.md#prohibited-implementation-shortcuts Flattening is expressed by the type and not performed here.
* @evidence contracts/common.md#meaningful-documentation The comment says it is the normalized union and each field is described.
*/
export interface IOneOf extends IJsonSchemaAttribute {
/** Union member schemas. */
oneOf: Exclude<IJsonSchema, IJsonSchema.IOneOf>[];
/** Discriminator for tagged unions. */
discriminator?: IOneOf.IDiscriminator;
}
export namespace IOneOf {
/**
* Discriminator for tagged unions.
*
* @evidence contracts/common.md#principled-implementation A property name and an optional value-to-reference map describe the variant selector of a tagged union.
* @evidence contracts/common.md#clear-and-simple-design Two fields.
* @evidence contracts/common.md#prohibited-implementation-shortcuts A data record that does not verify that variants carry the property.
* @evidence contracts/common.md#meaningful-documentation Each field has a one-line comment.
*/
export interface IDiscriminator {
/** Discriminator property name. */
propertyName: string;
/** Value to schema mapping. */
mapping?: Record<string, string>;
}
}
/**
* Null type.
*
* @evidence contracts/common.md#principled-implementation The null variant has type null and an optional default of null, the only value it admits.
* @evidence contracts/common.md#clear-and-simple-design One optional field.
* @evidence contracts/common.md#prohibited-implementation-shortcuts A data record.
* @evidence contracts/common.md#meaningful-documentation One-line comments on the type and the field.
*/
export interface INull extends IJsonSchemaAttribute.INull {
/** Default value. */
default?: null;
}
/**
* Unknown (`any`) type.
*
* @evidence contracts/common.md#principled-implementation A schema with no type and an optional default of any value represents an unconstrained value.
* @evidence contracts/common.md#clear-and-simple-design One optional field on the unknown attribute record.
* @evidence contracts/common.md#prohibited-implementation-shortcuts A data record.
* @evidence contracts/common.md#meaningful-documentation One-line comments on the type and the field.
*/
export interface IUnknown extends IJsonSchemaAttribute.IUnknown {
/** Default value. */
default?: any;
}
}
/**
* Security scheme types.
*
* @evidence contracts/common.md#principled-implementation A union of five schemes, discriminated by `type` and, for HTTP, by `scheme`, so each authentication method has the fields it needs and no others.
* @evidence contracts/common.md#clear-and-simple-design One alias over five records in the same-named namespace.
* @evidence contracts/common.md#prohibited-implementation-shortcuts A representation of credentials requirements; no secrets or checks.
* @evidence contracts/common.md#meaningful-documentation The one-line comment names it as the security scheme types.
*/
export type ISecurityScheme =
| ISecurityScheme.IApiKey
| ISecurityScheme.IHttpBasic
| ISecurityScheme.IHttpBearer
| ISecurityScheme.IOAuth2
| ISecurityScheme.IOpenId;
export namespace ISecurityScheme {
/**
* API key authentication.
*
* @evidence contracts/common.md#principled-implementation The `apiKey` scheme with an optional location among header, query and cookie and an optional name.
* @evidence contracts/common.md#clear-and-simple-design One record.
* @evidence contracts/common.md#prohibited-implementation-shortcuts A data record.
* @evidence contracts/common.md#meaningful-documentation Each field has a one-line comment.
*/
export interface IApiKey {
/** Scheme type. */
type: "apiKey";
/** Key location. */
in?: "header" | "query" | "cookie";
/** Key name. */
name?: string;
/** Scheme description. */
description?: string;
}
/**
* HTTP basic authentication.
*
* @evidence contracts/common.md#principled-implementation The `http` type with the literal scheme `basic`, which is how the specification expresses HTTP basic authentication.
* @evidence contracts/common.md#clear-and-simple-design A separate record from bearer because the schemes carry different fields.
* @evidence contracts/common.md#prohibited-implementation-shortcuts A data record.
* @evidence contracts/common.md#meaningful-documentation Each field has a one-line comment.
*/
export interface IHttpBasic {
/** Scheme type. */
type: "http";
/** Authentication scheme. */
scheme: "basic";
/** Scheme description. */
description?: string;
}
/**
* HTTP bearer authentication.
*
* @evidence contracts/common.md#principled-implementation The `http` type with the literal scheme `bearer` and an optional format hint for the token.
* @evidence contracts/common.md#clear-and-simple-design A separate record from basic because only bearer has a format hint.
* @evidence contracts/common.md#prohibited-implementation-shortcuts A data record.
* @evidence contracts/common.md#meaningful-documentation Each field has a one-line comment.
*/
export interface IHttpBearer {
/** Scheme type. */
type: "http";
/** Authentication scheme. */
scheme: "bearer";
/** Bearer token format hint. */
bearerFormat?: string;
/** Scheme description. */
description?: string;
}
/**
* OAuth2 authentication.
*
* @evidence contracts/common.md#principled-implementation The `oauth2` type with a required flow set and an optional metadata discovery URL.
* @evidence contracts/common.md#clear-and-simple-design One record; flow records are in the namespace.
* @evidence contracts/common.md#prohibited-implementation-shortcuts A data record.
* @evidence contracts/common.md#meaningful-documentation Each field has a one-line comment.
*/
export interface IOAuth2 {
/** Scheme type. */
type: "oauth2";
/** OAuth2 flows. */
flows: IOAuth2.IFlowSet;
/** OAuth2 metadata discovery URL. */
oauth2MetadataUrl?: string;
/** Scheme description. */
description?: string;
}
/**
* OpenID Connect authentication.
*
* @evidence contracts/common.md#principled-implementation The `openIdConnect` type with a required discovery URL.
* @evidence contracts/common.md#clear-and-simple-design One record.
* @evidence contracts/common.md#prohibited-implementation-shortcuts A data record.
* @evidence contracts/common.md#meaningful-documentation Each field has a one-line comment.
*/
export interface IOpenId {
/** Scheme type. */
type: "openIdConnect";
/** OpenID Connect discovery URL. */
openIdConnectUrl: string;
/** Scheme description. */
description?: string;
}
export namespace IOAuth2 {
/**
* OAuth2 flow configurations.
*
* @evidence contracts/common.md#principled-implementation Each flow is optional, and Omit removes the URL that the flow does not use: no token URL for implicit and no authorization URL for password and client credentials; device authorization has its own record.
* @evidence contracts/common.md#clear-and-simple-design One record with Omit used so the shared flow shape is not repeated.
* @evidence contracts/common.md#prohibited-implementation-shortcuts A data record.
* @evidence contracts/common.md#meaningful-documentation Each field names its flow.
*/
export interface IFlowSet {
/** Authorization code flow. */
authorizationCode?: IFlow;
/** Implicit flow. */
implicit?: Omit<IFlow, "tokenUrl">;
/** Password flow. */
password?: Omit<IFlow, "authorizationUrl">;
/** Client credentials flow. */
clientCredentials?: Omit<IFlow, "authorizationUrl">;
/** Device authorization flow. */
deviceAuthorization?: IDeviceFlow;
}
/**
* OAuth2 flow configuration.
*
* @evidence contracts/common.md#principled-implementation Authorization, token and refresh URLs and scopes are all optional, since which are required depends on the flow and the flow set removes the unused ones.
* @evidence contracts/common.md#clear-and-simple-design One record shared by several flows.
* @evidence contracts/common.md#prohibited-implementation-shortcuts A data record.
* @evidence contracts/common.md#meaningful-documentation Each field has a one-line comment.
*/
export interface IFlow {
/** Authorization URL. */
authorizationUrl?: string;
/** Token URL. */
tokenUrl?: string;
/** Refresh URL. */
refreshUrl?: string;
/** Available scopes. */
scopes?: Record<string, string>;
}
/**
* OAuth2 device authorization flow.
*
* @evidence contracts/common.md#principled-implementation The device authorization URL and token URL are required and refresh URL and scopes are optional, as the device grant needs both endpoints.
* @evidence contracts/common.md#clear-and-simple-design A separate record because its required fields differ from IFlow.
* @evidence contracts/common.md#prohibited-implementation-shortcuts A data record.
* @evidence contracts/common.md#meaningful-documentation Each field has a one-line comment.
*/
export interface IDeviceFlow {
/** Device authorization URL. */
deviceAuthorizationUrl: string;
/** Token URL. */
tokenUrl: string;
/** Refresh URL. */
refreshUrl?: string;
/** Available scopes. */
scopes?: Record<string, string>;
}
}
}
}undefined
import { IJsonSchemaAttribute } from "../schema/IJsonSchemaAttribute";
import * as tags from "../tags";
/**
* OpenAPI v3.0 specification types.
*
* `OpenApiV3` contains TypeScript type definitions for OpenAPI v3.0 documents.
* Used for parsing and generating OpenAPI v3.0 specifications. For a normalized
* format that unifies all OpenAPI versions, use {@link OpenApi} instead.
*
* Key differences from v3.1:
*
* - Uses `nullable: true` instead of `type: ["string", "null"]`
* - No `const` keyword support
* - No `prefixItems` for tuples
*
* @author Jeongho Nam - https://github.com/samchon
*
* @evidence contracts/common.md#principled-implementation The namespace describes the supported OpenAPI 3.0 fields, including nullable, boolean exclusive bounds and allOf. It is a structural input model, not a complete specification validator or a promise of lossless parsing of every field; the utils converter owns normalization.
* @evidence contracts/common.md#clear-and-simple-design One namespace with the same member layout as the sibling version namespaces, so converters can be written version by version without cross-references between them.
* @evidence contracts/common.md#prohibited-implementation-shortcuts It describes an input format and does not convert or normalize it; conversion is in the utils package.
* @evidence contracts/common.md#meaningful-documentation The comment lists the main 3.0 differences and links the normalized type.
*/
export namespace OpenApiV3 {
/**
* HTTP method of the operation.
*
* @evidence contracts/common.md#principled-implementation The eight methods that a 3.0 path item can hold; `query` is omitted because it appears only in 3.2.
* @evidence contracts/common.md#clear-and-simple-design One alias used by IPath.
* @evidence contracts/common.md#prohibited-implementation-shortcuts A literal union.
* @evidence contracts/common.md#meaningful-documentation The one-line comment names it as the HTTP method of an operation.
*/
export type Method =
| "get"
| "post"
| "put"
| "delete"
| "options"
| "head"
| "patch"
| "trace";
/* -----------------------------------------------------------
DOCUMENTS
----------------------------------------------------------- */
/**
* OpenAPI document structure.
*
* @evidence contracts/common.md#principled-implementation The version accepts 3.0 and patch spellings, and sections are optional for structural compatibility. This is more permissive than the specification, which requires info and paths; the declaration does not validate a complete document.
* @evidence contracts/common.md#clear-and-simple-design One flat record with metadata types in its namespace.
* @evidence contracts/common.md#prohibited-implementation-shortcuts A data record.
* @evidence contracts/common.md#meaningful-documentation Each field has a one-line comment.
*/
export interface IDocument {
/** OpenAPI version. */
openapi: "3.0" | `3.0.${number}`;
/** List of servers. */
servers?: IServer[];
/** API metadata. */
info?: IDocument.IInfo;
/** Reusable components. */
components?: IComponents;
/** API paths and operations. */
paths?: Record<string, IPath>;
/** Global security requirements. */
security?: Record<string, string[]>[];
/** Tag definitions. */
tags?: IDocument.ITag[];
}
export namespace IDocument {
/**
* API metadata.
*
* @evidence contracts/common.md#principled-implementation Title and version are required; the record has no `summary` because 3.0 does not define one.
* @evidence contracts/common.md#clear-and-simple-design One record.
* @evidence contracts/common.md#prohibited-implementation-shortcuts A data record.
* @evidence contracts/common.md#meaningful-documentation Each field has a one-line comment.
*/
export interface IInfo {
/** API title. */
title: string;
/** API description. */
description?: string;
/** Terms of service URL. */
termsOfService?: string;
/** Contact information. */
contact?: IContact;
/** License information. */
license?: ILicense;
/** API version. */
version: string;
}
/**
* Tag for grouping operations.
*
* @evidence contracts/common.md#principled-implementation A name with an optional description, which is all 3.0 defines for a tag.
* @evidence contracts/common.md#clear-and-simple-design One record.
* @evidence contracts/common.md#prohibited-implementation-shortcuts A data record.
* @evidence contracts/common.md#meaningful-documentation Each field has a one-line comment.
*/
export interface ITag {
/** Tag name. */
name: string;
/** Tag description. */
description?: string;
}
/**
* Contact information.
*
* @evidence contracts/common.md#principled-implementation All three fields are optional and the email carries the Format email tag.
* @evidence contracts/common.md#clear-and-simple-design One record.
* @evidence contracts/common.md#prohibited-implementation-shortcuts The tag is a declared constraint, not a check performed here.
* @evidence contracts/common.md#meaningful-documentation Each field has a one-line comment.
*/
export interface IContact {
/** Contact name. */
name?: string;
/** Contact URL. */
url?: string;
/** Contact email. */
email?: string & tags.Format<"email">;
}
/**
* License information.
*
* @evidence contracts/common.md#principled-implementation A name and an optional URL, with no SPDX identifier since 3.0 lacks it.
* @evidence contracts/common.md#clear-and-simple-design One record.
* @evidence contracts/common.md#prohibited-implementation-shortcuts A data record.
* @evidence contracts/common.md#meaningful-documentation Each field has a one-line comment.
*/
export interface ILicense {
/** License name. */
name: string;
/** License URL. */
url?: string;
}
}
/**
* Server providing the API.
*
* @evidence contracts/common.md#principled-implementation A required URL with optional description and template variables.
* @evidence contracts/common.md#clear-and-simple-design One record.
* @evidence contracts/common.md#prohibited-implementation-shortcuts A data record.
* @evidence contracts/common.md#meaningful-documentation Each field has a one-line comment.
*/
export interface IServer {
/** Server URL. */
url: string;
/** Server description. */
description?: string;
/** URL template variables. */
variables?: Record<string, IServer.IVariable>;
}
export namespace IServer {
/**
* URL template variable.
*
* @evidence contracts/common.md#principled-implementation A required default with optional enum and description.
* @evidence contracts/common.md#clear-and-simple-design One record.
* @evidence contracts/common.md#prohibited-implementation-shortcuts A data record.
* @evidence contracts/common.md#meaningful-documentation Each field has a one-line comment.
*/
export interface IVariable {
/** Default value. */
default: string;
/** Allowed values. */
enum?: string[];
/** Variable description. */
description?: string;
}
}
/* -----------------------------------------------------------
PATH ITEMS
----------------------------------------------------------- */
/**
* Path item containing operations by HTTP method.
*
* @evidence contracts/common.md#principled-implementation A partial method map whose values may be undefined, plus path-level parameters that may be inline or `$ref` forms to the headers or parameters component, servers, summary and description, and an `x-additionalOperations` extension used when a 3.2 document is downgraded to carry non-standard methods.
* @evidence contracts/common.md#clear-and-simple-design The reference alternatives are spelled out as template-literal reference types instead of a free string.
* @evidence contracts/common.md#prohibited-implementation-shortcuts The extension is a documented downgrade channel and is not a special case for a consumer.
* @evidence contracts/common.md#meaningful-documentation Each field has a comment, and the extension explains why it exists.
*/
export interface IPath extends Partial<
Record<Method, IOperation | undefined>
> {
/** Path-level parameters. */
parameters?: Array<
| IOperation.IParameter
| IJsonSchema.IReference<`#/components/headers/${string}`>
| IJsonSchema.IReference<`#/components/parameters/${string}`>
>;
/** Path-level servers. */
servers?: IServer[];
/** Path summary. */
summary?: string;
/** Path description. */
description?: string;
/**
* Non-standard HTTP method operations (extension).
*
* Used when downgrading from OpenAPI v3.2 to preserve non-standard methods
* like `query` or custom methods.
*/
"x-additionalOperations"?: Record<string, IOperation>;
}
/**
* API operation metadata.
*
* @evidence contracts/common.md#principled-implementation Parameters, request bodies and responses may each be inline or `$ref` forms, with the component path prefixes typed as template literals; there are no typia extension fields because those exist only on the emended form.
* @evidence contracts/common.md#clear-and-simple-design One record; the inline forms are in the namespace.
* @evidence contracts/common.md#prohibited-implementation-shortcuts A data record.
* @evidence contracts/common.md#meaningful-documentation Each field has a one-line comment.
*/
export interface IOperation {
/** Unique operation identifier. */
operationId?: string;
/** Operation parameters. */
parameters?: Array<
| IOperation.IParameter
| IJsonSchema.IReference<`#/components/headers/${string}`>
| IJsonSchema.IReference<`#/components/parameters/${string}`>
>;
/** Request body. */
requestBody?:
| IOperation.IRequestBody
| IJsonSchema.IReference<`#/components/requestBodies/${string}`>;
/** Response definitions by status code. */
responses?: Record<
string,
| IOperation.IResponse
| IJsonSchema.IReference<`#/components/responses/${string}`>
>;
/** Operation-level servers. */
servers?: IServer[];
/** Short summary. */
summary?: string;
/** Full description. */
description?: string;
/** Security requirements. */
security?: Record<string, string[]>[];
/** Operation tags. */
tags?: string[];
/** Whether deprecated. */
deprecated?: boolean;
}
export namespace IOperation {
/**
* Operation parameter.
*
* @evidence contracts/common.md#principled-implementation Location is the four 3.0 values with no querystring, and style covers the 3.0 styles; schema is required for these parameters.
* @evidence contracts/common.md#clear-and-simple-design One record.
* @evidence contracts/common.md#prohibited-implementation-shortcuts A data record.
* @evidence contracts/common.md#meaningful-documentation Each field has a one-line comment.
*/
export interface IParameter {
/** Parameter name. */
name?: string;
/** Parameter location. */
in: "path" | "query" | "header" | "cookie";
/** Parameter schema. */
schema: IJsonSchema;
/** Whether required. */
required?: boolean;
/** Parameter serialization style. */
style?:
| "matrix"
| "label"
| "form"
| "simple"
| "spaceDelimited"
| "pipeDelimited"
| "deepObject";
/** Whether arrays and objects are exploded during serialization. */
explode?: boolean;
/** Parameter description. */
description?: string;
/** Example value. */
example?: any;
/** Named examples. */
examples?: Record<
string,
IExample | IJsonSchema.IReference<`#/components/examples/${string}`>
>;
}
/**
* Request body.
*
* @evidence contracts/common.md#principled-implementation Optional description, required flag and a map from media type string to media type record.
* @evidence contracts/common.md#clear-and-simple-design One record.
* @evidence contracts/common.md#prohibited-implementation-shortcuts A data record.
* @evidence contracts/common.md#meaningful-documentation Each field has a one-line comment.
*/
export interface IRequestBody {
/** Body description. */
description?: string;
/** Whether required. */
required?: boolean;
/** Body content by media type. */
content?: Record<string, IMediaType>;
}
/**
* Response definition.
*
* @evidence contracts/common.md#principled-implementation Content, headers and description are optional; response headers are parameters without their location or `$ref` forms, since a header's location is fixed.
* @evidence contracts/common.md#clear-and-simple-design One record.
* @evidence contracts/common.md#prohibited-implementation-shortcuts A data record.
* @evidence contracts/common.md#meaningful-documentation Each field has a one-line comment.
*/
export interface IResponse {
/** Response content by media type. */
content?: Record<string, IMediaType>;
/** Response headers. */
headers?: Record<
string,
| Omit<IOperation.IParameter, "in">
| IJsonSchema.IReference<`#/components/headers/${string}`>
>;
/** Response description. */
description?: string;
}
/**
* Media type definition.
*
* @evidence contracts/common.md#principled-implementation Optional schema, example and named examples, where each named example may be a `$ref` to the examples component.
* @evidence contracts/common.md#clear-and-simple-design One record.
* @evidence contracts/common.md#prohibited-implementation-shortcuts A data record.
* @evidence contracts/common.md#meaningful-documentation Each field has a one-line comment.
*/
export interface IMediaType {
/** Content schema. */
schema?: IJsonSchema;
/** Example value. */
example?: any;
/** Named examples. */
examples?: Record<
string,
IExample | IJsonSchema.IReference<`#/components/examples/${string}`>
>;
}
}
/**
* Example value definition.
*
* @evidence contracts/common.md#principled-implementation Optional summary, description, inline value and external value URL.
* @evidence contracts/common.md#clear-and-simple-design One record.
* @evidence contracts/common.md#prohibited-implementation-shortcuts A data record.
* @evidence contracts/common.md#meaningful-documentation Each field has a one-line comment.
*/
export interface IExample {
/** Example summary. */
summary?: string;
/** Example description. */
description?: string;
/** Example value. */
value?: any;
/** External value URL. */
externalValue?: string;
}
/* -----------------------------------------------------------
SCHEMA DEFINITIONS
----------------------------------------------------------- */
/**
* Reusable components storage.
*
* @evidence contracts/common.md#principled-implementation The record represents seven reusable component maps: schemas, responses, parameters, request bodies, security schemes, headers and examples. It does not enumerate the specification's callbacks and links maps or resolve references.
* @evidence contracts/common.md#clear-and-simple-design Optional maps.
* @evidence contracts/common.md#prohibited-implementation-shortcuts A data record.
* @evidence contracts/common.md#meaningful-documentation Each field has a one-line comment.
*/
export interface IComponents {
/** Named schemas. */
schemas?: Record<string, IJsonSchema>;
/** Named responses. */
responses?: Record<string, IOperation.IResponse>;
/** Named parameters. */
parameters?: Record<string, IOperation.IParameter>;
/** Named request bodies. */
requestBodies?: Record<string, IOperation.IRequestBody>;
/** Named security schemes. */
securitySchemes?: Record<string, ISecurityScheme>;
/** Named headers. */
headers?: Record<string, Omit<IOperation.IParameter, "in">>;
/** Named examples. */
examples?: Record<string, IExample>;
}
/**
* JSON Schema type for OpenAPI v3.0.
*
* @evidence contracts/common.md#principled-implementation A union of variants where `nullable` is a flag on each typed variant and `allOf`, `anyOf` and `oneOf` are separate, as in 3.0, so legacy spellings are representable without being emended.
* @evidence contracts/common.md#clear-and-simple-design One alias over variants in the same-named namespace.
* @evidence contracts/common.md#prohibited-implementation-shortcuts It represents the input format and does not normalize it.
* @evidence contracts/common.md#meaningful-documentation The one-line comment names the version.
*/
export type IJsonSchema =
| IJsonSchema.IBoolean
| IJsonSchema.IInteger
| IJsonSchema.INumber
| IJsonSchema.IString
| IJsonSchema.IArray
| IJsonSchema.IObject
| IJsonSchema.IReference
| IJsonSchema.IAllOf
| IJsonSchema.IAnyOf
| IJsonSchema.IOneOf
| IJsonSchema.INullOnly
| IJsonSchema.IUnknown;
export namespace IJsonSchema {
/**
* Boolean type.
*
* @evidence contracts/common.md#principled-implementation The boolean variant takes the boolean attribute record without `examples`, because 3.0 has only `example`, and adds nullable, default and enum, where both may include null.
* @evidence contracts/common.md#clear-and-simple-design Optional fields.
* @evidence contracts/common.md#prohibited-implementation-shortcuts A data record.
* @evidence contracts/common.md#meaningful-documentation Each field has a one-line comment.
*/
export interface IBoolean
extends Omit<IJsonSchemaAttribute.IBoolean, "examples">, __IAttribute {
/** Whether nullable. */
nullable?: boolean;
/** Default value. */
default?: boolean | null;
/** Allowed values. */
enum?: Array<boolean | null>;
}
/**
* Integer type.
*
* @evidence contracts/common.md#principled-implementation As for the integer type in the normalized form, with 3.0's `nullable`, enum with null and exclusive bounds that may be a number or the older boolean flag.
* @evidence contracts/common.md#clear-and-simple-design Optional keywords on the integer attribute record.
* @evidence contracts/common.md#prohibited-implementation-shortcuts The boolean exclusive form is a 3.0 spelling kept for fidelity and not converted here.
* @evidence contracts/common.md#meaningful-documentation Each field has a one-line comment.
*/
export interface IInteger
extends Omit<IJsonSchemaAttribute.IInteger, "examples">, __IAttribute {
/** Whether nullable. */
nullable?: boolean;
/** Default value. */
default?: (number & tags.Type<"int64">) | null;
/** Allowed values. */
enum?: Array<(number & tags.Type<"int64">) | null>;
/** Minimum value. */
minimum?: number & tags.Type<"int64">;
/** Maximum value. */
maximum?: number & tags.Type<"int64">;
/** Exclusive minimum. */
exclusiveMinimum?: number | boolean;
/** Exclusive maximum. */
exclusiveMaximum?: number | boolean;
/** Multiple of constraint. */
multipleOf?: number & tags.ExclusiveMinimum<0>;
}
/**
* Number (double) type.
*
* @evidence contracts/common.md#principled-implementation Number keywords as in integer without the int64 tag, including nullable, enum with null and exclusive bounds as a number or a boolean.
* @evidence contracts/common.md#clear-and-simple-design Optional keywords on the number attribute record.
* @evidence contracts/common.md#prohibited-implementation-shortcuts A data record.
* @evidence contracts/common.md#meaningful-documentation Each field has a one-line comment.
*/
export interface INumber
extends Omit<IJsonSchemaAttribute.INumber, "examples">, __IAttribute {
/** Whether nullable. */
nullable?: boolean;
/** Default value. */
default?: number | null;
/** Allowed values. */
enum?: Array<number | null>;
/** Minimum value. */
minimum?: number;
/** Maximum value. */
maximum?: number;
/** Exclusive minimum. */
exclusiveMinimum?: number | boolean;
/** Exclusive maximum. */
exclusiveMaximum?: number | boolean;
/** Multiple of constraint. */
multipleOf?: number & tags.ExclusiveMinimum<0>;
}
/**
* String type.
*
* @evidence contracts/common.md#principled-implementation String keywords with nullable, enum with null, format as the known set or any string, pattern and unsigned length bounds; it has no content keywords because 3.0 does not define them.
* @evidence contracts/common.md#clear-and-simple-design Optional keywords on the string attribute record.
* @evidence contracts/common.md#prohibited-implementation-shortcuts A data record.
* @evidence contracts/common.md#meaningful-documentation Each field has a one-line comment.
*/
export interface IString
extends Omit<IJsonSchemaAttribute.IString, "examples">, __IAttribute {
/** Whether nullable. */
nullable?: boolean;
/** Default value. */
default?: string | null;
/** Allowed values. */
enum?: Array<string | null>;
/** String format. */
format?:
| "binary"
| "byte"
| "password"
| "regex"
| "uuid"
| "email"
| "hostname"
| "idn-email"
| "idn-hostname"
| "iri"
| "iri-reference"
| "ipv4"
| "ipv6"
| "uri"
| "uri-reference"
| "uri-template"
| "url"
| "date-time"
| "date"
| "time"
| "duration"
| "json-pointer"
| "relative-json-pointer"
| (string & {});
/** Regex pattern. */
pattern?: string;
/** Minimum length. */
minLength?: number & tags.Type<"uint64">;
/** Maximum length. */
maxLength?: number & tags.Type<"uint64">;
}
/**
* Array type.
*
* @evidence contracts/common.md#principled-implementation A required items schema with nullable, uniqueness and unsigned size bounds; arrays here are homogeneous because 3.0 has no `prefixItems`.
* @evidence contracts/common.md#clear-and-simple-design Fields on the array attribute record.
* @evidence contracts/common.md#prohibited-implementation-shortcuts A data record.
* @evidence contracts/common.md#meaningful-documentation Each field has a one-line comment.
*/
export interface IArray
extends Omit<IJsonSchemaAttribute.IArray, "examples">, __IAttribute {
/** Whether nullable. */
nullable?: boolean;
/** Element type. */
items: IJsonSchema;
/** Whether elements must be unique. */
uniqueItems?: boolean;
/** Minimum items. */
minItems?: number & tags.Type<"uint64">;
/** Maximum items. */
maxItems?: number & tags.Type<"uint64">;
}
/**
* Object type.
*
* @evidence contracts/common.md#principled-implementation Properties, required names, additional properties and property-count bounds are all optional, with nullable, as 3.0 defines them.
* @evidence contracts/common.md#clear-and-simple-design Optional fields on the object attribute record.
* @evidence contracts/common.md#prohibited-implementation-shortcuts A data record.
* @evidence contracts/common.md#meaningful-documentation Each field has a one-line comment.
*/
export interface IObject
extends Omit<IJsonSchemaAttribute.IObject, "examples">, __IAttribute {
/** Whether nullable. */
nullable?: boolean;
/** Property schemas. */
properties?: Record<string, IJsonSchema>;
/** Required property names. */
required?: string[];
/** Additional properties schema. */
additionalProperties?: boolean | IJsonSchema;
/** Maximum properties. */
maxProperties?: number;
/** Minimum properties. */
minProperties?: number;
}
/**
* Reference to a named schema.
*
* @evidence contracts/common.md#principled-implementation A `$ref` typed by a key parameter that defaults to string, so callers such as the parameter and header unions can narrow the path prefix.
* @evidence contracts/common.md#clear-and-simple-design One generic field.
* @evidence contracts/common.md#prohibited-implementation-shortcuts A data record that does not resolve references.
* @evidence contracts/common.md#meaningful-documentation The one-line comment says it references a named schema.
*/
export interface IReference<Key = string> extends __IAttribute {
/** Reference path. */
$ref: Key;
}
/**
* All-of combination.
*
* @evidence contracts/common.md#principled-implementation A list of schemas that all must match, the 3.0 composition the emended form merges away.
* @evidence contracts/common.md#clear-and-simple-design One field.
* @evidence contracts/common.md#prohibited-implementation-shortcuts A data record that does not merge.
* @evidence contracts/common.md#meaningful-documentation The one-line comment names the combination.
*/
export interface IAllOf extends __IAttribute {
/** Schemas to combine. */
allOf: IJsonSchema[];
}
/**
* Any-of union.
*
* @evidence contracts/common.md#principled-implementation A list of member schemas of which at least one must match.
* @evidence contracts/common.md#clear-and-simple-design One field.
* @evidence contracts/common.md#prohibited-implementation-shortcuts A data record.
* @evidence contracts/common.md#meaningful-documentation The one-line comment names the union.
*/
export interface IAnyOf extends __IAttribute {
/** Union member schemas. */
anyOf: IJsonSchema[];
}
/**
* One-of union.
*
* @evidence contracts/common.md#principled-implementation A list of member schemas of which exactly one must match, with an optional discriminator for tagged unions.
* @evidence contracts/common.md#clear-and-simple-design Two fields, with the discriminator record in the namespace.
* @evidence contracts/common.md#prohibited-implementation-shortcuts A data record.
* @evidence contracts/common.md#meaningful-documentation The one-line comment names the union.
*/
export interface IOneOf extends __IAttribute {
/** Union member schemas. */
oneOf: IJsonSchema[];
/** Discriminator for tagged unions. */
discriminator?: IOneOf.IDiscriminator;
}
export namespace IOneOf {
/**
* Discriminator for tagged unions.
*
* @evidence contracts/common.md#principled-implementation A property name with an optional value to reference map.
* @evidence contracts/common.md#clear-and-simple-design Two fields.
* @evidence contracts/common.md#prohibited-implementation-shortcuts A data record.
* @evidence contracts/common.md#meaningful-documentation Each field has a one-line comment.
*/
export interface IDiscriminator {
/** Discriminator property name. */
propertyName: string;
/** Value to schema mapping. */
mapping?: Record<string, string>;
}
}
/**
* Null type.
*
* @evidence contracts/common.md#principled-implementation A null type with an optional null default; the name differs from the 3.1 variants because 3.0 expresses null only through `nullable` on other types and this is the standalone case.
* @evidence contracts/common.md#clear-and-simple-design One optional field.
* @evidence contracts/common.md#prohibited-implementation-shortcuts A data record.
* @evidence contracts/common.md#meaningful-documentation One-line comments on the type and the default.
*/
export interface INullOnly
extends Omit<IJsonSchemaAttribute.INull, "examples">, __IAttribute {
/** Default value. */
default?: null;
}
/**
* Unknown type.
*
* @evidence contracts/common.md#principled-implementation A schema with no type and an optional default of any value, representing an unconstrained value.
* @evidence contracts/common.md#clear-and-simple-design One optional field.
* @evidence contracts/common.md#prohibited-implementation-shortcuts A data record.
* @evidence contracts/common.md#meaningful-documentation One-line comments on the type and the default.
*/
export interface IUnknown
extends Omit<IJsonSchemaAttribute.IUnknown, "examples">, __IAttribute {
/** Default value. */
default?: any;
}
/** @ignore Base Attribute interface. */
export interface __IAttribute extends Omit<
IJsonSchemaAttribute,
"examples"
> {}
}
/**
* Security scheme types.
*
* @evidence contracts/common.md#principled-implementation A union of five schemes discriminated by `type` and, for http, by `scheme`.
* @evidence contracts/common.md#clear-and-simple-design One alias over five records in the same-named namespace.
* @evidence contracts/common.md#prohibited-implementation-shortcuts A representation; no secrets or checks.
* @evidence contracts/common.md#meaningful-documentation The one-line comment names the security scheme types.
*/
export type ISecurityScheme =
| ISecurityScheme.IApiKey
| ISecurityScheme.IHttpBasic
| ISecurityScheme.IHttpBearer
| ISecurityScheme.IOAuth2
| ISecurityScheme.IOpenId;
export namespace ISecurityScheme {
/**
* API key authentication.
*
* @evidence contracts/common.md#principled-implementation The `apiKey` scheme with optional location and name.
* @evidence contracts/common.md#clear-and-simple-design One record.
* @evidence contracts/common.md#prohibited-implementation-shortcuts A data record.
* @evidence contracts/common.md#meaningful-documentation Each field has a one-line comment.
*/
export interface IApiKey {
/** Scheme type. */
type: "apiKey";
/** Key location. */
in?: "header" | "query" | "cookie";
/** Key name. */
name?: string;
/** Scheme description. */
description?: string;
}
/**
* HTTP basic authentication.
*
* @evidence contracts/common.md#principled-implementation The `http` type with the literal scheme `basic`.
* @evidence contracts/common.md#clear-and-simple-design Separate from bearer because the fields differ.
* @evidence contracts/common.md#prohibited-implementation-shortcuts A data record.
* @evidence contracts/common.md#meaningful-documentation Each field has a one-line comment.
*/
export interface IHttpBasic {
/** Scheme type. */
type: "http";
/** Authentication scheme. */
scheme: "basic";
/** Scheme description. */
description?: string;
}
/**
* HTTP bearer authentication.
*
* @evidence contracts/common.md#principled-implementation The `http` type with the literal scheme `bearer` and an optional token format.
* @evidence contracts/common.md#clear-and-simple-design Separate from basic because only bearer has a format.
* @evidence contracts/common.md#prohibited-implementation-shortcuts A data record.
* @evidence contracts/common.md#meaningful-documentation Each field has a one-line comment.
*/
export interface IHttpBearer {
/** Scheme type. */
type: "http";
/** Authentication scheme. */
scheme: "bearer";
/** Bearer token format hint. */
bearerFormat?: string;
/** Scheme description. */
description?: string;
}
/**
* OAuth2 authentication.
*
* @evidence contracts/common.md#principled-implementation The `oauth2` type with required flows; it has no metadata URL because 3.0 lacks it.
* @evidence contracts/common.md#clear-and-simple-design One record.
* @evidence contracts/common.md#prohibited-implementation-shortcuts A data record.
* @evidence contracts/common.md#meaningful-documentation Each field has a one-line comment.
*/
export interface IOAuth2 {
/** Scheme type. */
type: "oauth2";
/** OAuth2 flows. */
flows: IOAuth2.IFlowSet;
/** Scheme description. */
description?: string;
}
/**
* OpenID Connect authentication.
*
* @evidence contracts/common.md#principled-implementation The `openIdConnect` type with a required discovery URL.
* @evidence contracts/common.md#clear-and-simple-design One record.
* @evidence contracts/common.md#prohibited-implementation-shortcuts A data record.
* @evidence contracts/common.md#meaningful-documentation Each field has a one-line comment.
*/
export interface IOpenId {
/** Scheme type. */
type: "openIdConnect";
/** OpenID Connect discovery URL. */
openIdConnectUrl: string;
/** Scheme description. */
description?: string;
}
export namespace IOAuth2 {
/**
* OAuth2 flow configurations.
*
* @evidence contracts/common.md#principled-implementation Four optional flows, with Omit removing the unused URL for each, and no device flow because 3.0 lacks it.
* @evidence contracts/common.md#clear-and-simple-design One record using Omit over the shared flow shape.
* @evidence contracts/common.md#prohibited-implementation-shortcuts A data record.
* @evidence contracts/common.md#meaningful-documentation Each field names its flow.
*/
export interface IFlowSet {
/** Authorization code flow. */
authorizationCode?: IFlow;
/** Implicit flow. */
implicit?: Omit<IFlow, "tokenUrl">;
/** Password flow. */
password?: Omit<IFlow, "authorizationUrl">;
/** Client credentials flow. */
clientCredentials?: Omit<IFlow, "authorizationUrl">;
}
/**
* OAuth2 flow configuration.
*
* @evidence contracts/common.md#principled-implementation Optional authorization, token and refresh URLs and scopes, since which are needed depends on the flow.
* @evidence contracts/common.md#clear-and-simple-design One record shared by several flows.
* @evidence contracts/common.md#prohibited-implementation-shortcuts A data record.
* @evidence contracts/common.md#meaningful-documentation Each field has a one-line comment.
*/
export interface IFlow {
/** Authorization URL. */
authorizationUrl?: string;
/** Token URL. */
tokenUrl?: string;
/** Refresh URL. */
refreshUrl?: string;
/** Available scopes. */
scopes?: Record<string, string>;
}
}
}
}What gets included
Anything you express in the TypeScript type carries over:
tags.Format<"uuid">โ"format": "uuid"tags.MaxLength<100>โ"maxLength": 100tags.Minimum<0>โ"minimum": 0- JSDoc description on a property โ
"description": "..."
A few JSON-Schema-only comment tags are also recognized โ they donโt affect runtime validation but they show up in the emitted schema:
| Tag | Effect |
|---|---|
@title Something | Sets title |
@deprecated | Sets deprecated: true |
@hidden / @internal | Excludes the field from the emitted schema |
TypeScript Source
import typia, { tags } from "typia";
export const SpecialCommentTagSchema = typia.json.schemas<[Special], "3.1">();
interface Special {
/**
* Deprecated tags are just used for marking.
*
* @deprecated
*
* @title Unsigned integer
*/
type: number & tags.Type<"int32">;
/**
* Internal tagged property never be shown in JSON schema.
*
* It even doesn't be shown in other `typia` functions like `assert<T>()`.
*
* @internal
*/
internal: number[];
/**
* Hidden tagged property never be shown in JSON schema.
*
* However, it would be shown in other `typia` functions like
* `stringify<T>()`.
*
* @ignore
*/
hidden: boolean;
/**
* You can limit the range of number.
*
* @exclusiveMinimum 19
*
* @maximum 100
*/
number?: number;
/**
* You can limit the length of string.
*
* Also, multiple range conditions are also possible.
*/
string: string &
(
| (tags.MinLength<3> & tags.MaxLength<24>)
| (tags.MinLength<40> & tags.MaxLength<100>)
);
/**
* You can limit the pattern of string.
*
* @pattern ^[a-z]+$
*/
pattern: string;
/**
* You can limit the format of string.
*
* @format date-time
*/
format: string | null;
/** In the Array case, possible to restrict its elements. */
array: Array<string & tags.Format<"uuid">> & tags.MinItems<3>;
}Compiled JavaScript
import typia from "typia";
export const SpecialCommentTagSchema = {
components: {
schemas: {
Special: {
type: "object",
properties: {
type: {
type: "integer",
title: "Unsigned integer",
description: "Deprecated tags are just used for marking.",
deprecated: true,
},
number: {
type: "number",
exclusiveMinimum: 19,
maximum: 100,
description: "You can limit the range of number.",
},
string: {
oneOf: [
{
type: "string",
minLength: 3,
maxLength: 24,
},
{
type: "string",
minLength: 40,
maxLength: 100,
},
],
description:
"You can limit the length of string.\n\nAlso, multiple range conditions are also possible.",
},
pattern: {
type: "string",
pattern: "^[a-z]+$",
description: "You can limit the pattern of string.",
},
format: {
oneOf: [
{
type: "null",
},
{
type: "string",
format: "date-time",
},
],
description: "You can limit the format of string.",
},
array: {
type: "array",
minItems: 3,
items: {
type: "string",
format: "uuid",
},
description:
"In the Array case, possible to restrict its elements.",
},
},
required: ["type", "string", "pattern", "format", "array"],
additionalProperties: false,
},
},
},
schemas: [
{
$ref: "#/components/schemas/Special",
},
],
version: "3.1",
};Custom fields
OpenAPI-style schema consumers commonly use the x-* prefix for non-standard extensions. To embed x-* properties (for vendor-specific tooling, internal flags, anything that isnโt part of the standard), use tags.TagBase.schema or the tags.JsonSchemaPlugin helper:
TypeScript Source
import typia, { tags } from "typia";
export const SpecialTypeTagSchema = typia.json.schemas<[IAccount]>();
type Monetary<Value extends string> = tags.TagBase<{
target: "number";
kind: "monetary";
value: Value;
schema: {
"x-monetary": Value;
};
}>;
type Placeholder<Value extends string> = tags.JsonSchemaPlugin<{
"x-placeholder": Value;
}>;
interface IAccount {
code: string & Placeholder<"Write your account code please">;
balance: number & Monetary<"dollar">;
}Compiled JavaScript
import typia from "typia";
export const SpecialTypeTagSchema = {
components: {
schemas: {
IAccount: {
type: "object",
properties: {
code: {
type: "string",
"x-placeholder": "Write your account code please",
},
balance: {
type: "number",
"x-monetary": "dollar",
},
},
required: ["code", "balance"],
additionalProperties: false,
},
},
},
schemas: [
{
$ref: "#/components/schemas/IAccount",
},
],
version: "3.1",
};For standard schema keywords that TypeScript cannot infer, such as OpenAPI 3.1 / JSON Schema patternProperties, use the same escape hatch when the annotation is only for schema consumers:
import typia, { tags } from "typia";
type XHeaders = Record<string, string> &
tags.JsonSchemaPlugin<{
patternProperties: {
"^x-": { type: "string" };
};
additionalProperties: false;
}>;
typia.json.schema<XHeaders>();JsonSchemaPlugin is schema-only metadata. It does not change validator behavior; if runtime validation must reject keys outside the pattern, encode that rule with a validating custom tags.TagBase or validate the keys separately.
Restrictions
bigint is rejected
JSON Schema has no bigint. typia refuses to compile a schema for a type that contains one:
TypeScript Source
import typia, { tags } from "typia";
interface Something {
bigint: bigint;
array: bigint[];
nested: Nested;
}
interface Nested {
uint64: bigint & tags.Type<"uint64">;
}
typia.json.schemas<[Something]>();Console Output
main.ts:12:1 - error TS(typia.json.schemas): typia transform error: unsupported type detected
- Something.bigint: bigint
- JSON schema does not support bigint type.
- Something.array: bigint
- JSON schema does not support bigint type.
- Nested.uint64: (bigint & Typeuint64)
- JSON schema does not support bigint type.Native classes โ only Date is allowed
Map, Set, Uint8Array, โฆ are rejected. Date is special-cased: it serializes as string & tags.Format<"date-time">, so typia accepts it.
TypeScript Source
import typia from "typia";
interface Native {
date: Date;
}
typia.json.schemas<[Native]>();Output JSON Schema
({
version: "3.1",
components: {
schemas: {
Native: {
type: "object",
properties: {
date: {
type: "string",
format: "date-time",
},
},
required: ["date"],
},
},
},
schemas: [
{
$ref: "#/components/schemas/Native",
},
],
});Where to go next
- Reading JSON safely โ
json.*Parse - Writing JSON fast โ
json.*Stringify - LLM-compatible schema for function calling โ
llm.parameters - Constraint cheatsheet โ Special Tags