Skip to content

OpenApiPatch

OpenAPI spec patching utilities.

Handles parsing and applying JSON Patch documents (RFC 6902) to OpenAPI specs. Supports patches from: - JSON files (.json) - YAML files (.yaml, .yml) - Inline JSON strings

12 exports Added in v4.0.0 Source

Errors

Error thrown when multiple JSON Patch operations fail.

Details

This error aggregates all application errors so users can see every failing operation at once instead of fixing them one at a time.

Signature

declare class JsonPatchAggregateError extends any {
constructor();
message: string;
}

Error thrown when applying a JSON Patch operation fails.

Details

This error occurs when: - A path does not exist for remove/replace operations - An array index is out of bounds - The target location is not a valid container

Signature

declare class JsonPatchApplicationError extends any {
constructor();
message: string;
}

Error thrown when parsing a JSON Patch input fails.

Details

This error occurs when: - A patch file cannot be read - JSON or YAML syntax is invalid - The file format is unsupported

Signature

declare class JsonPatchParseError extends any {
constructor();
message: string;
}

Error thrown when a parsed value does not conform to the JSON Patch schema.

Details

This error occurs when: - The patch is not an array - An operation is missing required fields (op, path) - An operation has an unsupported op value - An add/replace operation is missing the value field

Signature

declare class JsonPatchValidationError extends any {
constructor();
message: string;
}

Models

JsonPatchDocument type

Added in v4.0.0 Source

Type for a JSON Patch document.

Signature

type JsonPatchDocument = typeof JsonPatchDocument.Type;

Parsing

Parse a JSON Patch from either a file path or inline JSON string.

Details

The input is first checked as a file path. If the file exists, it is read and parsed based on its extension (.json, .yaml, .yml). Otherwise, the input is parsed as inline JSON.

Signature

declare const parsePatchInput: (...args: [input: string]) => Effect<any, unknown, unknown>;

Schemas

JsonPatchAdd

Added in v4.0.0 Source

Schema for a JSON Patch "add" operation.

Signature

declare const JsonPatchAdd: Schema.Codec<
Extract<
JsonPatch.JsonPatchOperation,
{
op: "add";
}
>
>;

Schema for a JSON Patch document (array of operations).

Details

A JSON Patch document is an ordered list of operations to apply to a JSON document. Operations are applied in sequence, with each operation seeing the result of previous operations.

Signature

declare const JsonPatchDocument: $Array<
Codec<JsonPatchOperation, JsonPatchOperation, never, never>
>;

Schema for a single JSON Patch operation.

Details

Supports the subset of RFC 6902 operations that Effect's JsonPatch module implements: add, remove, and replace.

Signature

declare const JsonPatchOperation: Schema.Codec<JsonPatch.JsonPatchOperation>;

Schema for a JSON Patch "remove" operation.

Signature

declare const JsonPatchRemove: Schema.Codec<
Extract<
JsonPatch.JsonPatchOperation,
{
op: "remove";
}
>
>;

Schema for a JSON Patch "replace" operation.

Signature

declare const JsonPatchReplace: Schema.Codec<
Extract<
JsonPatch.JsonPatchOperation,
{
op: "replace";
}
>
>;

Transforming

applyPatches

Added in v4.0.0 Source

Apply a sequence of JSON patches to a document.

Details

Patches are applied in order, with each patch operating on the result of the previous one. All operations are attempted, and if any fail, the errors are accumulated and reported together so users can fix all issues at once.

Signature

declare const applyPatches: (...args: [patches: readonly Array<{
readonly patch: readonly Array<JsonPatchOperation>;
readonly source: string;
}>, document: Json]) => Effect<any, unknown, unknown>