You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Some Valibot features can't be mapped to JSON schema. For example, transformation actions have no equivalent in JSON schema. Also, some Valibot schemas or validations are too JS-specific and do not have an equivalent JSON schema attribute.
12
+
This package is particularly popular for:
13
+
14
+
-**API Documentation**: Generate OpenAPI specifications from your Valibot schemas
15
+
-**Code Generation**: Create client SDKs and types from your validation schemas
16
+
-**LLM Integration**: Generate structured outputs for Large Language Models
17
+
-**Schema Sharing**: Share validation logic between backend and frontend
18
+
19
+
> Some Valibot features can't be mapped to JSON schema. For example, transformation actions have no equivalent in JSON schema. Also, some Valibot schemas or validations are too JS-specific and do not have an equivalent JSON schema attribute.
13
20
14
21
## Supported features
15
22
@@ -23,7 +30,7 @@ Some Valibot features can't be mapped to JSON schema. For example, transformatio
23
30
|`enum`| ✅ ||
24
31
|`exactOptional`| ✅ ||
25
32
|`intersect`| ✅ ||
26
-
|`lazy`| ⚠️ | The `.getter`function is always executed with `undefined` as input|
33
+
|`lazy`| ⚠️ | The `.getter`function is always executed with `undefined` as input |
27
34
|`literal`| ⚠️ | Only JSON compatible values are supported |
28
35
|`looseObject`| ✅ ||
29
36
|`looseTuple`| ✅ ||
@@ -50,14 +57,14 @@ Some Valibot features can't be mapped to JSON schema. For example, transformatio
| errorMode |`'throw' \| 'warn' \| 'ignore'`| The policy for handling incompatible schemas and actions. |
94
-
| definitions |`Record<string, GenericSchema>`| The schema definitions for constructing recursive schemas. If not specified, the definitions are generated automatically. |
| typeMode |`'ignore' \| 'input' \| 'output'`| Whether to convert the input or output type of the Valibot schema to JSON Schema. |
101
+
| errorMode |`'throw' \| 'warn' \| 'ignore'`| The policy for handling incompatible schemas and actions. |
102
+
| definitions |`Record<string, GenericSchema>`| The schema definitions for constructing recursive schemas. If not specified, the definitions are generated automatically. |
103
+
| overrideSchema |`(context: OverrideSchemaContext) => JSONSchema7 \| null \| undefined`| Overrides the JSON Schema conversion for a specific Valibot schema. |
104
+
| ignoreActions |`string[]`| The actions that should be ignored during the conversion. |
105
+
| overrideAction |`(context: OverrideActionContext) => JSONSchema7 \| null \| undefined`| Overrides the JSON Schema reference for a specific Valibot action. |
106
+
| overrideRef |`(context: OverrideRefContext) => string \| null \| undefined`| Overrides the JSON Schema reference for a specific reference ID. |
107
+
108
+
### Type mode
109
+
110
+
The `typeMode` configuration controls whether to convert the input or output type of the Valibot schema to JSON Schema.
111
+
112
+
- When set to `'input'`, conversion stops before the first potential type transformation action or second schema in any pipeline.
113
+
- When set to `'output'`, conversion of any pipelines starts from the last schema in the pipeline. Therefore, the output type must be specified explicitly with a schema after the last type transformation action.
114
+
- When set to `'ignore'` (default), the entire pipeline is converted.
115
+
116
+
This is particularly useful when defining API endpoints where external developers need different schema information for requests vs responses:
The package provides powerful override capabilities to customize the JSON Schema conversion process. You can override the conversion of specific schemas, actions, or references.
165
+
166
+
#### Override schema conversion
167
+
168
+
Handle unsupported schemas or customize conversion behavior:
Converts only the provided Valibot schema definitions to JSON Schema definitions, without wrapping them in a root schema. This is particularly useful for OpenAPI specifications where you need only the schema definitions.
For advanced use cases, you can manage global schema definitions that will be automatically used when converting schemas. This is particularly useful for larger projects with many reusable schemas.
0 commit comments