@standard-community/standard-openapi 0.2.0-rc.0 → 0.2.0

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@4` |
22
+ | Valibot | `@valibot/to-json-schema` |
25
23
 
26
24
  ## Usage
27
25
 
@@ -41,16 +39,27 @@ const schema = v.pipe(
41
39
  const openapiSchema = await toOpenAPISchema(schema);
42
40
  ```
43
41
 
44
- ## Compatibility
42
+ ### Sync Usage
45
43
 
46
- List of supported validators -
44
+ This is useful for -
47
45
 
48
- | Vendor | Supported |
49
- | ------- | ------- |
50
- | Zod | ✅ |
51
- | Valibot | ✅ |
52
- | ArkType | |
53
- | Typebox | (Using [TypeMap](https://github.com/sinclairzx81/typemap) |
54
- | Effect Schema | 🛠️ |
46
+ 1. Adding support for Unsupported validation libs, like Sury
47
+ 2. Customize the toOpenAPISchema of a supported lib
48
+
49
+ ```ts
50
+ import { toOpenAPISchema, loadVendor } from "@standard-community/standard-openapi";
51
+ import { convertSchemaToJson } from "your-validation-lib";
52
+
53
+ // The lib should support Standard Schema
54
+ // as we use 'schema["~standard"].vendor' to get the vendor name
55
+ // Eg. loadVendor(zod["~standard"].vendor, convertorFunction)
56
+ loadVendor("validation-lib-name", convertSchemaToJson)
55
57
 
56
- You can check the compatibility versions at [standardschema.dev](https://standardschema.dev/)
58
+ // Define your validation schema
59
+ const schema = {
60
+ // ...
61
+ };
62
+
63
+ // Convert it to OpenAPI Schema
64
+ const openapiSchema = toOpenAPISchema(schema);
65
+ ```
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- function convertToOpenAPISchema(jsonSchema) {
3
+ function convertToOpenAPISchema(jsonSchema, context) {
4
4
  const _jsonSchema = JSON.parse(JSON.stringify(jsonSchema));
5
5
  if ("nullable" in _jsonSchema && _jsonSchema.nullable === true) {
6
6
  if (_jsonSchema.type) {
@@ -44,22 +44,37 @@ function convertToOpenAPISchema(jsonSchema) {
44
44
  if (key === "properties" || key === "definitions" || key === "$defs" || key === "patternProperties") {
45
45
  for (const subKey in _jsonSchema[key]) {
46
46
  _jsonSchema[key][subKey] = convertToOpenAPISchema(
47
- _jsonSchema[key][subKey]
47
+ _jsonSchema[key][subKey],
48
+ context
48
49
  );
49
50
  }
50
51
  } else if (key === "allOf" || key === "anyOf" || key === "oneOf") {
51
- _jsonSchema[key] = _jsonSchema[key].map(convertToOpenAPISchema);
52
+ _jsonSchema[key] = _jsonSchema[key].map(
53
+ (item) => convertToOpenAPISchema(item, context)
54
+ );
52
55
  } else if (key === "items") {
53
56
  if (Array.isArray(_jsonSchema[key])) {
54
- _jsonSchema[key] = _jsonSchema[key].map(convertToOpenAPISchema);
57
+ _jsonSchema[key] = _jsonSchema[key].map(
58
+ (item) => convertToOpenAPISchema(item, context)
59
+ );
55
60
  } else {
56
- _jsonSchema[key] = convertToOpenAPISchema(_jsonSchema[key]);
61
+ _jsonSchema[key] = convertToOpenAPISchema(_jsonSchema[key], context);
57
62
  }
58
63
  } else {
59
- _jsonSchema[key] = convertToOpenAPISchema(_jsonSchema[key]);
64
+ _jsonSchema[key] = convertToOpenAPISchema(_jsonSchema[key], context);
60
65
  }
61
66
  }
62
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
+ }
63
78
  return _jsonSchema;
64
79
  }
65
80
 
@@ -1,4 +1,4 @@
1
- function convertToOpenAPISchema(jsonSchema) {
1
+ function convertToOpenAPISchema(jsonSchema, context) {
2
2
  const _jsonSchema = JSON.parse(JSON.stringify(jsonSchema));
3
3
  if ("nullable" in _jsonSchema && _jsonSchema.nullable === true) {
4
4
  if (_jsonSchema.type) {
@@ -42,22 +42,37 @@ function convertToOpenAPISchema(jsonSchema) {
42
42
  if (key === "properties" || key === "definitions" || key === "$defs" || key === "patternProperties") {
43
43
  for (const subKey in _jsonSchema[key]) {
44
44
  _jsonSchema[key][subKey] = convertToOpenAPISchema(
45
- _jsonSchema[key][subKey]
45
+ _jsonSchema[key][subKey],
46
+ context
46
47
  );
47
48
  }
48
49
  } else if (key === "allOf" || key === "anyOf" || key === "oneOf") {
49
- _jsonSchema[key] = _jsonSchema[key].map(convertToOpenAPISchema);
50
+ _jsonSchema[key] = _jsonSchema[key].map(
51
+ (item) => convertToOpenAPISchema(item, context)
52
+ );
50
53
  } else if (key === "items") {
51
54
  if (Array.isArray(_jsonSchema[key])) {
52
- _jsonSchema[key] = _jsonSchema[key].map(convertToOpenAPISchema);
55
+ _jsonSchema[key] = _jsonSchema[key].map(
56
+ (item) => convertToOpenAPISchema(item, context)
57
+ );
53
58
  } else {
54
- _jsonSchema[key] = convertToOpenAPISchema(_jsonSchema[key]);
59
+ _jsonSchema[key] = convertToOpenAPISchema(_jsonSchema[key], context);
55
60
  }
56
61
  } else {
57
- _jsonSchema[key] = convertToOpenAPISchema(_jsonSchema[key]);
62
+ _jsonSchema[key] = convertToOpenAPISchema(_jsonSchema[key], context);
58
63
  }
59
64
  }
60
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
+ }
61
76
  return _jsonSchema;
62
77
  }
63
78
 
@@ -1,12 +1,10 @@
1
1
  import { toJsonSchema } from '@standard-community/standard-json';
2
- import { c as convertToOpenAPISchema } from './convert-B1hz_0d-.js';
2
+ import { c as convertToOpenAPISchema } from './convert-BrW5dcj8.js';
3
3
 
4
4
  async function getToOpenAPISchemaFn() {
5
5
  return async (schema, context) => convertToOpenAPISchema(
6
- await toJsonSchema(
7
- schema,
8
- context.options
9
- )
6
+ await toJsonSchema(schema, context.options),
7
+ context
10
8
  );
11
9
  }
12
10
 
@@ -1,14 +1,12 @@
1
1
  'use strict';
2
2
 
3
3
  var standardJson = require('@standard-community/standard-json');
4
- var convert = require('./convert-Bgc7pB9z.cjs');
4
+ var convert = require('./convert--bmLap0k.cjs');
5
5
 
6
6
  async function getToOpenAPISchemaFn() {
7
7
  return async (schema, context) => convert.convertToOpenAPISchema(
8
- await standardJson.toJsonSchema(
9
- schema,
10
- context.options
11
- )
8
+ await standardJson.toJsonSchema(schema, context.options),
9
+ context
12
10
  );
13
11
  }
14
12
 
@@ -0,0 +1,64 @@
1
+ import { quansync } from 'quansync';
2
+
3
+ const errorMessageWrapper = (message) => `standard-openapi: ${message}`;
4
+ const openapiVendorMap = /* @__PURE__ */ new Map();
5
+
6
+ const getToOpenAPISchemaFn = async (vendor) => {
7
+ const cached = openapiVendorMap.get(vendor);
8
+ if (cached) {
9
+ return cached;
10
+ }
11
+ let vendorFnPromise;
12
+ switch (vendor) {
13
+ case "valibot":
14
+ vendorFnPromise = (await import('./valibot-pYvQeYpK.js')).default();
15
+ break;
16
+ case "zod":
17
+ vendorFnPromise = (await import('./zod-BzrcyUsw.js')).default();
18
+ break;
19
+ case "arktype":
20
+ case "effect":
21
+ vendorFnPromise = (await import('./default-B3j_H5mf.js')).default();
22
+ break;
23
+ default:
24
+ throw new Error(
25
+ errorMessageWrapper(`Unsupported schema vendor "${vendor}".`)
26
+ );
27
+ }
28
+ const vendorFn = await vendorFnPromise;
29
+ openapiVendorMap.set(vendor, vendorFn);
30
+ return vendorFn;
31
+ };
32
+
33
+ const toOpenAPISchema = quansync({
34
+ sync: (schema, context = {}) => {
35
+ const fn = openapiVendorMap.get(schema["~standard"].vendor);
36
+ if (!fn) {
37
+ throw new Error(
38
+ errorMessageWrapper(
39
+ `Unsupported schema vendor "${schema["~standard"].vendor}".`
40
+ )
41
+ );
42
+ }
43
+ const { components = {}, options } = context;
44
+ const _schema = fn(schema, { components, options });
45
+ return {
46
+ schema: _schema,
47
+ components: Object.keys(components).length > 0 ? components : void 0
48
+ };
49
+ },
50
+ async: async (schema, context = {}) => {
51
+ const fn = await getToOpenAPISchemaFn(schema["~standard"].vendor);
52
+ const { components = {}, options } = context;
53
+ const _schema = await fn(schema, { components, options });
54
+ return {
55
+ schema: _schema,
56
+ components: Object.keys(components).length > 0 ? components : void 0
57
+ };
58
+ }
59
+ });
60
+ function loadVendor(vendor, fn) {
61
+ openapiVendorMap.set(vendor, fn);
62
+ }
63
+
64
+ export { errorMessageWrapper as e, loadVendor as l, toOpenAPISchema as t };
@@ -0,0 +1,68 @@
1
+ 'use strict';
2
+
3
+ var quansync = require('quansync');
4
+
5
+ const errorMessageWrapper = (message) => `standard-openapi: ${message}`;
6
+ const openapiVendorMap = /* @__PURE__ */ new Map();
7
+
8
+ const getToOpenAPISchemaFn = async (vendor) => {
9
+ const cached = openapiVendorMap.get(vendor);
10
+ if (cached) {
11
+ return cached;
12
+ }
13
+ let vendorFnPromise;
14
+ switch (vendor) {
15
+ case "valibot":
16
+ vendorFnPromise = (await Promise.resolve().then(function () { return require('./valibot-CmK54MCp.cjs'); })).default();
17
+ break;
18
+ case "zod":
19
+ vendorFnPromise = (await Promise.resolve().then(function () { return require('./zod-BX8Nhg6z.cjs'); })).default();
20
+ break;
21
+ case "arktype":
22
+ case "effect":
23
+ vendorFnPromise = (await Promise.resolve().then(function () { return require('./default-CLvGm-jP.cjs'); })).default();
24
+ break;
25
+ default:
26
+ throw new Error(
27
+ errorMessageWrapper(`Unsupported schema vendor "${vendor}".`)
28
+ );
29
+ }
30
+ const vendorFn = await vendorFnPromise;
31
+ openapiVendorMap.set(vendor, vendorFn);
32
+ return vendorFn;
33
+ };
34
+
35
+ const toOpenAPISchema = quansync.quansync({
36
+ sync: (schema, context = {}) => {
37
+ const fn = openapiVendorMap.get(schema["~standard"].vendor);
38
+ if (!fn) {
39
+ throw new Error(
40
+ errorMessageWrapper(
41
+ `Unsupported schema vendor "${schema["~standard"].vendor}".`
42
+ )
43
+ );
44
+ }
45
+ const { components = {}, options } = context;
46
+ const _schema = fn(schema, { components, options });
47
+ return {
48
+ schema: _schema,
49
+ components: Object.keys(components).length > 0 ? components : void 0
50
+ };
51
+ },
52
+ async: async (schema, context = {}) => {
53
+ const fn = await getToOpenAPISchemaFn(schema["~standard"].vendor);
54
+ const { components = {}, options } = context;
55
+ const _schema = await fn(schema, { components, options });
56
+ return {
57
+ schema: _schema,
58
+ components: Object.keys(components).length > 0 ? components : void 0
59
+ };
60
+ }
61
+ });
62
+ function loadVendor(vendor, fn) {
63
+ openapiVendorMap.set(vendor, fn);
64
+ }
65
+
66
+ exports.errorMessageWrapper = errorMessageWrapper;
67
+ exports.loadVendor = loadVendor;
68
+ exports.toOpenAPISchema = toOpenAPISchema;
package/dist/index.cjs CHANGED
@@ -1,7 +1,9 @@
1
1
  'use strict';
2
2
 
3
- var index = require('./index-iywZ_eHa.cjs');
3
+ require('quansync');
4
+ var index = require('./index-lYeS5F9z.cjs');
4
5
 
5
6
 
6
7
 
8
+ exports.loadVendor = index.loadVendor;
7
9
  exports.toOpenAPISchema = index.toOpenAPISchema;
package/dist/index.d.cts CHANGED
@@ -1,12 +1,21 @@
1
- import { StandardSchemaV1 } from '@standard-schema/spec';
1
+ import * as quansync from 'quansync';
2
+ import * as openapi_types from 'openapi-types';
2
3
  import { OpenAPIV3_1 } from 'openapi-types';
4
+ import { StandardSchemaV1 } from '@standard-schema/spec';
5
+
6
+ type ToOpenAPISchemaContext = {
7
+ components: OpenAPIV3_1.ComponentsObject;
8
+ options?: Record<string, unknown>;
9
+ };
10
+ type ToOpenAPISchemaFn = (schema: StandardSchemaV1, context: ToOpenAPISchemaContext) => OpenAPIV3_1.SchemaObject | Promise<OpenAPIV3_1.SchemaObject>;
3
11
 
4
12
  /**
5
13
  * Converts a Standard Schema to a OpenAPI schema.
6
14
  */
7
- declare const toOpenAPISchema: (schema: StandardSchemaV1, options?: Record<string, unknown>) => Promise<{
8
- schema: OpenAPIV3_1.SchemaObject;
9
- components: OpenAPIV3_1.ComponentsObject | undefined;
10
- }>;
15
+ declare const toOpenAPISchema: quansync.QuansyncFn<{
16
+ schema: openapi_types.OpenAPIV3_1.SchemaObject | Promise<openapi_types.OpenAPIV3_1.SchemaObject>;
17
+ components: openapi_types.OpenAPIV3_1.ComponentsObject | undefined;
18
+ }, [schema: StandardSchemaV1<unknown, unknown>, context?: Partial<ToOpenAPISchemaContext> | undefined]>;
19
+ declare function loadVendor(vendor: string, fn: ToOpenAPISchemaFn): void;
11
20
 
12
- export { toOpenAPISchema };
21
+ export { loadVendor, toOpenAPISchema };
package/dist/index.d.ts CHANGED
@@ -1,12 +1,21 @@
1
- import { StandardSchemaV1 } from '@standard-schema/spec';
1
+ import * as quansync from 'quansync';
2
+ import * as openapi_types from 'openapi-types';
2
3
  import { OpenAPIV3_1 } from 'openapi-types';
4
+ import { StandardSchemaV1 } from '@standard-schema/spec';
5
+
6
+ type ToOpenAPISchemaContext = {
7
+ components: OpenAPIV3_1.ComponentsObject;
8
+ options?: Record<string, unknown>;
9
+ };
10
+ type ToOpenAPISchemaFn = (schema: StandardSchemaV1, context: ToOpenAPISchemaContext) => OpenAPIV3_1.SchemaObject | Promise<OpenAPIV3_1.SchemaObject>;
3
11
 
4
12
  /**
5
13
  * Converts a Standard Schema to a OpenAPI schema.
6
14
  */
7
- declare const toOpenAPISchema: (schema: StandardSchemaV1, options?: Record<string, unknown>) => Promise<{
8
- schema: OpenAPIV3_1.SchemaObject;
9
- components: OpenAPIV3_1.ComponentsObject | undefined;
10
- }>;
15
+ declare const toOpenAPISchema: quansync.QuansyncFn<{
16
+ schema: openapi_types.OpenAPIV3_1.SchemaObject | Promise<openapi_types.OpenAPIV3_1.SchemaObject>;
17
+ components: openapi_types.OpenAPIV3_1.ComponentsObject | undefined;
18
+ }, [schema: StandardSchemaV1<unknown, unknown>, context?: Partial<ToOpenAPISchemaContext> | undefined]>;
19
+ declare function loadVendor(vendor: string, fn: ToOpenAPISchemaFn): void;
11
20
 
12
- export { toOpenAPISchema };
21
+ export { loadVendor, toOpenAPISchema };
package/dist/index.js CHANGED
@@ -1 +1,2 @@
1
- export { t as toOpenAPISchema } from './index-Dy32JbZt.js';
1
+ import 'quansync';
2
+ export { l as loadVendor, t as toOpenAPISchema } from './index-B2FrwPUq.js';
@@ -0,0 +1,35 @@
1
+ 'use strict';
2
+
3
+ var standardJson = require('@standard-community/standard-json');
4
+ var convert = require('./convert--bmLap0k.cjs');
5
+
6
+ function getToOpenAPISchemaFn() {
7
+ return (schema, context) => standardJson.toJsonSchema(schema, {
8
+ // @ts-expect-error
9
+ overrideAction: ({ valibotAction, jsonSchema }) => {
10
+ const _jsonSchema = convert.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
+ exports.default = getToOpenAPISchemaFn;
@@ -0,0 +1,33 @@
1
+ import { toJsonSchema } from '@standard-community/standard-json';
2
+ import { c as convertToOpenAPISchema } from './convert-BrW5dcj8.js';
3
+
4
+ function getToOpenAPISchemaFn() {
5
+ return (schema, context) => toJsonSchema(schema, {
6
+ // @ts-expect-error
7
+ overrideAction: ({ valibotAction, jsonSchema }) => {
8
+ const _jsonSchema = convertToOpenAPISchema(jsonSchema, context);
9
+ if (valibotAction.kind === "metadata" && valibotAction.type === "metadata" && !("$ref" in _jsonSchema)) {
10
+ const metadata = valibotAction.metadata;
11
+ if (metadata.example !== void 0) {
12
+ _jsonSchema.example = metadata.example;
13
+ }
14
+ if (metadata.examples && metadata.examples.length > 0) {
15
+ _jsonSchema.examples = metadata.examples;
16
+ }
17
+ if (metadata.ref) {
18
+ context.components.schemas = {
19
+ ...context.components.schemas,
20
+ [metadata.ref]: _jsonSchema
21
+ };
22
+ return {
23
+ $ref: `#/components/schemas/${metadata.ref}`
24
+ };
25
+ }
26
+ }
27
+ return _jsonSchema;
28
+ },
29
+ ...context.options
30
+ });
31
+ }
32
+
33
+ export { getToOpenAPISchemaFn as default };
@@ -1,17 +1,16 @@
1
1
  'use strict';
2
2
 
3
- var index = require('./index-iywZ_eHa.cjs');
4
3
  var standardJson = require('@standard-community/standard-json');
5
- var convert = require('./convert-Bgc7pB9z.cjs');
4
+ var convert = require('./convert--bmLap0k.cjs');
5
+ var index = require('./index-lYeS5F9z.cjs');
6
+ require('quansync');
6
7
 
7
8
  async function getToOpenAPISchemaFn() {
8
9
  return async (schema, context) => {
9
10
  if ("_zod" in schema) {
10
11
  return convert.convertToOpenAPISchema(
11
- await standardJson.toJsonSchema(
12
- schema,
13
- context.options
14
- )
12
+ await standardJson.toJsonSchema(schema, context.options),
13
+ context
15
14
  );
16
15
  }
17
16
  try {
@@ -30,7 +29,7 @@ async function getToOpenAPISchemaFn() {
30
29
  return _schema;
31
30
  } catch {
32
31
  throw new Error(
33
- index.errorMessageWrapper(`Missing dependencies "zod-openapi".`)
32
+ index.errorMessageWrapper(`Missing dependencies "zod-openapi v4".`)
34
33
  );
35
34
  }
36
35
  };
@@ -1,15 +1,14 @@
1
- import { e as errorMessageWrapper } from './index-Dy32JbZt.js';
2
1
  import { toJsonSchema } from '@standard-community/standard-json';
3
- import { c as convertToOpenAPISchema } from './convert-B1hz_0d-.js';
2
+ import { c as convertToOpenAPISchema } from './convert-BrW5dcj8.js';
3
+ import { e as errorMessageWrapper } from './index-B2FrwPUq.js';
4
+ import 'quansync';
4
5
 
5
6
  async function getToOpenAPISchemaFn() {
6
7
  return async (schema, context) => {
7
8
  if ("_zod" in schema) {
8
9
  return convertToOpenAPISchema(
9
- await toJsonSchema(
10
- schema,
11
- context.options
12
- )
10
+ await toJsonSchema(schema, context.options),
11
+ context
13
12
  );
14
13
  }
15
14
  try {
@@ -28,7 +27,7 @@ async function getToOpenAPISchemaFn() {
28
27
  return _schema;
29
28
  } catch {
30
29
  throw new Error(
31
- errorMessageWrapper(`Missing dependencies "zod-openapi".`)
30
+ errorMessageWrapper(`Missing dependencies "zod-openapi v4".`)
32
31
  );
33
32
  }
34
33
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@standard-community/standard-openapi",
3
- "version": "0.2.0-rc.0",
3
+ "version": "0.2.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.cjs",
@@ -23,8 +23,7 @@
23
23
  },
24
24
  "repository": {
25
25
  "type": "git",
26
- "url": "git+https://github.com/standard-community/standard-openapi.git",
27
- "directory": "packages/core"
26
+ "url": "git+https://github.com/standard-community/standard-openapi.git"
28
27
  },
29
28
  "bugs": {
30
29
  "url": "https://github.com/standard-community/standard-openapi/issues"
@@ -40,12 +39,14 @@
40
39
  }
41
40
  },
42
41
  "peerDependencies": {
43
- "@standard-community/standard-json": "^0.3.0-rc.1",
42
+ "@standard-community/standard-json": "^0.3.0",
44
43
  "@standard-schema/spec": "^1.0.0",
45
44
  "arktype": "^2.1.20",
46
45
  "openapi-types": "^12.1.3",
46
+ "quansync": "^0.2.11",
47
47
  "valibot": "^1.1.0",
48
- "zod": "^3.25.67"
48
+ "zod": "^3.25.0 || ^4.0.0",
49
+ "zod-openapi": "^4"
49
50
  },
50
51
  "peerDependenciesMeta": {
51
52
  "arktype": {
@@ -56,20 +57,21 @@
56
57
  },
57
58
  "zod": {
58
59
  "optional": true
60
+ },
61
+ "zod-openapi": {
62
+ "optional": true
59
63
  }
60
64
  },
61
65
  "devDependencies": {
62
66
  "@biomejs/biome": "^2.0.4",
63
67
  "@types/json-schema": "^7.0.15",
68
+ "@types/node": "^24.3.1",
64
69
  "@valibot/to-json-schema": "^1.3.0",
65
70
  "pkgroll": "^2.13.1",
66
71
  "typescript": "^5.8.3",
67
72
  "vitest": "^3.2.4",
68
73
  "zod-to-json-schema": "^3.24.6"
69
74
  },
70
- "dependencies": {
71
- "zod-openapi": "^4.2.4"
72
- },
73
75
  "scripts": {
74
76
  "build": "pkgroll --clean-dist",
75
77
  "format": "biome check --write .",
@@ -1,30 +0,0 @@
1
- const errorMessageWrapper = (message) => `standard-openapi: ${message}`;
2
-
3
- const getToOpenAPISchemaFn = async (vendor) => {
4
- switch (vendor) {
5
- case "valibot":
6
- return (await import('./valibot-CIrrN3QZ.js')).default();
7
- case "zod":
8
- return (await import('./zod-DCcSUcb6.js')).default();
9
- case "arktype":
10
- case "effect":
11
- return (await import('./default-CRzfiS4W.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
- let 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 };
@@ -1,33 +0,0 @@
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-BGJahbVY.cjs'); })).default();
9
- case "zod":
10
- return (await Promise.resolve().then(function () { return require('./zod-DwEveHyt.cjs'); })).default();
11
- case "arktype":
12
- case "effect":
13
- return (await Promise.resolve().then(function () { return require('./default-BKxWl1Ae.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
- let 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;
@@ -1,38 +0,0 @@
1
- 'use strict';
2
-
3
- var standardJson = require('@standard-community/standard-json');
4
- var convert = require('./convert-Bgc7pB9z.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);
13
- if (valibotAction.kind === "metadata" && valibotAction.type === "metadata") {
14
- const metadata = valibotAction.metadata;
15
- if (metadata.ref) {
16
- context.components.schemas = {
17
- ...context.components.schemas,
18
- [metadata.ref]: _jsonSchema
19
- };
20
- return {
21
- $ref: `#/components/schemas/${metadata.ref}`
22
- };
23
- }
24
- if (metadata.example !== void 0) {
25
- _jsonSchema.example = metadata.example;
26
- }
27
- if (metadata.examples && metadata.examples.length > 0) {
28
- _jsonSchema.examples = metadata.examples;
29
- }
30
- }
31
- return _jsonSchema;
32
- },
33
- ...context.options
34
- }
35
- );
36
- }
37
-
38
- exports.default = getToOpenAPISchemaFn;
@@ -1,36 +0,0 @@
1
- import { toJsonSchema } from '@standard-community/standard-json';
2
- import { c as convertToOpenAPISchema } from './convert-B1hz_0d-.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);
11
- if (valibotAction.kind === "metadata" && valibotAction.type === "metadata") {
12
- const metadata = valibotAction.metadata;
13
- if (metadata.ref) {
14
- context.components.schemas = {
15
- ...context.components.schemas,
16
- [metadata.ref]: _jsonSchema
17
- };
18
- return {
19
- $ref: `#/components/schemas/${metadata.ref}`
20
- };
21
- }
22
- if (metadata.example !== void 0) {
23
- _jsonSchema.example = metadata.example;
24
- }
25
- if (metadata.examples && metadata.examples.length > 0) {
26
- _jsonSchema.examples = metadata.examples;
27
- }
28
- }
29
- return _jsonSchema;
30
- },
31
- ...context.options
32
- }
33
- );
34
- }
35
-
36
- export { getToOpenAPISchemaFn as default };