Skip to content

SchemaValidationSchema

Source: src/Cloudflare/SchemaValidation/Schema.ts

An OpenAPI v3 schema uploaded to a zone for API Shield schema validation (/zones/{zone_id}/schema_validation/schemas).

Uploading a schema registers the endpoints it describes as API Shield operations (a server-side side effect — deleting the schema does not delete those operations). The schema body is immutable: changing source uploads a new schema and deletes the old one (replacement). Only the validationEnabled flag is mutable in place.

Upload an OpenAPI v3 schema

const schema = yield* Cloudflare.SchemaValidationSchema("ApiSchema", {
zoneId: zone.zoneId,
source: JSON.stringify({
openapi: "3.0.0",
info: { title: "my-api", version: "1.0.0" },
servers: [{ url: "https://api.example.com" }],
paths: {
"/users": {
get: {
operationId: "listUsers",
responses: { "200": { description: "ok" } },
},
},
},
}),
});

Upload a schema without enabling validation

const schema = yield* Cloudflare.SchemaValidationSchema("DraftSchema", {
zoneId: zone.zoneId,
source: openApiDocument,
validationEnabled: false,
});
// Enabling (false → true) patches the schema in place. Disabling an
// enabled schema is rejected by Cloudflare, so `true` → `false` (like a
// `source` change) replaces the schema instead.
yield* Cloudflare.SchemaValidationSchema("DraftSchema", {
zoneId: zone.zoneId,
source: openApiDocument,
validationEnabled: true,
});