Hyperlinkv0.8.0-beta.28

JsonSchema

JsonSchema.fromSchemaOpenApi3_0functioneffect/JsonSchema.ts:475
(schema: JsonSchema): Document<"draft-2020-12">

Parses a raw OpenAPI 3.0 JSON Schema into a Document<"draft-2020-12">.

When to use

Use when you need to consume raw JSON Schema objects from an OpenAPI 3.0 specification.

Details

This handles OpenAPI 3.0 extensions, including nullable, singular example, and boolean exclusiveMinimum or exclusiveMaximum. It normalizes the schema to Draft-07 first, then converts to Draft-2020-12 via fromSchemaDraft07.

Example (Parsing an OpenAPI 3.0 nullable schema)

import { JsonSchema } from "effect"

const raw: JsonSchema.JsonSchema = {
  type: "string",
  nullable: true
}

const doc = JsonSchema.fromSchemaOpenApi3_0(raw)
// nullable is expanded into a type array
console.log(doc.schema.type) // ["string", "null"]
export function fromSchemaOpenApi3_0(schema: JsonSchema): Document<"draft-2020-12"> {
  const normalized = normalize_OpenApi3_0_to_Draft07(schema)
  return fromSchemaDraft07(normalized as JsonSchema)
}