11import type { StandardJSONSchemaV1 , StandardSchemaV1 } from '@standard-schema/spec'
2- import { toJsonSchema } from '@valibot/to-json-schema'
32
43const FALLBACK_SCHEMA = Object . freeze ( { type : 'object' , additionalProperties : true } )
54
@@ -9,17 +8,19 @@ type MaybeJsonSchema = StandardSchemaV1['~standard'] & Partial<StandardJSONSchem
98/**
109 * Convert a schema to JSON Schema for the inspector, vendor-neutrally.
1110 *
12- * Prefers the schema's own Standard JSON Schema converter
13- * (`~standard.jsonSchema`, implemented by e.g. zod 4), then falls back to
14- * valibot's converter, then to a permissive object — so introspection never
15- * throws regardless of which validator produced the schema.
11+ * Uses the schema's own [Standard JSON Schema](https://standardschema.dev/)
12+ * converter (`~standard.jsonSchema`, implemented by e.g. zod 4) when the
13+ * validator provides one, and degrades to a permissive object schema
14+ * otherwise (e.g. valibot, which has no native converter) — so introspection
15+ * never throws and never pulls in a converter library for a validator devframe
16+ * doesn't otherwise depend on.
1617 */
1718function convert ( schema : unknown ) : unknown {
1819 const standard = ( schema as StandardSchemaV1 ) [ '~standard' ] as MaybeJsonSchema
20+ if ( ! standard . jsonSchema )
21+ return FALLBACK_SCHEMA
1922 try {
20- if ( standard . jsonSchema )
21- return standard . jsonSchema . input ( { target : 'draft-2020-12' } )
22- return toJsonSchema ( schema as never )
23+ return standard . jsonSchema . input ( { target : 'draft-2020-12' } )
2324 }
2425 catch {
2526 return FALLBACK_SCHEMA
0 commit comments