1 parent
e5aab76b79
commit
e12999ebd6
6 files changed
+107
No files matched your search
@@ -45,6 +45,7 @@
|
||||
"@zod/mini": "^4.0.0-beta",
|
||||
"arktype": "catalog:schema",
|
||||
"effect": "catalog:schema",
|
||||
"sury": "^10.0.0-rc",
|
||||
"zod": "^3.24.3 || ^4.0.0-beta",
|
||||
"zod-to-json-schema": "catalog:schema"
|
||||
},
|
||||
@@ -61,6 +62,9 @@
|
||||
"effect": {
|
||||
"optional": true
|
||||
},
|
||||
"sury": {
|
||||
"optional": true
|
||||
},
|
||||
"zod": {
|
||||
"optional": true
|
||||
},
|
||||
@@ -75,6 +79,7 @@
|
||||
"@zod/mini": "^4.0.0-beta.20250420T053007",
|
||||
"arktype": "catalog:schema",
|
||||
"effect": "catalog:schema",
|
||||
"sury": "^10.0.0-rc.4",
|
||||
"valibot": "catalog:schema",
|
||||
"zod": "catalog:schema",
|
||||
"zod-to-json-schema": "catalog:schema",
|
||||
|
||||
@@ -19,6 +19,9 @@ export const getToJsonSchemaFn = async (vendor: string): Promise<ToJsonSchemaFn>
|
||||
case 'effect':
|
||||
return import('./effect')
|
||||
.then(async ({ getToJsonSchemaFn }) => getToJsonSchemaFn())
|
||||
case 'sury':
|
||||
return import('./sury')
|
||||
.then(async ({ getToJsonSchemaFn }) => getToJsonSchemaFn())
|
||||
case 'valibot':
|
||||
return import('./valibot')
|
||||
.then(async ({ getToJsonSchemaFn }) => getToJsonSchemaFn())
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
import type { Schema } from 'sury'
|
||||
|
||||
import type { ToJsonSchemaFn } from '.'
|
||||
|
||||
import { tryImport } from '.'
|
||||
|
||||
export const getToJsonSchemaFn = async (): Promise<ToJsonSchemaFn> => {
|
||||
const { toJSONSchema } = await tryImport(import('sury'), 'sury')
|
||||
return schema => toJSONSchema((schema as Schema<unknown>))
|
||||
}
|
||||
@@ -108,6 +108,60 @@ exports[`toJsonSchema > effect sync 1`] = `
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`toJsonSchema > sury 1`] = `
|
||||
{
|
||||
"additionalProperties": true,
|
||||
"description": "My neat object schema",
|
||||
"properties": {
|
||||
"myString": {
|
||||
"type": "string",
|
||||
},
|
||||
"myUnion": {
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "number",
|
||||
},
|
||||
{
|
||||
"type": "boolean",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
"required": [
|
||||
"myString",
|
||||
"myUnion",
|
||||
],
|
||||
"type": "object",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`toJsonSchema > sury sync 1`] = `
|
||||
{
|
||||
"additionalProperties": true,
|
||||
"description": "My neat object schema",
|
||||
"properties": {
|
||||
"myString": {
|
||||
"type": "string",
|
||||
},
|
||||
"myUnion": {
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "number",
|
||||
},
|
||||
{
|
||||
"type": "boolean",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
"required": [
|
||||
"myString",
|
||||
"myUnion",
|
||||
],
|
||||
"type": "object",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`toJsonSchema > valibot 1`] = `
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { z as zm } from '@zod/mini'
|
||||
import { type } from 'arktype'
|
||||
import { Schema } from 'effect'
|
||||
import * as S from 'sury'
|
||||
import * as v from 'valibot'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { z } from 'zod'
|
||||
@@ -40,6 +41,16 @@ describe('toJsonSchema', () => {
|
||||
expect(jsonSchema).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it('sury', async () => {
|
||||
const schema = S.schema({
|
||||
myString: S.string,
|
||||
myUnion: S.union([S.number, S.boolean]),
|
||||
}).with(S.meta, { description: 'My neat object schema' })
|
||||
|
||||
const jsonSchema = await toJsonSchema(schema)
|
||||
expect(jsonSchema).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it('valibot', async () => {
|
||||
const schema = v.pipe(
|
||||
v.object({
|
||||
@@ -101,6 +112,17 @@ describe('toJsonSchema', () => {
|
||||
expect(jsonSchema).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it('sury sync', async () => {
|
||||
const schema = S.schema({
|
||||
myString: S.string,
|
||||
myUnion: S.union([S.number, S.boolean]),
|
||||
}).with(S.meta, { description: 'My neat object schema' })
|
||||
|
||||
await initToJsonSchemaSyncVendor('sury')
|
||||
const jsonSchema = toJsonSchemaSync(schema)
|
||||
expect(jsonSchema).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it('valibot sync', async () => {
|
||||
const schema = v.pipe(
|
||||
v.object({
|
||||
|
||||
Generated
+13
@@ -335,6 +335,9 @@ importers:
|
||||
effect:
|
||||
specifier: catalog:schema
|
||||
version: 3.14.5
|
||||
sury:
|
||||
specifier: ^10.0.0-rc.4
|
||||
version: 10.0.0-rc.4
|
||||
valibot:
|
||||
specifier: catalog:schema
|
||||
version: 1.0.0(typescript@5.6.3)
|
||||
@@ -5012,6 +5015,14 @@ packages:
|
||||
resolution: {integrity: sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==}
|
||||
engines: {node: '>= 0.4'}
|
||||
|
||||
sury@10.0.0-rc.4:
|
||||
resolution: {integrity: sha512-BnGcpxbhbtmJ2rNepTOIc8f1fFnVS2S7T5HLltFcmCNmij6iZq6JFERY0AxsdRd5PP0yp5FByiBngxo3TLokKQ==}
|
||||
peerDependencies:
|
||||
rescript: 11.x
|
||||
peerDependenciesMeta:
|
||||
rescript:
|
||||
optional: true
|
||||
|
||||
sync-child-process@1.0.2:
|
||||
resolution: {integrity: sha512-8lD+t2KrrScJ/7KXCSyfhT3/hRq78rC0wBFqNJXv3mZyn6hW2ypM05JmlSvtqRbeq6jqA94oHbxAr2vYsJ8vDA==}
|
||||
engines: {node: '>=16.0.0'}
|
||||
@@ -10530,6 +10541,8 @@ snapshots:
|
||||
|
||||
supports-preserve-symlinks-flag@1.0.0: {}
|
||||
|
||||
sury@10.0.0-rc.4: {}
|
||||
|
||||
sync-child-process@1.0.2:
|
||||
dependencies:
|
||||
sync-message-port: 1.1.3
|
||||
|
||||
Reference in new issue
Block a user