@ykdz/template 0.0.37 → 0.0.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/application.d.ts +1 -52
- package/dist/application.js +0 -81
- package/dist/cli.js +14 -28
- package/dist/input-schemas.d.ts +30 -0
- package/dist/input-schemas.js +75 -0
- package/dist/main.d.ts +3 -14
- package/dist/main.js +496 -378
- package/dist/result-schemas.d.ts +222 -0
- package/dist/result-schemas.js +74 -0
- package/dist/standard-schema.d.ts +3 -0
- package/dist/standard-schema.js +29 -0
- package/node_modules/@standard-schema/spec/LICENSE +21 -0
- package/node_modules/@standard-schema/spec/README.md +198 -0
- package/node_modules/@standard-schema/spec/dist/index.cjs +18 -0
- package/node_modules/@standard-schema/spec/dist/index.d.cts +119 -0
- package/node_modules/@standard-schema/spec/dist/index.d.ts +119 -0
- package/node_modules/@standard-schema/spec/dist/index.js +0 -0
- package/node_modules/@standard-schema/spec/package.json +52 -0
- package/node_modules/@types/node/LICENSE +21 -0
- package/node_modules/@types/node/README.md +15 -0
- package/node_modules/@types/node/assert/strict.d.ts +111 -0
- package/node_modules/@types/node/assert.d.ts +1115 -0
- package/node_modules/@types/node/async_hooks.d.ts +619 -0
- package/node_modules/@types/node/buffer.buffer.d.ts +477 -0
- package/node_modules/@types/node/buffer.d.ts +1941 -0
- package/node_modules/@types/node/child_process.d.ts +1480 -0
- package/node_modules/@types/node/cluster.d.ts +578 -0
- package/node_modules/@types/node/compatibility/iterators.d.ts +21 -0
- package/node_modules/@types/node/console.d.ts +453 -0
- package/node_modules/@types/node/constants.d.ts +21 -0
- package/node_modules/@types/node/crypto.d.ts +5484 -0
- package/node_modules/@types/node/dgram.d.ts +715 -0
- package/node_modules/@types/node/diagnostics_channel.d.ts +576 -0
- package/node_modules/@types/node/dns/promises.d.ts +503 -0
- package/node_modules/@types/node/dns.d.ts +923 -0
- package/node_modules/@types/node/domain.d.ts +166 -0
- package/node_modules/@types/node/events.d.ts +967 -0
- package/node_modules/@types/node/fs/promises.d.ts +1354 -0
- package/node_modules/@types/node/fs.d.ts +4777 -0
- package/node_modules/@types/node/globals.d.ts +170 -0
- package/node_modules/@types/node/globals.typedarray.d.ts +41 -0
- package/node_modules/@types/node/http.d.ts +2246 -0
- package/node_modules/@types/node/http2.d.ts +2882 -0
- package/node_modules/@types/node/https.d.ts +585 -0
- package/node_modules/@types/node/index.d.ts +101 -0
- package/node_modules/@types/node/inspector.d.ts +323 -0
- package/node_modules/@types/node/inspector.generated.d.ts +4406 -0
- package/node_modules/@types/node/module.d.ts +844 -0
- package/node_modules/@types/node/net.d.ts +1197 -0
- package/node_modules/@types/node/os.d.ts +507 -0
- package/node_modules/@types/node/package.json +140 -0
- package/node_modules/@types/node/path.d.ts +200 -0
- package/node_modules/@types/node/perf_hooks.d.ts +1054 -0
- package/node_modules/@types/node/process.d.ts +2101 -0
- package/node_modules/@types/node/punycode.d.ts +117 -0
- package/node_modules/@types/node/querystring.d.ts +152 -0
- package/node_modules/@types/node/readline/promises.d.ts +161 -0
- package/node_modules/@types/node/readline.d.ts +600 -0
- package/node_modules/@types/node/repl.d.ts +438 -0
- package/node_modules/@types/node/sea.d.ts +162 -0
- package/node_modules/@types/node/sqlite.d.ts +1182 -0
- package/node_modules/@types/node/stream/consumers.d.ts +45 -0
- package/node_modules/@types/node/stream/promises.d.ts +90 -0
- package/node_modules/@types/node/stream/web.d.ts +596 -0
- package/node_modules/@types/node/stream.d.ts +1707 -0
- package/node_modules/@types/node/string_decoder.d.ts +67 -0
- package/node_modules/@types/node/test.d.ts +2656 -0
- package/node_modules/@types/node/timers/promises.d.ts +108 -0
- package/node_modules/@types/node/timers.d.ts +285 -0
- package/node_modules/@types/node/tls.d.ts +1314 -0
- package/node_modules/@types/node/trace_events.d.ts +197 -0
- package/node_modules/@types/node/ts5.6/buffer.buffer.d.ts +473 -0
- package/node_modules/@types/node/ts5.6/compatibility/float16array.d.ts +71 -0
- package/node_modules/@types/node/ts5.6/globals.typedarray.d.ts +36 -0
- package/node_modules/@types/node/ts5.6/index.d.ts +103 -0
- package/node_modules/@types/node/ts5.7/compatibility/float16array.d.ts +72 -0
- package/node_modules/@types/node/ts5.7/index.d.ts +103 -0
- package/node_modules/@types/node/tty.d.ts +209 -0
- package/node_modules/@types/node/url.d.ts +1103 -0
- package/node_modules/@types/node/util.d.ts +2376 -0
- package/node_modules/@types/node/v8.d.ts +1010 -0
- package/node_modules/@types/node/vm.d.ts +1160 -0
- package/node_modules/@types/node/wasi.d.ts +202 -0
- package/node_modules/@types/node/web-globals/abortcontroller.d.ts +34 -0
- package/node_modules/@types/node/web-globals/crypto.d.ts +32 -0
- package/node_modules/@types/node/web-globals/domexception.d.ts +68 -0
- package/node_modules/@types/node/web-globals/events.d.ts +97 -0
- package/node_modules/@types/node/web-globals/fetch.d.ts +62 -0
- package/node_modules/@types/node/web-globals/navigator.d.ts +25 -0
- package/node_modules/@types/node/web-globals/storage.d.ts +24 -0
- package/node_modules/@types/node/web-globals/streams.d.ts +22 -0
- package/node_modules/@types/node/worker_threads.d.ts +894 -0
- package/node_modules/@types/node/zlib.d.ts +768 -0
- package/node_modules/@valibot/to-json-schema/LICENSE.md +9 -0
- package/node_modules/@valibot/to-json-schema/README.md +475 -0
- package/node_modules/@valibot/to-json-schema/dist/index.cjs +800 -0
- package/node_modules/@valibot/to-json-schema/dist/index.d.cts +991 -0
- package/node_modules/@valibot/to-json-schema/dist/index.d.mts +991 -0
- package/node_modules/@valibot/to-json-schema/dist/index.min.cjs +1 -0
- package/node_modules/@valibot/to-json-schema/dist/index.min.mjs +1 -0
- package/node_modules/@valibot/to-json-schema/dist/index.mjs +795 -0
- package/node_modules/@valibot/to-json-schema/package.json +75 -0
- package/node_modules/@ykdz/cli-contract/LICENSE +21 -0
- package/node_modules/@ykdz/cli-contract/dist/atomic-variant-compiler.d.ts +17 -0
- package/node_modules/@ykdz/cli-contract/dist/atomic-variant-compiler.js +55 -0
- package/node_modules/@ykdz/cli-contract/dist/cli-contract.d.ts +1164 -0
- package/node_modules/@ykdz/cli-contract/dist/cli-contract.js +1408 -0
- package/node_modules/@ykdz/cli-contract/dist/cli-execution.d.ts +54 -0
- package/node_modules/@ykdz/cli-contract/dist/cli-execution.js +708 -0
- package/node_modules/@ykdz/cli-contract/dist/cli-invocation.d.ts +174 -0
- package/node_modules/@ykdz/cli-contract/dist/cli-invocation.js +524 -0
- package/node_modules/@ykdz/cli-contract/dist/cli-write-error.d.ts +10 -0
- package/node_modules/@ykdz/cli-contract/dist/cli-write-error.js +14 -0
- package/node_modules/@ykdz/cli-contract/dist/contract-definition-error.d.ts +260 -0
- package/node_modules/@ykdz/cli-contract/dist/contract-definition-error.js +130 -0
- package/node_modules/@ykdz/cli-contract/dist/contract-execution-error.d.ts +63 -0
- package/node_modules/@ykdz/cli-contract/dist/contract-execution-error.js +17 -0
- package/node_modules/@ykdz/cli-contract/dist/contract-schema-compiler.d.ts +6 -0
- package/node_modules/@ykdz/cli-contract/dist/contract-schema-compiler.js +532 -0
- package/node_modules/@ykdz/cli-contract/dist/contract-schema.d.ts +14 -0
- package/node_modules/@ykdz/cli-contract/dist/contract-schema.js +1 -0
- package/node_modules/@ykdz/cli-contract/dist/description.d.ts +2 -0
- package/node_modules/@ykdz/cli-contract/dist/description.js +13 -0
- package/node_modules/@ykdz/cli-contract/dist/index.d.ts +8 -0
- package/node_modules/@ykdz/cli-contract/dist/index.js +7 -0
- package/node_modules/@ykdz/cli-contract/dist/json-value.d.ts +4 -0
- package/node_modules/@ykdz/cli-contract/dist/json-value.js +64 -0
- package/node_modules/@ykdz/cli-contract/dist/node.d.ts +21 -0
- package/node_modules/@ykdz/cli-contract/dist/node.js +109 -0
- package/node_modules/@ykdz/cli-contract/dist/outcome-fact.d.ts +162 -0
- package/node_modules/@ykdz/cli-contract/dist/outcome-fact.js +113 -0
- package/node_modules/@ykdz/cli-contract/dist/outcome-wire.d.ts +53 -0
- package/node_modules/@ykdz/cli-contract/dist/outcome-wire.js +189 -0
- package/node_modules/@ykdz/cli-contract/dist/stream-variant-compiler.d.ts +16 -0
- package/node_modules/@ykdz/cli-contract/dist/stream-variant-compiler.js +45 -0
- package/node_modules/@ykdz/cli-contract/package.json +69 -0
- package/node_modules/@ykdz/template-builtin-presets/dist/src/foundation.d.ts +20 -0
- package/node_modules/@ykdz/template-builtin-presets/dist/src/foundation.js +27 -28
- package/node_modules/@ykdz/template-builtin-presets/dist/src/generation-record.d.ts +19 -0
- package/node_modules/@ykdz/template-builtin-presets/dist/src/generation-record.js +1 -1
- package/node_modules/@ykdz/template-builtin-presets/dist/src/index.d.ts +2 -1
- package/node_modules/@ykdz/template-builtin-presets/dist/src/index.js +2 -1
- package/node_modules/@ykdz/template-builtin-presets/dist/src/ts-cli/definition.js +9 -5
- package/node_modules/@ykdz/template-builtin-presets/dist/src/vike-app/definition.js +0 -4
- package/node_modules/@ykdz/template-builtin-presets/package.json +2 -1
- package/node_modules/@ykdz/template-builtin-presets/templates/foundation/AGENTS.md.template +10 -4
- package/node_modules/@ykdz/template-builtin-presets/templates/foundation/devcontainer.json +3 -0
- package/node_modules/@ykdz/template-builtin-presets/templates/ts-cli/publication/artifact.ts +128 -59
- package/node_modules/@ykdz/template-builtin-presets/templates/ts-cli/publication/handoff.ts +80 -8
- package/node_modules/@ykdz/template-builtin-presets/templates/ts-cli/publication/readiness.ts +7 -3
- package/node_modules/@ykdz/template-builtin-presets/templates/ts-cli/src/cli.ts +9 -19
- package/node_modules/@ykdz/template-builtin-presets/templates/ts-cli/src/main.ts +144 -60
- package/node_modules/@ykdz/template-builtin-presets/templates/ts-cli/src/standard-schema.ts +37 -0
- package/node_modules/@ykdz/template-builtin-presets/templates/ts-cli/test/e2e/journeys/lookup.journey.ts +71 -0
- package/node_modules/@ykdz/template-builtin-presets/templates/ts-cli/test/integration/command.test.ts +118 -59
- package/node_modules/@ykdz/template-core/dist/package-contribution.d.ts +0 -1
- package/node_modules/@ykdz/template-core/dist/pnpm-workspace.yaml +2 -1
- package/node_modules/@ykdz/template-core/dist/project-blueprint.d.ts +15 -0
- package/node_modules/@ykdz/template-core/dist/project-blueprint.js +1 -1
- package/node_modules/@ykdz/template-core/dist/project-github.d.ts +1 -1
- package/node_modules/undici-types/LICENSE +21 -0
- package/node_modules/undici-types/README.md +6 -0
- package/node_modules/undici-types/agent.d.ts +32 -0
- package/node_modules/undici-types/api.d.ts +43 -0
- package/node_modules/undici-types/balanced-pool.d.ts +30 -0
- package/node_modules/undici-types/cache-interceptor.d.ts +179 -0
- package/node_modules/undici-types/cache.d.ts +36 -0
- package/node_modules/undici-types/client-stats.d.ts +15 -0
- package/node_modules/undici-types/client.d.ts +123 -0
- package/node_modules/undici-types/connector.d.ts +36 -0
- package/node_modules/undici-types/content-type.d.ts +21 -0
- package/node_modules/undici-types/cookies.d.ts +30 -0
- package/node_modules/undici-types/diagnostics-channel.d.ts +74 -0
- package/node_modules/undici-types/dispatcher.d.ts +279 -0
- package/node_modules/undici-types/env-http-proxy-agent.d.ts +22 -0
- package/node_modules/undici-types/errors.d.ts +177 -0
- package/node_modules/undici-types/eventsource.d.ts +66 -0
- package/node_modules/undici-types/fetch.d.ts +211 -0
- package/node_modules/undici-types/formdata.d.ts +108 -0
- package/node_modules/undici-types/global-dispatcher.d.ts +9 -0
- package/node_modules/undici-types/global-origin.d.ts +7 -0
- package/node_modules/undici-types/h2c-client.d.ts +73 -0
- package/node_modules/undici-types/handlers.d.ts +15 -0
- package/node_modules/undici-types/header.d.ts +160 -0
- package/node_modules/undici-types/index.d.ts +91 -0
- package/node_modules/undici-types/interceptors.d.ts +80 -0
- package/node_modules/undici-types/mock-agent.d.ts +68 -0
- package/node_modules/undici-types/mock-call-history.d.ts +111 -0
- package/node_modules/undici-types/mock-client.d.ts +27 -0
- package/node_modules/undici-types/mock-errors.d.ts +12 -0
- package/node_modules/undici-types/mock-interceptor.d.ts +94 -0
- package/node_modules/undici-types/mock-pool.d.ts +27 -0
- package/node_modules/undici-types/package.json +55 -0
- package/node_modules/undici-types/patch.d.ts +29 -0
- package/node_modules/undici-types/pool-stats.d.ts +19 -0
- package/node_modules/undici-types/pool.d.ts +41 -0
- package/node_modules/undici-types/proxy-agent.d.ts +29 -0
- package/node_modules/undici-types/readable.d.ts +68 -0
- package/node_modules/undici-types/retry-agent.d.ts +8 -0
- package/node_modules/undici-types/retry-handler.d.ts +125 -0
- package/node_modules/undici-types/round-robin-pool.d.ts +41 -0
- package/node_modules/undici-types/snapshot-agent.d.ts +109 -0
- package/node_modules/undici-types/socks5-proxy-agent.d.ts +25 -0
- package/node_modules/undici-types/util.d.ts +18 -0
- package/node_modules/undici-types/utility.d.ts +7 -0
- package/node_modules/undici-types/webidl.d.ts +347 -0
- package/node_modules/undici-types/websocket.d.ts +188 -0
- package/package.json +5 -3
- package/dist/command-result.d.ts +0 -9
- package/dist/command-result.js +0 -231
- package/node_modules/@ykdz/template-builtin-presets/templates/ts-cli/test/e2e/journeys/greet.journey.ts +0 -46
- package/node_modules/@ykdz/template-builtin-presets/templates/ts-cli/test/unit/greet.test.ts +0 -15
- package/node_modules/@ykdz/template-builtin-presets/templates/vike-app/devcontainer/docker-client.Dockerfile +0 -3
- package/node_modules/commander/LICENSE +0 -22
- package/node_modules/commander/Readme.md +0 -1172
- package/node_modules/commander/index.js +0 -21
- package/node_modules/commander/lib/argument.js +0 -147
- package/node_modules/commander/lib/command.js +0 -2790
- package/node_modules/commander/lib/error.js +0 -36
- package/node_modules/commander/lib/help.js +0 -731
- package/node_modules/commander/lib/option.js +0 -377
- package/node_modules/commander/lib/suggestSimilar.js +0 -99
- package/node_modules/commander/package-support.json +0 -19
- package/node_modules/commander/package.json +0 -64
- package/node_modules/commander/typings/index.d.ts +0 -1113
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Fabian Hiller
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,475 @@
|
|
|
1
|
+
# Valibot to JSON Schema
|
|
2
|
+
|
|
3
|
+
Utility to convert [Valibot](https://valibot.dev) schemas to JSON Schema. Supports JSON Schema draft-07, draft-2020-12, and OpenAPI 3.0 Schema Object formats.
|
|
4
|
+
|
|
5
|
+
```js
|
|
6
|
+
import { toJsonSchema } from '@valibot/to-json-schema';
|
|
7
|
+
import * as v from 'valibot';
|
|
8
|
+
|
|
9
|
+
toJsonSchema(v.string()); // { $schema: "http://json-schema.org/draft-07/schema#", type: "string" }
|
|
10
|
+
```
|
|
11
|
+
|
|
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 different programming languages
|
|
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.
|
|
20
|
+
|
|
21
|
+
## Supported features
|
|
22
|
+
|
|
23
|
+
**Note**: Converted schemas may behave slightly differently in JSON schema validators (especially for string format) because their implementation is different from Valibot's.
|
|
24
|
+
|
|
25
|
+
| Schema | Status | Note |
|
|
26
|
+
| ---------------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------- |
|
|
27
|
+
| `any` | ✅ | |
|
|
28
|
+
| `array` | ✅ | |
|
|
29
|
+
| `boolean` | ✅ | |
|
|
30
|
+
| `enum` | ⚠️ | Only JSON compatible values are supported |
|
|
31
|
+
| `exactOptional` | ✅ | |
|
|
32
|
+
| `intersect` | ✅ | |
|
|
33
|
+
| `lazy` | ⚠️ | The `.getter` function is always executed with `undefined` as input |
|
|
34
|
+
| `literal` | ⚠️ | Only JSON compatible values are supported |
|
|
35
|
+
| `looseObject` | ✅ | |
|
|
36
|
+
| `looseTuple` | ✅ | |
|
|
37
|
+
| `never` | ✅ | |
|
|
38
|
+
| `null` | ✅ | |
|
|
39
|
+
| `nullable` | ✅ | |
|
|
40
|
+
| `nullish` | ✅ | |
|
|
41
|
+
| `number` | ✅ | |
|
|
42
|
+
| `objectWithRest` | ✅ | |
|
|
43
|
+
| `object` | ✅ | |
|
|
44
|
+
| `optional` | ✅ | |
|
|
45
|
+
| `picklist` | ⚠️ | Only JSON compatible values are supported |
|
|
46
|
+
| `record` | ⚠️ | Only `string` schemas for the key of the record are supported. Adds `propertyNames` for key validation (not available in OpenAPI 3.0) |
|
|
47
|
+
| `strictObject` | ✅ | |
|
|
48
|
+
| `strictTuple` | ✅ | |
|
|
49
|
+
| `string` | ✅ | |
|
|
50
|
+
| `tupleWithRest` | ✅ | |
|
|
51
|
+
| `tuple` | ✅ | |
|
|
52
|
+
| `union` | ✅ | |
|
|
53
|
+
| `undefinedable` | ✅ | |
|
|
54
|
+
| `unknown` | ✅ | |
|
|
55
|
+
| `variant` | ⚠️ | The discriminator key will be ignored |
|
|
56
|
+
|
|
57
|
+
| Actions | Status | Note |
|
|
58
|
+
| --------------- | ------ | ------------------------------------------------------ |
|
|
59
|
+
| `base64` | ✅ | |
|
|
60
|
+
| `bic` | ✅ | |
|
|
61
|
+
| `cuid2` | ✅ | |
|
|
62
|
+
| `decimal` | ✅ | |
|
|
63
|
+
| `description` | ✅ | |
|
|
64
|
+
| `digits` | ✅ | |
|
|
65
|
+
| `domain` | ✅ | |
|
|
66
|
+
| `email` | ✅ | |
|
|
67
|
+
| `emoji` | ✅ | |
|
|
68
|
+
| `empty` | ✅ | |
|
|
69
|
+
| `endsWith` | ✅ | |
|
|
70
|
+
| `entries` | ✅ | |
|
|
71
|
+
| `examples` | ✅ | |
|
|
72
|
+
| `gtValue` | ⚠️ | Only in combination with `number` and `integer` schema |
|
|
73
|
+
| `hash` | ✅ | |
|
|
74
|
+
| `hexadecimal` | ✅ | |
|
|
75
|
+
| `hexColor` | ✅ | |
|
|
76
|
+
| `includes` | ✅ | |
|
|
77
|
+
| `integer` | ✅ | |
|
|
78
|
+
| `ipv4` | ✅ | |
|
|
79
|
+
| `ipv6` | ✅ | |
|
|
80
|
+
| `isoDate` | ✅ | |
|
|
81
|
+
| `isoDateTime` | ✅ | |
|
|
82
|
+
| `isoTime` | ✅ | |
|
|
83
|
+
| `isoTimeSecond` | ✅ | |
|
|
84
|
+
| `isoTimestamp` | ✅ | |
|
|
85
|
+
| `isoWeek` | ✅ | |
|
|
86
|
+
| `isrc` | ✅ | |
|
|
87
|
+
| `jwsCompact` | ✅ | |
|
|
88
|
+
| `ksuid` | ✅ | |
|
|
89
|
+
| `length` | ⚠️ | Only in combination with `string` and `array` schema |
|
|
90
|
+
| `ltValue` | ⚠️ | Only in combination with `number` and `integer` schema |
|
|
91
|
+
| `mac` | ✅ | |
|
|
92
|
+
| `mac48` | ✅ | |
|
|
93
|
+
| `mac64` | ✅ | |
|
|
94
|
+
| `maxEntries` | ✅ | |
|
|
95
|
+
| `maxLength` | ⚠️ | Only in combination with `string` and `array` schema |
|
|
96
|
+
| `maxValue` | ⚠️ | Only in combination with `number` schema |
|
|
97
|
+
| `metadata` | ✅ | Additional properties are added without validation |
|
|
98
|
+
| `minEntries` | ✅ | |
|
|
99
|
+
| `minLength` | ⚠️ | Only in combination with `string` and `array` schema |
|
|
100
|
+
| `minValue` | ⚠️ | Only in combination with `number` schema |
|
|
101
|
+
| `multipleOf` | ✅ | |
|
|
102
|
+
| `nanoid` | ✅ | |
|
|
103
|
+
| `nonEmpty` | ✅ | |
|
|
104
|
+
| `notValue` | ⚠️ | Only JSON compatible values are supported |
|
|
105
|
+
| `notValues` | ⚠️ | Only JSON compatible values are supported |
|
|
106
|
+
| `octal` | ✅ | |
|
|
107
|
+
| `regex` | ⚠️ | RegExp flags are not supported in JSON Schema |
|
|
108
|
+
| `rfcEmail` | ✅ | |
|
|
109
|
+
| `safeInteger` | ✅ | |
|
|
110
|
+
| `slug` | ✅ | |
|
|
111
|
+
| `startsWith` | ✅ | |
|
|
112
|
+
| `title` | ✅ | |
|
|
113
|
+
| `ulid` | ✅ | |
|
|
114
|
+
| `url` | ✅ | |
|
|
115
|
+
| `uuid` | ✅ | |
|
|
116
|
+
| `value` | ⚠️ | Only JSON compatible values are supported |
|
|
117
|
+
| `values` | ⚠️ | Only JSON compatible values are supported |
|
|
118
|
+
|
|
119
|
+
> For `length`, `minLength`, and `maxLength`, string constraints have different length semantics in Valibot and JSON Schema. Valibot checks JavaScript string length (`value.length`, UTF-16 code units), while JSON Schema `minLength` and `maxLength` count Unicode code points. This can differ for non-BMP code points such as emoji and for multi-code-point grapheme clusters such as combining marks or ZWJ sequences.
|
|
120
|
+
|
|
121
|
+
## Configurations
|
|
122
|
+
|
|
123
|
+
| Option | Type | Note |
|
|
124
|
+
| -------------- | --------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- |
|
|
125
|
+
| target | `'draft-07' \| 'draft-2020-12' \| 'openapi-3.0'` | The target JSON Schema format. Defaults to `'draft-07'`. |
|
|
126
|
+
| typeMode | `'ignore' \| 'input' \| 'output'` | Whether to convert the input or output type of the Valibot schema to JSON Schema. |
|
|
127
|
+
| errorMode | `'throw' \| 'warn' \| 'ignore'` | The policy for handling incompatible schemas and actions. |
|
|
128
|
+
| definitions | `Record<string, GenericSchema>` | The schema definitions for constructing recursive schemas. If not specified, the definitions are generated automatically. |
|
|
129
|
+
| overrideSchema | `(context: OverrideSchemaContext) => JsonSchema \| null \| undefined` | Overrides the JSON Schema conversion for a specific Valibot schema. |
|
|
130
|
+
| ignoreActions | `string[]` | The actions that should be ignored during the conversion. |
|
|
131
|
+
| overrideAction | `(context: OverrideActionContext) => JsonSchema \| null \| undefined` | Overrides the JSON Schema reference for a specific Valibot action. |
|
|
132
|
+
| overrideRef | `(context: OverrideRefContext) => string \| null \| undefined` | Overrides the JSON Schema reference for a specific reference ID. |
|
|
133
|
+
|
|
134
|
+
### Target format
|
|
135
|
+
|
|
136
|
+
The `target` configuration allows you to specify which JSON Schema format to generate. Different targets have different capabilities and syntax:
|
|
137
|
+
|
|
138
|
+
```js
|
|
139
|
+
import { toJsonSchema } from '@valibot/to-json-schema';
|
|
140
|
+
import * as v from 'valibot';
|
|
141
|
+
|
|
142
|
+
const schema = v.nullable(v.string());
|
|
143
|
+
|
|
144
|
+
// JSON Schema draft-07 (default)
|
|
145
|
+
toJsonSchema(schema);
|
|
146
|
+
// { $schema: "http://json-schema.org/draft-07/schema#", anyOf: [{ type: "string" }, { type: "null" }] }
|
|
147
|
+
|
|
148
|
+
// JSON Schema draft-2020-12
|
|
149
|
+
toJsonSchema(schema, { target: 'draft-2020-12' });
|
|
150
|
+
// { $schema: "https://json-schema.org/draft/2020-12/schema", anyOf: [{ type: "string" }, { type: "null" }] }
|
|
151
|
+
|
|
152
|
+
// OpenAPI 3.0 Schema Object
|
|
153
|
+
toJsonSchema(schema, { target: 'openapi-3.0' });
|
|
154
|
+
// { type: "string", nullable: true }
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
**Note**: Some features like `propertyNames` for record schemas are not available in OpenAPI 3.0.
|
|
158
|
+
|
|
159
|
+
### Type mode
|
|
160
|
+
|
|
161
|
+
The `typeMode` configuration controls whether to convert the input or output type of the Valibot schema to JSON Schema.
|
|
162
|
+
|
|
163
|
+
- When set to `'input'`, conversion stops before the first potential type transformation action or second schema in any pipeline.
|
|
164
|
+
- 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.
|
|
165
|
+
- When set to `'ignore'` (default), the entire pipeline is converted.
|
|
166
|
+
|
|
167
|
+
This is particularly useful when defining API endpoints where external developers need different schema information for requests vs responses:
|
|
168
|
+
|
|
169
|
+
```js
|
|
170
|
+
import { toJsonSchema } from '@valibot/to-json-schema';
|
|
171
|
+
import * as v from 'valibot';
|
|
172
|
+
|
|
173
|
+
const ValibotSchema = v.pipe(
|
|
174
|
+
v.string(),
|
|
175
|
+
v.decimal(),
|
|
176
|
+
v.transform(Number),
|
|
177
|
+
v.number(),
|
|
178
|
+
v.maxValue(100)
|
|
179
|
+
);
|
|
180
|
+
|
|
181
|
+
toJsonSchema(ValibotSchema, { typeMode: 'input' });
|
|
182
|
+
|
|
183
|
+
// {
|
|
184
|
+
// $schema: "http://json-schema.org/draft-07/schema#",
|
|
185
|
+
// type: "string",
|
|
186
|
+
// pattern: "^[+-]?(?:\\d*\\.)?\\d+$"
|
|
187
|
+
// }
|
|
188
|
+
|
|
189
|
+
toJsonSchema(ValibotSchema, { typeMode: 'output' });
|
|
190
|
+
|
|
191
|
+
// {
|
|
192
|
+
// $schema: "http://json-schema.org/draft-07/schema#",
|
|
193
|
+
// type: "number",
|
|
194
|
+
// maximum: 100
|
|
195
|
+
// }
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### Error mode
|
|
199
|
+
|
|
200
|
+
The `errorMode` configuration controls how the converter handles unsupported schemas and actions. By default, the error mode is set to `'throw'`. To force the conversion of unsupported Valibot features, you can set it to `'ignore'`.
|
|
201
|
+
|
|
202
|
+
> Unsupported schemas usually return an empty JSON schema (`{}`) and unsupported actions are usually ignored.
|
|
203
|
+
|
|
204
|
+
```js
|
|
205
|
+
import { toJsonSchema } from '@valibot/to-json-schema';
|
|
206
|
+
import * as v from 'valibot';
|
|
207
|
+
|
|
208
|
+
toJsonSchema(v.file(), { errorMode: 'ignore' }); // {}
|
|
209
|
+
|
|
210
|
+
toJsonSchema(v.pipe(v.string(), v.creditCard()), { errorMode: 'ignore' }); // { type: "string" }
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
### Override functions
|
|
214
|
+
|
|
215
|
+
The package provides powerful override capabilities to customize the JSON Schema conversion process. You can override the conversion of specific schemas, actions, or references.
|
|
216
|
+
|
|
217
|
+
#### Override schema conversion
|
|
218
|
+
|
|
219
|
+
Handle unsupported schemas or customize conversion behavior:
|
|
220
|
+
|
|
221
|
+
```js
|
|
222
|
+
import { toJsonSchema } from '@valibot/to-json-schema';
|
|
223
|
+
import * as v from 'valibot';
|
|
224
|
+
|
|
225
|
+
const ValibotSchema = v.object({ createdAt: v.date() });
|
|
226
|
+
|
|
227
|
+
toJsonSchema(ValibotSchema, {
|
|
228
|
+
overrideSchema(context) {
|
|
229
|
+
if (context.valibotSchema.type === 'date') {
|
|
230
|
+
return { type: 'string', format: 'date-time' };
|
|
231
|
+
}
|
|
232
|
+
},
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
// {
|
|
236
|
+
// $schema: "http://json-schema.org/draft-07/schema#",
|
|
237
|
+
// type: "object",
|
|
238
|
+
// properties: {
|
|
239
|
+
// createdAt: { type: "string" format: "date-time" }
|
|
240
|
+
// },
|
|
241
|
+
// required: ["createdAt"]
|
|
242
|
+
// }
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
#### Override reference IDs
|
|
246
|
+
|
|
247
|
+
Customize reference IDs for OpenAPI or other specifications:
|
|
248
|
+
|
|
249
|
+
```js
|
|
250
|
+
import { toJsonSchemaDefs } from '@valibot/to-json-schema';
|
|
251
|
+
import * as v from 'valibot';
|
|
252
|
+
|
|
253
|
+
const UserSchema = v.object({ name: v.string() });
|
|
254
|
+
|
|
255
|
+
toJsonSchemaDefs(
|
|
256
|
+
{ UserSchema },
|
|
257
|
+
{ overrideRef: (context) => `#/schemas/${context.referenceId}` }
|
|
258
|
+
);
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
### Enhanced metadata support
|
|
262
|
+
|
|
263
|
+
Use the generic `metadata` action to add title, description, and examples to your schemas or the individual `title` and `description` actions. Any other properties of the `metadata` action are added to the JSON Schema without further validation. This allows you to specify custom annotations and standard keywords such as `format`:
|
|
264
|
+
|
|
265
|
+
```js
|
|
266
|
+
import { toJsonSchema } from '@valibot/to-json-schema';
|
|
267
|
+
import * as v from 'valibot';
|
|
268
|
+
|
|
269
|
+
const ValibotSchema = v.pipe(
|
|
270
|
+
v.string(),
|
|
271
|
+
v.email(),
|
|
272
|
+
v.metadata({
|
|
273
|
+
title: 'Email Schema',
|
|
274
|
+
description: 'A schema that validates email addresses.',
|
|
275
|
+
examples: ['jane@example.com'],
|
|
276
|
+
'x-category': 'auth',
|
|
277
|
+
})
|
|
278
|
+
);
|
|
279
|
+
|
|
280
|
+
toJsonSchema(ValibotSchema);
|
|
281
|
+
|
|
282
|
+
// {
|
|
283
|
+
// $schema: "http://json-schema.org/draft-07/schema#",
|
|
284
|
+
// type: "string",
|
|
285
|
+
// format: "email",
|
|
286
|
+
// title: "Email Schema",
|
|
287
|
+
// description: "A schema that validates email addresses.",
|
|
288
|
+
// examples: ["jane@example.com"],
|
|
289
|
+
// "x-category": "auth"
|
|
290
|
+
// }
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
### Definitions
|
|
294
|
+
|
|
295
|
+
Nested and recursive schemas can be broken in multiple reusable definitions.
|
|
296
|
+
|
|
297
|
+
```js
|
|
298
|
+
import { toJsonSchema } from '@valibot/to-json-schema';
|
|
299
|
+
import * as v from 'valibot';
|
|
300
|
+
|
|
301
|
+
const EmailSchema = v.pipe(v.string(), v.email());
|
|
302
|
+
toJsonSchema(v.object({ email: EmailSchema }), {
|
|
303
|
+
definitions: { EmailSchema },
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
// {
|
|
307
|
+
// $schema: "http://json-schema.org/draft-07/schema#",
|
|
308
|
+
// type: "object",
|
|
309
|
+
// properties: {
|
|
310
|
+
// email: {
|
|
311
|
+
// $ref: "#/$defs/EmailSchema"
|
|
312
|
+
// }
|
|
313
|
+
// },
|
|
314
|
+
// required: ["email"],
|
|
315
|
+
// $defs: {
|
|
316
|
+
// EmailSchema: {
|
|
317
|
+
// type: "string",
|
|
318
|
+
// format: "email"
|
|
319
|
+
// }
|
|
320
|
+
// }
|
|
321
|
+
// }
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
Definitions are not required for converting `lazy` schemas. Missing definitions will be generated automatically.
|
|
325
|
+
|
|
326
|
+
```js
|
|
327
|
+
import { toJsonSchema } from '@valibot/to-json-schema';
|
|
328
|
+
import * as v from 'valibot';
|
|
329
|
+
|
|
330
|
+
const StringSchema = v.string();
|
|
331
|
+
toJsonSchema(v.object({ key: v.lazy(() => StringSchema) }));
|
|
332
|
+
|
|
333
|
+
// {
|
|
334
|
+
// $schema: "http://json-schema.org/draft-07/schema#",
|
|
335
|
+
// type: "object",
|
|
336
|
+
// properties: {
|
|
337
|
+
// key: {
|
|
338
|
+
// $ref: "#/$defs/0"
|
|
339
|
+
// }
|
|
340
|
+
// },
|
|
341
|
+
// required: ["key"],
|
|
342
|
+
// $defs: {
|
|
343
|
+
// 0: {
|
|
344
|
+
// type: "string"
|
|
345
|
+
// }
|
|
346
|
+
// }
|
|
347
|
+
// }
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
## Additional functions
|
|
351
|
+
|
|
352
|
+
### `toStandardJsonSchema`
|
|
353
|
+
|
|
354
|
+
Converts a Valibot schema to the [Standard JSON Schema](https://standardschema.dev/) format. This format is useful when working with tools and libraries that support the Standard JSON Schema specification.
|
|
355
|
+
|
|
356
|
+
```js
|
|
357
|
+
import { toStandardJsonSchema } from '@valibot/to-json-schema';
|
|
358
|
+
import * as v from 'valibot';
|
|
359
|
+
|
|
360
|
+
const schema = toStandardJsonSchema(
|
|
361
|
+
v.object({
|
|
362
|
+
id: v.pipe(v.string(), v.uuid()),
|
|
363
|
+
name: v.pipe(v.string(), v.nonEmpty()),
|
|
364
|
+
age: v.optional(v.number()),
|
|
365
|
+
})
|
|
366
|
+
);
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
### `toJsonSchemaDefs`
|
|
370
|
+
|
|
371
|
+
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.
|
|
372
|
+
|
|
373
|
+
```js
|
|
374
|
+
import { toJsonSchemaDefs } from '@valibot/to-json-schema';
|
|
375
|
+
import * as v from 'valibot';
|
|
376
|
+
|
|
377
|
+
const EmailSchema = v.pipe(v.string(), v.email());
|
|
378
|
+
const UserSchema = v.object({
|
|
379
|
+
name: v.string(),
|
|
380
|
+
email: EmailSchema,
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
toJsonSchemaDefs({ EmailSchema, UserSchema });
|
|
384
|
+
|
|
385
|
+
// {
|
|
386
|
+
// EmailSchema: {
|
|
387
|
+
// type: "string",
|
|
388
|
+
// format: "email"
|
|
389
|
+
// },
|
|
390
|
+
// UserSchema: {
|
|
391
|
+
// type: "object",
|
|
392
|
+
// properties: {
|
|
393
|
+
// name: {
|
|
394
|
+
// type: "string"
|
|
395
|
+
// },
|
|
396
|
+
// email: {
|
|
397
|
+
// $ref: "#/$defs/EmailSchema"
|
|
398
|
+
// }
|
|
399
|
+
// },
|
|
400
|
+
// required: ["name", "email"]
|
|
401
|
+
// }
|
|
402
|
+
// }
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
#### OpenAPI integration
|
|
406
|
+
|
|
407
|
+
For OpenAPI specifications, you can customize reference IDs:
|
|
408
|
+
|
|
409
|
+
```js
|
|
410
|
+
import { toJsonSchemaDefs } from '@valibot/to-json-schema';
|
|
411
|
+
import * as v from 'valibot';
|
|
412
|
+
|
|
413
|
+
const ValibotSchema1 = v.string();
|
|
414
|
+
const ValibotSchema2 = v.number();
|
|
415
|
+
const ValibotSchema3 = v.tuple([ValibotSchema1, ValibotSchema2]);
|
|
416
|
+
|
|
417
|
+
toJsonSchemaDefs(
|
|
418
|
+
{ ValibotSchema1, ValibotSchema2, ValibotSchema3 },
|
|
419
|
+
{ overrideRef: (context) => `#/schemas/${context.referenceId}` }
|
|
420
|
+
);
|
|
421
|
+
|
|
422
|
+
// {
|
|
423
|
+
// ValibotSchema1: { type: "string" },
|
|
424
|
+
// ValibotSchema2: { type: "number" },
|
|
425
|
+
// ValibotSchema3: {
|
|
426
|
+
// type: "array",
|
|
427
|
+
// items: [
|
|
428
|
+
// { $ref: "#/schemas/ValibotSchema1" },
|
|
429
|
+
// { $ref: "#/schemas/ValibotSchema2" }
|
|
430
|
+
// ],
|
|
431
|
+
// minItems: 2
|
|
432
|
+
// }
|
|
433
|
+
// }
|
|
434
|
+
```
|
|
435
|
+
|
|
436
|
+
### Global definitions
|
|
437
|
+
|
|
438
|
+
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.
|
|
439
|
+
|
|
440
|
+
```js
|
|
441
|
+
import { addGlobalDefs, toJsonSchema } from '@valibot/to-json-schema';
|
|
442
|
+
import * as v from 'valibot';
|
|
443
|
+
|
|
444
|
+
const ValibotSchema1 = v.string();
|
|
445
|
+
const ValibotSchema2 = v.number();
|
|
446
|
+
|
|
447
|
+
addGlobalDefs({ ValibotSchema1, ValibotSchema2 });
|
|
448
|
+
|
|
449
|
+
const ValibotSchema3 = v.tuple([ValibotSchema1, ValibotSchema2]);
|
|
450
|
+
|
|
451
|
+
toJsonSchema(ValibotSchema3);
|
|
452
|
+
|
|
453
|
+
// {
|
|
454
|
+
// $schema: "http://json-schema.org/draft-07/schema#",
|
|
455
|
+
// type: "array",
|
|
456
|
+
// items: [
|
|
457
|
+
// { $ref: "#/$defs/ValibotSchema1" },
|
|
458
|
+
// { $ref: "#/$defs/ValibotSchema2" }
|
|
459
|
+
// ],
|
|
460
|
+
// minItems: 2,
|
|
461
|
+
// $defs: {
|
|
462
|
+
// ValibotSchema1: { type: "string" },
|
|
463
|
+
// ValibotSchema2: { type: "number" }
|
|
464
|
+
// }
|
|
465
|
+
// }
|
|
466
|
+
```
|
|
467
|
+
|
|
468
|
+
You can also convert global definitions directly using `toJsonSchemaDefs`:
|
|
469
|
+
|
|
470
|
+
```js
|
|
471
|
+
const globalDefs = getGlobalDefs();
|
|
472
|
+
if (globalDefs) {
|
|
473
|
+
const schemaDefs = toJsonSchemaDefs(globalDefs);
|
|
474
|
+
}
|
|
475
|
+
```
|