Skip to content

Support the openapi-3.0 JSON Schema target #1707

Closed

Description

@MichaelDeBoey

Request a feature

Support target: "openapi-3.0" in toJsonSchema() and in the Standard JSON Schema ~standard.jsonSchema.input() / .output() methods.

🤷 Motivation

OpenAPI 3.0 documents are still common, and their Schema Object is a JSON Schema draft-04 superset with its own keywords. The Standard JSON Schema spec lists "openapi-3.0" as one of its standard targets, next to "draft-2020-12" and "draft-07". A tool that builds an OpenAPI 3.0 document from Standard JSON Schema validators can ask zod, sury and valibot (through toStandardJsonSchema from @valibot/to-json-schema) for that target today. ArkType throws:

import { type } from "arktype"

type("string | null")["~standard"].jsonSchema.input({ target: "openapi-3.0" })
// ParseError: JSONSchema target 'openapi-3.0' is not supported (must be "draft-2020-12" or "draft-07")

The spec says libraries should throw for a target they don't support, so this is correct behaviour; the request is to support the target. type.toJsonSchema({ target: "openapi-3.0" }) is rejected by the types and, at runtime, returns draft 2020-12 output without $schema.

The check sits in validateStandardJsonSchemaTarget:

const supportedJsonSchemaTargets: ToJsonSchema.Target[] = [
"draft-2020-12",
"draft-07"
]
export const writeInvalidJsonSchemaTargetMessage = (target: string): string =>
`JSONSchema target '${target}' is not supported (must be ${supportedJsonSchemaTargets.map(t => `"${t}"`).join(" or ")})`
const validateStandardJsonSchemaTarget = (
target: StandardJSONSchemaV1.Target
): ToJsonSchema.Target => {
if (!includes(supportedJsonSchemaTargets, target))
throwParseError(writeInvalidJsonSchemaTargetMessage(target))
return target
}

Without the target, the caller has to post-process ArkType's draft-07 output into OpenAPI 3.0, while the other validators already do that themselves.

💡 Solution

Add "openapi-3.0" to ToJsonSchema.Target and translate the keywords OpenAPI 3.0 lacks, like the "draft-07" branches already do for definitions and tuple items. For a few shapes, ArkType 2.2.9's "draft-07" output and what zod 4.6.7 writes for "openapi-3.0":

Shape ArkType, "draft-07" zod, "openapi-3.0"
type("0 < number < 10") {"type":"number","exclusiveMaximum":10,"exclusiveMinimum":0} {"type":"number","minimum":0,"exclusiveMinimum":true,"maximum":10,"exclusiveMaximum":true}
type("'cat'") {"const":"cat"} {"type":"string","enum":["cat"]}
type("string | null") {"anyOf":[{"type":"string"},{"type":"null"}]} {"nullable":true,"type":"string"}
type(["string", "number"]) {"type":"array","minItems":2,"items":[{"type":"string"},{"type":"number"}],"additionalItems":false} {"type":"array","items":{"anyOf":[{"type":"string"},{"type":"number"}]},"minItems":2,"maxItems":2}

($schema omitted from the ArkType column.)

In short:

  • Exclusive bounds become minimum / maximum with boolean exclusiveMinimum / exclusiveMaximum.
  • const becomes a single-value enum.
  • null in a union becomes nullable: true on the remaining branch, since 3.0 has no "null" type.
  • No $schema keyword.
  • Tuples have no exact 3.0 form, because items must be a single schema. sury, valibot and zod all approximate a tuple as items: { anyOf: [...] } plus minItems / maxItems. Throwing, or deferring to the existing fallback handlers, would be alternatives.

For comparison, sury and valibot write the same nullable, enum and tuple forms. valibot throws for exclusive bounds (The "gt_value" action is not supported for OpenAPI 3.0.).

Related: #1328 (OpenAPI-compatible enum output for unions), #1465 (OpenAPI discriminator).

Activity

  1. pullfrog commented on Oct 22, 2026

    @pullfrog
    Contributor
  2. ssalbdivad commented on Nov 18, 2026

    @ssalbdivad
    Member

    Fixed in 3.0.0-beta.0 (#1728). Try it with npm i arktype@next.

  3. moved this from To do to Done (merged or closed) in arktypeioon Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    • Status
      Done (merged or closed)

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions