Skip to content

Commit 1bcea2a

Browse files
feat: added support for sury and minor modifications
1 parent 60a807f commit 1bcea2a

File tree

6 files changed

+132
-40
lines changed

6 files changed

+132
-40
lines changed

package.json

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -53,34 +53,15 @@
5353
"types": "./dist/vendors/convert.d.cts",
5454
"default": "./dist/vendors/convert.cjs"
5555
}
56-
},
57-
"./valibot": {
58-
"import": {
59-
"types": "./dist/vendors/valibot.d.ts",
60-
"default": "./dist/vendors/valibot.js"
61-
},
62-
"require": {
63-
"types": "./dist/vendors/valibot.d.cts",
64-
"default": "./dist/vendors/valibot.cjs"
65-
}
66-
},
67-
"./zod": {
68-
"import": {
69-
"types": "./dist/vendors/zod.d.ts",
70-
"default": "./dist/vendors/zod.js"
71-
},
72-
"require": {
73-
"types": "./dist/vendors/zod.d.cts",
74-
"default": "./dist/vendors/zod.cjs"
75-
}
7656
}
7757
},
7858
"peerDependencies": {
79-
"@standard-community/standard-json": "^0.3.4",
59+
"@standard-community/standard-json": "^0.3.5",
8060
"@standard-schema/spec": "^1.0.0",
8161
"arktype": "^2.1.20",
8262
"effect": "^3.17.14",
8363
"openapi-types": "^12.1.3",
64+
"sury": "^10.0.0",
8465
"typebox": "^1.0.0",
8566
"valibot": "^1.1.0",
8667
"zod": "^3.25.0 || ^4.0.0",
@@ -93,6 +74,9 @@
9374
"effect": {
9475
"optional": true
9576
},
77+
"sury": {
78+
"optional": true
79+
},
9680
"typebox": {
9781
"optional": true
9882
},

pnpm-lock.yaml

Lines changed: 22 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/vendors/convert.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ export function convertToOpenAPISchema(
5858
] as const;
5959

6060
nestedSchemaKeys.forEach((key) => {
61-
if (_jsonSchema[key]) {
61+
if (
62+
_jsonSchema[key] &&
63+
(typeof _jsonSchema[key] === "object" || Array.isArray(_jsonSchema[key]))
64+
) {
6265
if (
6366
key === "properties" ||
6467
key === "definitions" ||

src/vendors/index.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
import {
2-
errorMessageWrapper,
3-
openapiVendorMap,
4-
type ToOpenAPISchemaFn,
5-
} from "./utils.js";
1+
import { openapiVendorMap, type ToOpenAPISchemaFn } from "./utils.js";
62

73
export const getToOpenAPISchemaFn = async (
84
vendor: string,
@@ -21,15 +17,8 @@ export const getToOpenAPISchemaFn = async (
2117
case "zod":
2218
vendorFn = (await import("./zod.js")).default();
2319
break;
24-
case "arktype":
25-
case "effect":
26-
case "typebox":
27-
vendorFn = (await import("./default.js")).default();
28-
break;
2920
default:
30-
throw new Error(
31-
errorMessageWrapper(`Unsupported schema vendor "${vendor}".`),
32-
);
21+
vendorFn = (await import("./default.js")).default();
3322
}
3423

3524
openapiVendorMap.set(vendor, vendorFn);
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2+
3+
exports[`sury > basic 1`] = `
4+
{
5+
"components": undefined,
6+
"schema": {
7+
"additionalProperties": true,
8+
"properties": {
9+
"myString": {
10+
"type": "string",
11+
},
12+
"myUnion": {
13+
"anyOf": [
14+
{
15+
"type": "number",
16+
},
17+
{
18+
"type": "boolean",
19+
},
20+
],
21+
},
22+
},
23+
"required": [
24+
"myString",
25+
"myUnion",
26+
],
27+
"type": "object",
28+
},
29+
}
30+
`;
31+
32+
exports[`sury > with metadata 1`] = `
33+
{
34+
"components": {
35+
"schemas": {
36+
"MyNeatObjectSchema": {
37+
"additionalProperties": true,
38+
"description": "My neat object schema",
39+
"properties": {
40+
"myString": {
41+
"type": "string",
42+
},
43+
"myUnion": {
44+
"anyOf": [
45+
{
46+
"type": "number",
47+
},
48+
{
49+
"type": "boolean",
50+
},
51+
],
52+
},
53+
},
54+
"required": [
55+
"myString",
56+
"myUnion",
57+
],
58+
"type": "object",
59+
},
60+
},
61+
},
62+
"schema": {
63+
"$ref": "#/components/schemas/MyNeatObjectSchema",
64+
},
65+
}
66+
`;

tests/sury.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import * as S from "sury";
2+
import { describe, expect, it } from "vitest";
3+
4+
import { toOpenAPISchema } from "~/index.js";
5+
6+
describe("sury", () => {
7+
it("basic", async () => {
8+
const schema = S.schema({
9+
myString: S.string,
10+
myUnion: S.union([S.number, S.boolean]),
11+
});
12+
13+
const specs = await toOpenAPISchema(schema);
14+
expect(specs).toMatchSnapshot();
15+
});
16+
17+
it("with metadata", async () => {
18+
const schema = S.extendJSONSchema(
19+
S.schema({
20+
myString: S.string,
21+
myUnion: S.union([S.number, S.boolean]),
22+
}).with(S.meta, {
23+
description: "My neat object schema",
24+
}),
25+
{
26+
$id: "MyNeatObjectSchema",
27+
},
28+
);
29+
30+
const specs = await toOpenAPISchema(schema);
31+
expect(specs).toMatchSnapshot();
32+
});
33+
});

0 commit comments

Comments
 (0)