@standard-community/standard-openapi 0.1.1 → 0.2.0-rc.1

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/README.md CHANGED
@@ -18,10 +18,8 @@ For some specific vendor, install the respective package also -
18
18
 
19
19
  | Vendor | Package |
20
20
  | ------- | ------- |
21
- | Zod | `zod-openapi` |
22
- | Valibot | `@standard-community/standard-json` `@valibot/to-json-schema` `json-schema-walker` |
23
- | ArkType | `@standard-community/standard-json` `json-schema-walker` |
24
- | Effect Schema | `@standard-community/standard-json` `json-schema-walker` |
21
+ | Zod v3 | `zod-openapi` |
22
+ | Valibot | `@valibot/to-json-schema` |
25
23
 
26
24
  ## Usage
27
25
 
@@ -50,6 +48,7 @@ List of supported validators -
50
48
  | Zod | ✅ |
51
49
  | Valibot | ✅ |
52
50
  | ArkType | ✅ |
51
+ | Typebox | ✅ (Using [TypeMap](https://github.com/sinclairzx81/typemap) |
53
52
  | Effect Schema | 🛠️ |
54
53
 
55
54
  You can check the compatibility versions at [standardschema.dev](https://standardschema.dev/)
@@ -0,0 +1,81 @@
1
+ 'use strict';
2
+
3
+ function convertToOpenAPISchema(jsonSchema, context) {
4
+ const _jsonSchema = JSON.parse(JSON.stringify(jsonSchema));
5
+ if ("nullable" in _jsonSchema && _jsonSchema.nullable === true) {
6
+ if (_jsonSchema.type) {
7
+ if (Array.isArray(_jsonSchema.type)) {
8
+ if (!_jsonSchema.type.includes("null")) {
9
+ _jsonSchema.type.push("null");
10
+ }
11
+ } else {
12
+ _jsonSchema.type = [_jsonSchema.type, "null"];
13
+ }
14
+ } else {
15
+ _jsonSchema.type = ["null"];
16
+ }
17
+ delete _jsonSchema.nullable;
18
+ }
19
+ if (_jsonSchema.$schema) {
20
+ delete _jsonSchema.$schema;
21
+ }
22
+ const nestedSchemaKeys = [
23
+ "properties",
24
+ "additionalProperties",
25
+ "items",
26
+ "additionalItems",
27
+ "allOf",
28
+ "anyOf",
29
+ "oneOf",
30
+ "not",
31
+ "if",
32
+ "then",
33
+ "else",
34
+ "definitions",
35
+ "$defs",
36
+ "patternProperties",
37
+ "propertyNames",
38
+ "contains"
39
+ // "unevaluatedProperties",
40
+ // "unevaluatedItems",
41
+ ];
42
+ nestedSchemaKeys.forEach((key) => {
43
+ if (_jsonSchema[key]) {
44
+ if (key === "properties" || key === "definitions" || key === "$defs" || key === "patternProperties") {
45
+ for (const subKey in _jsonSchema[key]) {
46
+ _jsonSchema[key][subKey] = convertToOpenAPISchema(
47
+ _jsonSchema[key][subKey],
48
+ context
49
+ );
50
+ }
51
+ } else if (key === "allOf" || key === "anyOf" || key === "oneOf") {
52
+ _jsonSchema[key] = _jsonSchema[key].map(
53
+ (item) => convertToOpenAPISchema(item, context)
54
+ );
55
+ } else if (key === "items") {
56
+ if (Array.isArray(_jsonSchema[key])) {
57
+ _jsonSchema[key] = _jsonSchema[key].map(
58
+ (item) => convertToOpenAPISchema(item, context)
59
+ );
60
+ } else {
61
+ _jsonSchema[key] = convertToOpenAPISchema(_jsonSchema[key], context);
62
+ }
63
+ } else {
64
+ _jsonSchema[key] = convertToOpenAPISchema(_jsonSchema[key], context);
65
+ }
66
+ }
67
+ });
68
+ if (_jsonSchema.ref) {
69
+ const { ref, ...component } = _jsonSchema;
70
+ context.components.schemas = {
71
+ ...context.components.schemas,
72
+ [ref]: component
73
+ };
74
+ return {
75
+ $ref: `#/components/schemas/${ref}`
76
+ };
77
+ }
78
+ return _jsonSchema;
79
+ }
80
+
81
+ exports.convertToOpenAPISchema = convertToOpenAPISchema;
@@ -0,0 +1,79 @@
1
+ function convertToOpenAPISchema(jsonSchema, context) {
2
+ const _jsonSchema = JSON.parse(JSON.stringify(jsonSchema));
3
+ if ("nullable" in _jsonSchema && _jsonSchema.nullable === true) {
4
+ if (_jsonSchema.type) {
5
+ if (Array.isArray(_jsonSchema.type)) {
6
+ if (!_jsonSchema.type.includes("null")) {
7
+ _jsonSchema.type.push("null");
8
+ }
9
+ } else {
10
+ _jsonSchema.type = [_jsonSchema.type, "null"];
11
+ }
12
+ } else {
13
+ _jsonSchema.type = ["null"];
14
+ }
15
+ delete _jsonSchema.nullable;
16
+ }
17
+ if (_jsonSchema.$schema) {
18
+ delete _jsonSchema.$schema;
19
+ }
20
+ const nestedSchemaKeys = [
21
+ "properties",
22
+ "additionalProperties",
23
+ "items",
24
+ "additionalItems",
25
+ "allOf",
26
+ "anyOf",
27
+ "oneOf",
28
+ "not",
29
+ "if",
30
+ "then",
31
+ "else",
32
+ "definitions",
33
+ "$defs",
34
+ "patternProperties",
35
+ "propertyNames",
36
+ "contains"
37
+ // "unevaluatedProperties",
38
+ // "unevaluatedItems",
39
+ ];
40
+ nestedSchemaKeys.forEach((key) => {
41
+ if (_jsonSchema[key]) {
42
+ if (key === "properties" || key === "definitions" || key === "$defs" || key === "patternProperties") {
43
+ for (const subKey in _jsonSchema[key]) {
44
+ _jsonSchema[key][subKey] = convertToOpenAPISchema(
45
+ _jsonSchema[key][subKey],
46
+ context
47
+ );
48
+ }
49
+ } else if (key === "allOf" || key === "anyOf" || key === "oneOf") {
50
+ _jsonSchema[key] = _jsonSchema[key].map(
51
+ (item) => convertToOpenAPISchema(item, context)
52
+ );
53
+ } else if (key === "items") {
54
+ if (Array.isArray(_jsonSchema[key])) {
55
+ _jsonSchema[key] = _jsonSchema[key].map(
56
+ (item) => convertToOpenAPISchema(item, context)
57
+ );
58
+ } else {
59
+ _jsonSchema[key] = convertToOpenAPISchema(_jsonSchema[key], context);
60
+ }
61
+ } else {
62
+ _jsonSchema[key] = convertToOpenAPISchema(_jsonSchema[key], context);
63
+ }
64
+ }
65
+ });
66
+ if (_jsonSchema.ref) {
67
+ const { ref, ...component } = _jsonSchema;
68
+ context.components.schemas = {
69
+ ...context.components.schemas,
70
+ [ref]: component
71
+ };
72
+ return {
73
+ $ref: `#/components/schemas/${ref}`
74
+ };
75
+ }
76
+ return _jsonSchema;
77
+ }
78
+
79
+ export { convertToOpenAPISchema as c };
@@ -0,0 +1,11 @@
1
+ import { toJsonSchema } from '@standard-community/standard-json';
2
+ import { c as convertToOpenAPISchema } from './convert-BrW5dcj8.js';
3
+
4
+ async function getToOpenAPISchemaFn() {
5
+ return async (schema, context) => convertToOpenAPISchema(
6
+ await toJsonSchema(schema, context.options),
7
+ context
8
+ );
9
+ }
10
+
11
+ export { getToOpenAPISchemaFn as default };
@@ -0,0 +1,13 @@
1
+ 'use strict';
2
+
3
+ var standardJson = require('@standard-community/standard-json');
4
+ var convert = require('./convert--bmLap0k.cjs');
5
+
6
+ async function getToOpenAPISchemaFn() {
7
+ return async (schema, context) => convert.convertToOpenAPISchema(
8
+ await standardJson.toJsonSchema(schema, context.options),
9
+ context
10
+ );
11
+ }
12
+
13
+ exports.default = getToOpenAPISchemaFn;
@@ -0,0 +1,33 @@
1
+ 'use strict';
2
+
3
+ const errorMessageWrapper = (message) => `standard-openapi: ${message}`;
4
+
5
+ const getToOpenAPISchemaFn = async (vendor) => {
6
+ switch (vendor) {
7
+ case "valibot":
8
+ return (await Promise.resolve().then(function () { return require('./valibot-Bhs--VcX.cjs'); })).default();
9
+ case "zod":
10
+ return (await Promise.resolve().then(function () { return require('./zod-DBFeduLX.cjs'); })).default();
11
+ case "arktype":
12
+ case "effect":
13
+ return (await Promise.resolve().then(function () { return require('./default-CLvGm-jP.cjs'); })).default();
14
+ default:
15
+ throw new Error(
16
+ errorMessageWrapper(`Unsupported schema vendor "${vendor}".`)
17
+ );
18
+ }
19
+ };
20
+
21
+ const toOpenAPISchema = async (schema, options) => {
22
+ const components = {};
23
+ const _schema = await getToOpenAPISchemaFn(schema["~standard"].vendor).then(
24
+ (toOpenAPISchemaFn) => toOpenAPISchemaFn(schema, { components, options })
25
+ );
26
+ return {
27
+ schema: _schema,
28
+ components: Object.keys(components).length > 0 ? components : void 0
29
+ };
30
+ };
31
+
32
+ exports.errorMessageWrapper = errorMessageWrapper;
33
+ exports.toOpenAPISchema = toOpenAPISchema;
@@ -0,0 +1,30 @@
1
+ const errorMessageWrapper = (message) => `standard-openapi: ${message}`;
2
+
3
+ const getToOpenAPISchemaFn = async (vendor) => {
4
+ switch (vendor) {
5
+ case "valibot":
6
+ return (await import('./valibot-68LL3XLE.js')).default();
7
+ case "zod":
8
+ return (await import('./zod-DMhHBlXu.js')).default();
9
+ case "arktype":
10
+ case "effect":
11
+ return (await import('./default-B3j_H5mf.js')).default();
12
+ default:
13
+ throw new Error(
14
+ errorMessageWrapper(`Unsupported schema vendor "${vendor}".`)
15
+ );
16
+ }
17
+ };
18
+
19
+ const toOpenAPISchema = async (schema, options) => {
20
+ const components = {};
21
+ const _schema = await getToOpenAPISchemaFn(schema["~standard"].vendor).then(
22
+ (toOpenAPISchemaFn) => toOpenAPISchemaFn(schema, { components, options })
23
+ );
24
+ return {
25
+ schema: _schema,
26
+ components: Object.keys(components).length > 0 ? components : void 0
27
+ };
28
+ };
29
+
30
+ export { errorMessageWrapper as e, toOpenAPISchema as t };
package/dist/index.cjs CHANGED
@@ -1 +1,7 @@
1
- "use strict";var a=Object.defineProperty;var n=(e,r)=>a(e,"name",{value:r,configurable:!0});const o=n(async e=>{const r=e["~standard"].vendor;let t;switch(r){case"arktype":case"effect":case"valibot":t=Promise.resolve().then(function(){return require("./default-C7_LgS8R.cjs")});break;case"zod":t=Promise.resolve().then(function(){return require("./zod-hd0-fbCt.cjs")});break;default:throw new Error(`standard-openapi: Unsupported schema vendor "${r}"`)}return await(await t).generator(e)},"toOpenAPISchema");exports.toOpenAPISchema=o;
1
+ 'use strict';
2
+
3
+ var index = require('./index-6sg7Y400.cjs');
4
+
5
+
6
+
7
+ exports.toOpenAPISchema = index.toOpenAPISchema;
package/dist/index.d.cts CHANGED
@@ -1,62 +1,12 @@
1
- import * as zod_openapi from 'zod-openapi';
1
+ import { StandardSchemaV1 } from '@standard-schema/spec';
2
+ import { OpenAPIV3_1 } from 'openapi-types';
2
3
 
3
- /** The Standard Schema interface. */
4
- interface StandardSchemaV1<Input = unknown, Output = Input> {
5
- /** The Standard Schema properties. */
6
- readonly "~standard": StandardSchemaV1.Props<Input, Output>;
7
- }
8
- declare namespace StandardSchemaV1 {
9
- /** The Standard Schema properties interface. */
10
- export interface Props<Input = unknown, Output = Input> {
11
- /** The version number of the standard. */
12
- readonly version: 1;
13
- /** The vendor name of the schema library. */
14
- readonly vendor: string;
15
- /** Validates unknown input values. */
16
- readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
17
- /** Inferred types associated with the schema. */
18
- readonly types?: Types<Input, Output> | undefined;
19
- }
20
- /** The result interface of the validate function. */
21
- export type Result<Output> = SuccessResult<Output> | FailureResult;
22
- /** The result interface if validation succeeds. */
23
- export interface SuccessResult<Output> {
24
- /** The typed output value. */
25
- readonly value: Output;
26
- /** The non-existent issues. */
27
- readonly issues?: undefined;
28
- }
29
- /** The result interface if validation fails. */
30
- export interface FailureResult {
31
- /** The issues of failed validation. */
32
- readonly issues: ReadonlyArray<Issue>;
33
- }
34
- /** The issue interface of the failure output. */
35
- export interface Issue {
36
- /** The error message of the issue. */
37
- readonly message: string;
38
- /** The path of the issue, if any. */
39
- readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
40
- }
41
- /** The path segment interface of the issue. */
42
- export interface PathSegment {
43
- /** The key representing a path segment. */
44
- readonly key: PropertyKey;
45
- }
46
- /** The Standard Schema types interface. */
47
- export interface Types<Input = unknown, Output = Input> {
48
- /** The input type of the schema. */
49
- readonly input: Input;
50
- /** The output type of the schema. */
51
- readonly output: Output;
52
- }
53
- /** Infers the input type of a Standard Schema. */
54
- export type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["input"];
55
- /** Infers the output type of a Standard Schema. */
56
- export type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["output"];
57
- export { };
58
- }
59
-
60
- declare const toOpenAPISchema: (schema: StandardSchemaV1) => Promise<zod_openapi.SchemaResult>;
4
+ /**
5
+ * Converts a Standard Schema to a OpenAPI schema.
6
+ */
7
+ declare const toOpenAPISchema: (schema: StandardSchemaV1, options?: Record<string, unknown>) => Promise<{
8
+ schema: OpenAPIV3_1.SchemaObject;
9
+ components: OpenAPIV3_1.ComponentsObject | undefined;
10
+ }>;
61
11
 
62
12
  export { toOpenAPISchema };
package/dist/index.d.ts CHANGED
@@ -1,62 +1,12 @@
1
- import * as zod_openapi from 'zod-openapi';
1
+ import { StandardSchemaV1 } from '@standard-schema/spec';
2
+ import { OpenAPIV3_1 } from 'openapi-types';
2
3
 
3
- /** The Standard Schema interface. */
4
- interface StandardSchemaV1<Input = unknown, Output = Input> {
5
- /** The Standard Schema properties. */
6
- readonly "~standard": StandardSchemaV1.Props<Input, Output>;
7
- }
8
- declare namespace StandardSchemaV1 {
9
- /** The Standard Schema properties interface. */
10
- export interface Props<Input = unknown, Output = Input> {
11
- /** The version number of the standard. */
12
- readonly version: 1;
13
- /** The vendor name of the schema library. */
14
- readonly vendor: string;
15
- /** Validates unknown input values. */
16
- readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
17
- /** Inferred types associated with the schema. */
18
- readonly types?: Types<Input, Output> | undefined;
19
- }
20
- /** The result interface of the validate function. */
21
- export type Result<Output> = SuccessResult<Output> | FailureResult;
22
- /** The result interface if validation succeeds. */
23
- export interface SuccessResult<Output> {
24
- /** The typed output value. */
25
- readonly value: Output;
26
- /** The non-existent issues. */
27
- readonly issues?: undefined;
28
- }
29
- /** The result interface if validation fails. */
30
- export interface FailureResult {
31
- /** The issues of failed validation. */
32
- readonly issues: ReadonlyArray<Issue>;
33
- }
34
- /** The issue interface of the failure output. */
35
- export interface Issue {
36
- /** The error message of the issue. */
37
- readonly message: string;
38
- /** The path of the issue, if any. */
39
- readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
40
- }
41
- /** The path segment interface of the issue. */
42
- export interface PathSegment {
43
- /** The key representing a path segment. */
44
- readonly key: PropertyKey;
45
- }
46
- /** The Standard Schema types interface. */
47
- export interface Types<Input = unknown, Output = Input> {
48
- /** The input type of the schema. */
49
- readonly input: Input;
50
- /** The output type of the schema. */
51
- readonly output: Output;
52
- }
53
- /** Infers the input type of a Standard Schema. */
54
- export type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["input"];
55
- /** Infers the output type of a Standard Schema. */
56
- export type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["output"];
57
- export { };
58
- }
59
-
60
- declare const toOpenAPISchema: (schema: StandardSchemaV1) => Promise<zod_openapi.SchemaResult>;
4
+ /**
5
+ * Converts a Standard Schema to a OpenAPI schema.
6
+ */
7
+ declare const toOpenAPISchema: (schema: StandardSchemaV1, options?: Record<string, unknown>) => Promise<{
8
+ schema: OpenAPIV3_1.SchemaObject;
9
+ components: OpenAPIV3_1.ComponentsObject | undefined;
10
+ }>;
61
11
 
62
12
  export { toOpenAPISchema };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- var o=Object.defineProperty;var t=(e,a)=>o(e,"name",{value:a,configurable:!0});const n=t(async e=>{const a=e["~standard"].vendor;let r;switch(a){case"arktype":case"effect":case"valibot":r=import("./default-PnsbTDiK.js");break;case"zod":r=import("./zod-B4Z3YRnT.js");break;default:throw new Error(`standard-openapi: Unsupported schema vendor "${a}"`)}return await(await r).generator(e)},"toOpenAPISchema");export{n as toOpenAPISchema};
1
+ export { t as toOpenAPISchema } from './index-BBkvvbCv.js';
@@ -0,0 +1,36 @@
1
+ import { toJsonSchema } from '@standard-community/standard-json';
2
+ import { c as convertToOpenAPISchema } from './convert-BrW5dcj8.js';
3
+
4
+ async function getToOpenAPISchemaFn() {
5
+ return async (schema, context) => toJsonSchema(
6
+ schema,
7
+ {
8
+ // @ts-expect-error
9
+ overrideAction: ({ valibotAction, jsonSchema }) => {
10
+ const _jsonSchema = convertToOpenAPISchema(jsonSchema, context);
11
+ if (valibotAction.kind === "metadata" && valibotAction.type === "metadata" && !("$ref" in _jsonSchema)) {
12
+ const metadata = valibotAction.metadata;
13
+ if (metadata.example !== void 0) {
14
+ _jsonSchema.example = metadata.example;
15
+ }
16
+ if (metadata.examples && metadata.examples.length > 0) {
17
+ _jsonSchema.examples = metadata.examples;
18
+ }
19
+ if (metadata.ref) {
20
+ context.components.schemas = {
21
+ ...context.components.schemas,
22
+ [metadata.ref]: _jsonSchema
23
+ };
24
+ return {
25
+ $ref: `#/components/schemas/${metadata.ref}`
26
+ };
27
+ }
28
+ }
29
+ return _jsonSchema;
30
+ },
31
+ ...context.options
32
+ }
33
+ );
34
+ }
35
+
36
+ export { getToOpenAPISchemaFn as default };
@@ -0,0 +1,38 @@
1
+ 'use strict';
2
+
3
+ var standardJson = require('@standard-community/standard-json');
4
+ var convert = require('./convert--bmLap0k.cjs');
5
+
6
+ async function getToOpenAPISchemaFn() {
7
+ return async (schema, context) => standardJson.toJsonSchema(
8
+ schema,
9
+ {
10
+ // @ts-expect-error
11
+ overrideAction: ({ valibotAction, jsonSchema }) => {
12
+ const _jsonSchema = convert.convertToOpenAPISchema(jsonSchema, context);
13
+ if (valibotAction.kind === "metadata" && valibotAction.type === "metadata" && !("$ref" in _jsonSchema)) {
14
+ const metadata = valibotAction.metadata;
15
+ if (metadata.example !== void 0) {
16
+ _jsonSchema.example = metadata.example;
17
+ }
18
+ if (metadata.examples && metadata.examples.length > 0) {
19
+ _jsonSchema.examples = metadata.examples;
20
+ }
21
+ if (metadata.ref) {
22
+ context.components.schemas = {
23
+ ...context.components.schemas,
24
+ [metadata.ref]: _jsonSchema
25
+ };
26
+ return {
27
+ $ref: `#/components/schemas/${metadata.ref}`
28
+ };
29
+ }
30
+ }
31
+ return _jsonSchema;
32
+ },
33
+ ...context.options
34
+ }
35
+ );
36
+ }
37
+
38
+ exports.default = getToOpenAPISchemaFn;
@@ -0,0 +1,37 @@
1
+ 'use strict';
2
+
3
+ var standardJson = require('@standard-community/standard-json');
4
+ var convert = require('./convert--bmLap0k.cjs');
5
+ var index = require('./index-6sg7Y400.cjs');
6
+
7
+ async function getToOpenAPISchemaFn() {
8
+ return async (schema, context) => {
9
+ if ("_zod" in schema) {
10
+ return convert.convertToOpenAPISchema(
11
+ await standardJson.toJsonSchema(schema, context.options),
12
+ context
13
+ );
14
+ }
15
+ try {
16
+ const { createSchema } = await import('zod-openapi');
17
+ const { schema: _schema, components } = createSchema(
18
+ // @ts-expect-error
19
+ schema,
20
+ context.options
21
+ );
22
+ if (components) {
23
+ context.components.schemas = {
24
+ ...context.components.schemas,
25
+ ...components
26
+ };
27
+ }
28
+ return _schema;
29
+ } catch {
30
+ throw new Error(
31
+ index.errorMessageWrapper(`Missing dependencies "zod-openapi v4".`)
32
+ );
33
+ }
34
+ };
35
+ }
36
+
37
+ exports.default = getToOpenAPISchemaFn;
@@ -0,0 +1,35 @@
1
+ import { toJsonSchema } from '@standard-community/standard-json';
2
+ import { c as convertToOpenAPISchema } from './convert-BrW5dcj8.js';
3
+ import { e as errorMessageWrapper } from './index-BBkvvbCv.js';
4
+
5
+ async function getToOpenAPISchemaFn() {
6
+ return async (schema, context) => {
7
+ if ("_zod" in schema) {
8
+ return convertToOpenAPISchema(
9
+ await toJsonSchema(schema, context.options),
10
+ context
11
+ );
12
+ }
13
+ try {
14
+ const { createSchema } = await import('zod-openapi');
15
+ const { schema: _schema, components } = createSchema(
16
+ // @ts-expect-error
17
+ schema,
18
+ context.options
19
+ );
20
+ if (components) {
21
+ context.components.schemas = {
22
+ ...context.components.schemas,
23
+ ...components
24
+ };
25
+ }
26
+ return _schema;
27
+ } catch {
28
+ throw new Error(
29
+ errorMessageWrapper(`Missing dependencies "zod-openapi v4".`)
30
+ );
31
+ }
32
+ };
33
+ }
34
+
35
+ export { getToOpenAPISchemaFn as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@standard-community/standard-openapi",
3
- "version": "0.1.1",
3
+ "version": "0.2.0-rc.1",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.cjs",
@@ -40,32 +40,40 @@
40
40
  }
41
41
  },
42
42
  "peerDependencies": {
43
- "@standard-community/standard-json": "^0.1.0",
44
- "json-schema-walker": "^2.0.0",
45
- "zod-openapi": "^4.0.0"
43
+ "@standard-community/standard-json": "^0.3.0-rc.1",
44
+ "@standard-schema/spec": "^1.0.0",
45
+ "arktype": "^2.1.20",
46
+ "openapi-types": "^12.1.3",
47
+ "valibot": "^1.1.0",
48
+ "zod": "^3.25.0 || ^4.0.0",
49
+ "zod-openapi": "^4"
46
50
  },
47
51
  "peerDependenciesMeta": {
48
- "zod-openapi": {
52
+ "arktype": {
53
+ "optional": true
54
+ },
55
+ "valibot": {
49
56
  "optional": true
50
57
  },
51
- "@standard-community/standard-json": {
58
+ "zod": {
52
59
  "optional": true
53
60
  },
54
- "json-schema-walker": {
61
+ "zod-openapi": {
55
62
  "optional": true
56
63
  }
57
64
  },
58
65
  "devDependencies": {
59
- "@apidevtools/json-schema-ref-parser": "^11.9.3",
60
- "@standard-schema/spec": "^1.0.0",
66
+ "@biomejs/biome": "^2.0.4",
61
67
  "@types/json-schema": "^7.0.15",
62
- "arktype": "^2.1.9",
63
- "openapi-types": "^12.1.3",
64
- "pkgroll": "^2.5.1",
65
- "valibot": "1.0.0-rc.4",
66
- "zod": "^3.24.2"
68
+ "@valibot/to-json-schema": "^1.3.0",
69
+ "pkgroll": "^2.13.1",
70
+ "typescript": "^5.8.3",
71
+ "vitest": "^3.2.4",
72
+ "zod-to-json-schema": "^3.24.6"
67
73
  },
68
74
  "scripts": {
69
- "build": "pkgroll --minify --clean-dist"
75
+ "build": "pkgroll --clean-dist",
76
+ "format": "biome check --write .",
77
+ "test": "vitest"
70
78
  }
71
79
  }
@@ -1 +0,0 @@
1
- "use strict";var d=Object.defineProperty;var i=(e,t)=>d(e,"name",{value:t,configurable:!0});var u=require("json-schema-walker"),p=require("@standard-community/standard-json");const y=["$ref","definitions","title","multipleOf","maximum","exclusiveMaximum","minimum","exclusiveMinimum","maxLength","minLength","pattern","maxItems","minItems","uniqueItems","maxProperties","minProperties","required","enum","type","not","allOf","oneOf","anyOf","items","properties","additionalProperties","description","format","default","nullable","discriminator","readOnly","writeOnly","example","externalDocs","deprecated","xml"];class c extends Error{static{i(this,"InvalidTypeError")}constructor(t){super(t),this.name="InvalidTypeError",this.message=t}}const f="x-",v=i(async(e,t)=>{if(typeof e!="object")return e;if(e.type){const r=new u.Walker;return await r.loadSchema({definitions:t.definitions||[],...e,$schema:t.$schema},{dereference:!0,cloneSchema:!0,dereferenceOptions:{dereference:{circular:"ignore"}}}),await r.walk(s,r.vocabularies.DRAFT_07),"definitions"in r.rootSchema&&(r.rootSchema.definitions=void 0),r.rootSchema}if(Array.isArray(e)){const r=e;if(r.includes("null")){const o=r.filter(a=>a!=="null");return{type:o.length===1?o[0]:o,nullable:!0}}}return e},"handleDefinition"),x=i(async e=>{const t=new u.Walker;await t.loadSchema(e),await t.walk(s,t.vocabularies.DRAFT_07);const n=t.rootSchema;if(n?.definitions)for(const r in n.definitions){const l=n.definitions[r];n.definitions[r]=await v(l,e)}return n},"convert");function w(e){return typeof e!="object"||(e.$schema=void 0,e.$id=void 0,"id"in e&&(e.id=void 0)),e}i(w,"stripIllegalKeywords");function s(e){let t=e;return t&&(t=w(t),t=S(t),t=M(t),t=O(t),t=k(t),t=T(t),t=$(t),t=P(t),typeof t.patternProperties=="object"&&(t=g(t)),t.type==="array"&&typeof t.items>"u"&&(t.items={}),t=j(t),t)}i(s,"convertSchema");const b=new Set(["null","boolean","object","array","number","string","integer"]);function A(e){if(typeof e=="object"&&!Array.isArray(e)&&(e&&"$ref"in e&&e.$ref||e&&"properties"in e&&e.properties))return;const t=Array.isArray(e)?e:[e];for(const n of t)if(n&&!b.has(n))throw new c(`Type "${n}" is not a valid type`)}i(A,"validateType");function O(e){const t=e.dependencies;if(typeof t!="object")return e;e.dependencies=void 0,Array.isArray(e.allOf)||(e.allOf=[]);for(const n in t){const r={oneOf:[{not:{required:[n]}},{required:[n,t[n]].flat()}]};e.allOf.push(r)}return e}i(O,"convertDependencies");function k(e){for(const t of["oneOf","anyOf"]){const n=e[t];if(!n)continue;if(!Array.isArray(n)||!n.some(o=>o.type==="null"))return e;const l=n.filter(o=>o.type!=="null");for(const o of l)o.nullable=!0;e[t]=l}return e}i(k,"convertNullable");function S(e){if(typeof e!="object"||e.type===void 0)return e;if(A(e.type),Array.isArray(e.type)){e.type.includes("null")&&(e.nullable=!0);const t=e.type.filter(n=>n!=="null");t.length===0?e.type=void 0:t.length===1?e.type=t[0]:(e.type=void 0,e.anyOf=t.map(n=>({type:n})))}else e.type==="null"&&(e.type=void 0,e.nullable=!0);return e}i(S,"convertTypes");function g(e){return e["x-patternProperties"]=e.patternProperties,e.patternProperties=void 0,e.additionalProperties??=!0,e}i(g,"convertPatternProperties");function j(e){const t=Object.keys(e);for(const n of t)if(!n.startsWith(f)&&!y.includes(n)){const r=`${f}${n}`;e[r]=e[n],e[n]=void 0}return e}i(j,"convertIllegalKeywordsAsExtensions");function P(e){return e.examples&&Array.isArray(e.examples)&&(e.example=e.examples[0],e.examples=void 0),e}i(P,"convertExamples");function M(e){return typeof e.const<"u"&&(e.enum=[e.const],e.const=void 0),e}i(M,"rewriteConst");function T(e){return typeof e!="object"||"if"in e&&e.if&&e.then&&(e.oneOf=[{allOf:[e.if,e.then].filter(Boolean)},{allOf:[{not:e.if},e.else].filter(Boolean)}],e.if=void 0,e.then=void 0,e.else=void 0),e}i(T,"rewriteIfThenElse");function $(e){return typeof e.exclusiveMaximum=="number"&&(e.maximum=e.exclusiveMaximum,e.exclusiveMaximum=!0),typeof e.exclusiveMinimum=="number"&&(e.minimum=e.exclusiveMinimum,e.exclusiveMinimum=!0),e}i($,"rewriteExclusiveMinMax");const E=i(async e=>{const t=p.toJsonSchema(e);return{schema:await x(t)}},"generator");exports.generator=E;
@@ -1 +0,0 @@
1
- var a=Object.defineProperty;var r=(e,t)=>a(e,"name",{value:t,configurable:!0});import{Walker as f}from"json-schema-walker";import{toJsonSchema as d}from"@standard-community/standard-json";const y=["$ref","definitions","title","multipleOf","maximum","exclusiveMaximum","minimum","exclusiveMinimum","maxLength","minLength","pattern","maxItems","minItems","uniqueItems","maxProperties","minProperties","required","enum","type","not","allOf","oneOf","anyOf","items","properties","additionalProperties","description","format","default","nullable","discriminator","readOnly","writeOnly","example","externalDocs","deprecated","xml"];class c extends Error{static{r(this,"InvalidTypeError")}constructor(t){super(t),this.name="InvalidTypeError",this.message=t}}const u="x-",v=r(async(e,t)=>{if(typeof e!="object")return e;if(e.type){const i=new f;return await i.loadSchema({definitions:t.definitions||[],...e,$schema:t.$schema},{dereference:!0,cloneSchema:!0,dereferenceOptions:{dereference:{circular:"ignore"}}}),await i.walk(s,i.vocabularies.DRAFT_07),"definitions"in i.rootSchema&&(i.rootSchema.definitions=void 0),i.rootSchema}if(Array.isArray(e)){const i=e;if(i.includes("null")){const o=i.filter(p=>p!=="null");return{type:o.length===1?o[0]:o,nullable:!0}}}return e},"handleDefinition"),x=r(async e=>{const t=new f;await t.loadSchema(e),await t.walk(s,t.vocabularies.DRAFT_07);const n=t.rootSchema;if(n?.definitions)for(const i in n.definitions){const l=n.definitions[i];n.definitions[i]=await v(l,e)}return n},"convert");function w(e){return typeof e!="object"||(e.$schema=void 0,e.$id=void 0,"id"in e&&(e.id=void 0)),e}r(w,"stripIllegalKeywords");function s(e){let t=e;return t&&(t=w(t),t=g(t),t=m(t),t=O(t),t=S(t),t=M(t),t=T(t),t=j(t),typeof t.patternProperties=="object"&&(t=k(t)),t.type==="array"&&typeof t.items>"u"&&(t.items={}),t=P(t),t)}r(s,"convertSchema");const b=new Set(["null","boolean","object","array","number","string","integer"]);function A(e){if(typeof e=="object"&&!Array.isArray(e)&&(e&&"$ref"in e&&e.$ref||e&&"properties"in e&&e.properties))return;const t=Array.isArray(e)?e:[e];for(const n of t)if(n&&!b.has(n))throw new c(`Type "${n}" is not a valid type`)}r(A,"validateType");function O(e){const t=e.dependencies;if(typeof t!="object")return e;e.dependencies=void 0,Array.isArray(e.allOf)||(e.allOf=[]);for(const n in t){const i={oneOf:[{not:{required:[n]}},{required:[n,t[n]].flat()}]};e.allOf.push(i)}return e}r(O,"convertDependencies");function S(e){for(const t of["oneOf","anyOf"]){const n=e[t];if(!n)continue;if(!Array.isArray(n)||!n.some(o=>o.type==="null"))return e;const l=n.filter(o=>o.type!=="null");for(const o of l)o.nullable=!0;e[t]=l}return e}r(S,"convertNullable");function g(e){if(typeof e!="object"||e.type===void 0)return e;if(A(e.type),Array.isArray(e.type)){e.type.includes("null")&&(e.nullable=!0);const t=e.type.filter(n=>n!=="null");t.length===0?e.type=void 0:t.length===1?e.type=t[0]:(e.type=void 0,e.anyOf=t.map(n=>({type:n})))}else e.type==="null"&&(e.type=void 0,e.nullable=!0);return e}r(g,"convertTypes");function k(e){return e["x-patternProperties"]=e.patternProperties,e.patternProperties=void 0,e.additionalProperties??=!0,e}r(k,"convertPatternProperties");function P(e){const t=Object.keys(e);for(const n of t)if(!n.startsWith(u)&&!y.includes(n)){const i=`${u}${n}`;e[i]=e[n],e[n]=void 0}return e}r(P,"convertIllegalKeywordsAsExtensions");function j(e){return e.examples&&Array.isArray(e.examples)&&(e.example=e.examples[0],e.examples=void 0),e}r(j,"convertExamples");function m(e){return typeof e.const<"u"&&(e.enum=[e.const],e.const=void 0),e}r(m,"rewriteConst");function M(e){return typeof e!="object"||"if"in e&&e.if&&e.then&&(e.oneOf=[{allOf:[e.if,e.then].filter(Boolean)},{allOf:[{not:e.if},e.else].filter(Boolean)}],e.if=void 0,e.then=void 0,e.else=void 0),e}r(M,"rewriteIfThenElse");function T(e){return typeof e.exclusiveMaximum=="number"&&(e.maximum=e.exclusiveMaximum,e.exclusiveMaximum=!0),typeof e.exclusiveMinimum=="number"&&(e.minimum=e.exclusiveMinimum,e.exclusiveMinimum=!0),e}r(T,"rewriteExclusiveMinMax");const $=r(async e=>{const t=d(e);return{schema:await x(t)}},"generator");export{$ as generator};
@@ -1 +0,0 @@
1
- var t=Object.defineProperty;var o=(e,r)=>t(e,"name",{value:r,configurable:!0});import{createSchema as a}from"zod-openapi";const c=o((e,r)=>a(e,r),"generator");export{c as generator};
@@ -1 +0,0 @@
1
- "use strict";var t=Object.defineProperty;var a=(e,r)=>t(e,"name",{value:r,configurable:!0});var c=require("zod-openapi");const n=a((e,r)=>c.createSchema(e,r),"generator");exports.generator=n;