@standard-community/standard-openapi 0.2.0 → 0.2.2

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
@@ -41,16 +41,13 @@ const openapiSchema = await toOpenAPISchema(schema);
41
41
 
42
42
  ### Sync Usage
43
43
 
44
- This is useful for -
45
-
46
- 1. Adding support for Unsupported validation libs, like Sury
47
- 2. Customize the toOpenAPISchema of a supported lib
44
+ #### Adding support for Unsupported validation libs
48
45
 
49
46
  ```ts
50
47
  import { toOpenAPISchema, loadVendor } from "@standard-community/standard-openapi";
51
48
  import { convertSchemaToJson } from "your-validation-lib";
52
49
 
53
- // The lib should support Standard Schema
50
+ // The lib should support Standard Schema, like Sury
54
51
  // as we use 'schema["~standard"].vendor' to get the vendor name
55
52
  // Eg. loadVendor(zod["~standard"].vendor, convertorFunction)
56
53
  loadVendor("validation-lib-name", convertSchemaToJson)
@@ -63,3 +60,25 @@ const schema = {
63
60
  // Convert it to OpenAPI Schema
64
61
  const openapiSchema = toOpenAPISchema(schema);
65
62
  ```
63
+
64
+ #### Customize the toOpenAPISchema of a supported lib
65
+
66
+ ```ts
67
+ import { toOpenAPISchema } from "@standard-community/standard-openapi";
68
+ import zodHandler from "@standard-community/standard-openapi/zod";
69
+
70
+ // Or pass a custom implmentation
71
+ loadVendor("zod", zodHandler())
72
+
73
+ // Define your schema
74
+ const schema = v.pipe(
75
+ v.object({
76
+ myString: v.string(),
77
+ myUnion: v.union([v.number(), v.boolean()]),
78
+ }),
79
+ v.description("My neat object schema"),
80
+ );
81
+
82
+ // Convert it to OpenAPI Schema
83
+ const openapiSchema = await toOpenAPISchema(schema);
84
+ ```
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var standardJson = require('@standard-community/standard-json');
4
- var convert = require('./convert--bmLap0k.cjs');
4
+ var convert = require('./vendors/convert.cjs');
5
5
 
6
6
  async function getToOpenAPISchemaFn() {
7
7
  return async (schema, context) => convert.convertToOpenAPISchema(
@@ -1,5 +1,5 @@
1
1
  import { toJsonSchema } from '@standard-community/standard-json';
2
- import { c as convertToOpenAPISchema } from './convert-BrW5dcj8.js';
2
+ import { convertToOpenAPISchema } from './vendors/convert.js';
3
3
 
4
4
  async function getToOpenAPISchemaFn() {
5
5
  return async (schema, context) => convertToOpenAPISchema(
package/dist/index.cjs CHANGED
@@ -1,9 +1,48 @@
1
1
  'use strict';
2
2
 
3
- require('quansync');
4
- var index = require('./index-lYeS5F9z.cjs');
3
+ var utils = require('./utils-DibZ0_jm.cjs');
5
4
 
5
+ function _interopNamespaceDefaultOnly (e) { return Object.freeze({ __proto__: null, default: e }); }
6
6
 
7
+ const getToOpenAPISchemaFn = async (vendor) => {
8
+ const cached = utils.openapiVendorMap.get(vendor);
9
+ if (cached) {
10
+ return cached;
11
+ }
12
+ let vendorFnPromise;
13
+ switch (vendor) {
14
+ case "valibot":
15
+ vendorFnPromise = (await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespaceDefaultOnly(require('./vendors/valibot.cjs')); })).default();
16
+ break;
17
+ case "zod":
18
+ vendorFnPromise = (await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespaceDefaultOnly(require('./vendors/zod.cjs')); })).default();
19
+ break;
20
+ case "arktype":
21
+ case "effect":
22
+ vendorFnPromise = (await Promise.resolve().then(function () { return require('./default-Cw7W_z8T.cjs'); })).default();
23
+ break;
24
+ default:
25
+ throw new Error(
26
+ utils.errorMessageWrapper(`Unsupported schema vendor "${vendor}".`)
27
+ );
28
+ }
29
+ const vendorFn = await vendorFnPromise;
30
+ utils.openapiVendorMap.set(vendor, vendorFn);
31
+ return vendorFn;
32
+ };
7
33
 
8
- exports.loadVendor = index.loadVendor;
9
- exports.toOpenAPISchema = index.toOpenAPISchema;
34
+ const toOpenAPISchema = async (schema, context = {}) => {
35
+ const fn = await getToOpenAPISchemaFn(schema["~standard"].vendor);
36
+ const { components = {}, options } = context;
37
+ const _schema = await fn(schema, { components, options });
38
+ return {
39
+ schema: _schema,
40
+ components: Object.keys(components).length > 0 ? components : void 0
41
+ };
42
+ };
43
+ function loadVendor(vendor, fn) {
44
+ utils.openapiVendorMap.set(vendor, fn);
45
+ }
46
+
47
+ exports.loadVendor = loadVendor;
48
+ exports.toOpenAPISchema = toOpenAPISchema;
package/dist/index.d.cts CHANGED
@@ -1,21 +1,18 @@
1
- import * as quansync from 'quansync';
2
1
  import * as openapi_types from 'openapi-types';
3
- import { OpenAPIV3_1 } from 'openapi-types';
4
2
  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
+ import { T as ToOpenAPISchemaContext, a as ToOpenAPISchemaFn } from './utils-D4f8cMSa.js';
11
4
 
12
5
  /**
13
6
  * Converts a Standard Schema to a OpenAPI schema.
14
7
  */
15
- declare const toOpenAPISchema: quansync.QuansyncFn<{
16
- schema: openapi_types.OpenAPIV3_1.SchemaObject | Promise<openapi_types.OpenAPIV3_1.SchemaObject>;
8
+ declare const toOpenAPISchema: (schema: StandardSchemaV1, context?: Partial<ToOpenAPISchemaContext>) => Promise<{
9
+ schema: openapi_types.OpenAPIV3_1.SchemaObject;
17
10
  components: openapi_types.OpenAPIV3_1.ComponentsObject | undefined;
18
- }, [schema: StandardSchemaV1<unknown, unknown>, context?: Partial<ToOpenAPISchemaContext> | undefined]>;
11
+ }>;
12
+ /**
13
+ * Load vendor before calling toOpenAPISchema,
14
+ * for imporving performance and adding support for unsupported vendors
15
+ */
19
16
  declare function loadVendor(vendor: string, fn: ToOpenAPISchemaFn): void;
20
17
 
21
- export { loadVendor, toOpenAPISchema };
18
+ export { ToOpenAPISchemaContext, ToOpenAPISchemaFn, loadVendor, toOpenAPISchema };
package/dist/index.d.ts CHANGED
@@ -1,21 +1,18 @@
1
- import * as quansync from 'quansync';
2
1
  import * as openapi_types from 'openapi-types';
3
- import { OpenAPIV3_1 } from 'openapi-types';
4
2
  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
+ import { T as ToOpenAPISchemaContext, a as ToOpenAPISchemaFn } from './utils-D4f8cMSa.js';
11
4
 
12
5
  /**
13
6
  * Converts a Standard Schema to a OpenAPI schema.
14
7
  */
15
- declare const toOpenAPISchema: quansync.QuansyncFn<{
16
- schema: openapi_types.OpenAPIV3_1.SchemaObject | Promise<openapi_types.OpenAPIV3_1.SchemaObject>;
8
+ declare const toOpenAPISchema: (schema: StandardSchemaV1, context?: Partial<ToOpenAPISchemaContext>) => Promise<{
9
+ schema: openapi_types.OpenAPIV3_1.SchemaObject;
17
10
  components: openapi_types.OpenAPIV3_1.ComponentsObject | undefined;
18
- }, [schema: StandardSchemaV1<unknown, unknown>, context?: Partial<ToOpenAPISchemaContext> | undefined]>;
11
+ }>;
12
+ /**
13
+ * Load vendor before calling toOpenAPISchema,
14
+ * for imporving performance and adding support for unsupported vendors
15
+ */
19
16
  declare function loadVendor(vendor: string, fn: ToOpenAPISchemaFn): void;
20
17
 
21
- export { loadVendor, toOpenAPISchema };
18
+ export { ToOpenAPISchemaContext, ToOpenAPISchemaFn, loadVendor, toOpenAPISchema };
package/dist/index.js CHANGED
@@ -1,2 +1,43 @@
1
- import 'quansync';
2
- export { l as loadVendor, t as toOpenAPISchema } from './index-B2FrwPUq.js';
1
+ import { o as openapiVendorMap, e as errorMessageWrapper } from './utils-Dhi4Aks8.js';
2
+
3
+ const getToOpenAPISchemaFn = async (vendor) => {
4
+ const cached = openapiVendorMap.get(vendor);
5
+ if (cached) {
6
+ return cached;
7
+ }
8
+ let vendorFnPromise;
9
+ switch (vendor) {
10
+ case "valibot":
11
+ vendorFnPromise = (await import('./vendors/valibot.js')).default();
12
+ break;
13
+ case "zod":
14
+ vendorFnPromise = (await import('./vendors/zod.js')).default();
15
+ break;
16
+ case "arktype":
17
+ case "effect":
18
+ vendorFnPromise = (await import('./default-yM7Nawqg.js')).default();
19
+ break;
20
+ default:
21
+ throw new Error(
22
+ errorMessageWrapper(`Unsupported schema vendor "${vendor}".`)
23
+ );
24
+ }
25
+ const vendorFn = await vendorFnPromise;
26
+ openapiVendorMap.set(vendor, vendorFn);
27
+ return vendorFn;
28
+ };
29
+
30
+ const toOpenAPISchema = async (schema, context = {}) => {
31
+ const fn = await getToOpenAPISchemaFn(schema["~standard"].vendor);
32
+ const { components = {}, options } = context;
33
+ const _schema = await fn(schema, { components, options });
34
+ return {
35
+ schema: _schema,
36
+ components: Object.keys(components).length > 0 ? components : void 0
37
+ };
38
+ };
39
+ function loadVendor(vendor, fn) {
40
+ openapiVendorMap.set(vendor, fn);
41
+ }
42
+
43
+ export { loadVendor, toOpenAPISchema };
@@ -0,0 +1,10 @@
1
+ import { StandardSchemaV1 } from '@standard-schema/spec';
2
+ import { OpenAPIV3_1 } from 'openapi-types';
3
+
4
+ type ToOpenAPISchemaContext = {
5
+ components: OpenAPIV3_1.ComponentsObject;
6
+ options?: Record<string, unknown>;
7
+ };
8
+ type ToOpenAPISchemaFn = (schema: StandardSchemaV1, context: ToOpenAPISchemaContext) => OpenAPIV3_1.SchemaObject | Promise<OpenAPIV3_1.SchemaObject>;
9
+
10
+ export type { ToOpenAPISchemaContext as T, ToOpenAPISchemaFn as a };
@@ -0,0 +1,4 @@
1
+ const errorMessageWrapper = (message) => `standard-openapi: ${message}`;
2
+ const openapiVendorMap = /* @__PURE__ */ new Map();
3
+
4
+ export { errorMessageWrapper as e, openapiVendorMap as o };
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ const errorMessageWrapper = (message) => `standard-openapi: ${message}`;
4
+ const openapiVendorMap = /* @__PURE__ */ new Map();
5
+
6
+ exports.errorMessageWrapper = errorMessageWrapper;
7
+ exports.openapiVendorMap = openapiVendorMap;
@@ -0,0 +1,174 @@
1
+ import { OpenAPIV3_1 } from 'openapi-types';
2
+ import { T as ToOpenAPISchemaContext } from '../utils-D4f8cMSa.js';
3
+ import '@standard-schema/spec';
4
+
5
+ // ==================================================================================================
6
+ // JSON Schema Draft 07
7
+ // ==================================================================================================
8
+ // https://tools.ietf.org/html/draft-handrews-json-schema-validation-01
9
+ // --------------------------------------------------------------------------------------------------
10
+
11
+ /**
12
+ * Primitive type
13
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.1.1
14
+ */
15
+ type JSONSchema7TypeName =
16
+ | "string" //
17
+ | "number"
18
+ | "integer"
19
+ | "boolean"
20
+ | "object"
21
+ | "array"
22
+ | "null";
23
+
24
+ /**
25
+ * Primitive type
26
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.1.1
27
+ */
28
+ type JSONSchema7Type =
29
+ | string //
30
+ | number
31
+ | boolean
32
+ | JSONSchema7Object
33
+ | JSONSchema7Array
34
+ | null;
35
+
36
+ // Workaround for infinite type recursion
37
+ interface JSONSchema7Object {
38
+ [key: string]: JSONSchema7Type;
39
+ }
40
+
41
+ // Workaround for infinite type recursion
42
+ // https://github.com/Microsoft/TypeScript/issues/3496#issuecomment-128553540
43
+ interface JSONSchema7Array extends Array<JSONSchema7Type> {}
44
+
45
+ /**
46
+ * Meta schema
47
+ *
48
+ * Recommended values:
49
+ * - 'http://json-schema.org/schema#'
50
+ * - 'http://json-schema.org/hyper-schema#'
51
+ * - 'http://json-schema.org/draft-07/schema#'
52
+ * - 'http://json-schema.org/draft-07/hyper-schema#'
53
+ *
54
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-5
55
+ */
56
+ type JSONSchema7Version = string;
57
+
58
+ /**
59
+ * JSON Schema v7
60
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01
61
+ */
62
+ type JSONSchema7Definition = JSONSchema7 | boolean;
63
+ interface JSONSchema7 {
64
+ $id?: string | undefined;
65
+ $ref?: string | undefined;
66
+ $schema?: JSONSchema7Version | undefined;
67
+ $comment?: string | undefined;
68
+
69
+ /**
70
+ * @see https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-00#section-8.2.4
71
+ * @see https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-validation-00#appendix-A
72
+ */
73
+ $defs?: {
74
+ [key: string]: JSONSchema7Definition;
75
+ } | undefined;
76
+
77
+ /**
78
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.1
79
+ */
80
+ type?: JSONSchema7TypeName | JSONSchema7TypeName[] | undefined;
81
+ enum?: JSONSchema7Type[] | undefined;
82
+ const?: JSONSchema7Type | undefined;
83
+
84
+ /**
85
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.2
86
+ */
87
+ multipleOf?: number | undefined;
88
+ maximum?: number | undefined;
89
+ exclusiveMaximum?: number | undefined;
90
+ minimum?: number | undefined;
91
+ exclusiveMinimum?: number | undefined;
92
+
93
+ /**
94
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.3
95
+ */
96
+ maxLength?: number | undefined;
97
+ minLength?: number | undefined;
98
+ pattern?: string | undefined;
99
+
100
+ /**
101
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.4
102
+ */
103
+ items?: JSONSchema7Definition | JSONSchema7Definition[] | undefined;
104
+ additionalItems?: JSONSchema7Definition | undefined;
105
+ maxItems?: number | undefined;
106
+ minItems?: number | undefined;
107
+ uniqueItems?: boolean | undefined;
108
+ contains?: JSONSchema7Definition | undefined;
109
+
110
+ /**
111
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.5
112
+ */
113
+ maxProperties?: number | undefined;
114
+ minProperties?: number | undefined;
115
+ required?: string[] | undefined;
116
+ properties?: {
117
+ [key: string]: JSONSchema7Definition;
118
+ } | undefined;
119
+ patternProperties?: {
120
+ [key: string]: JSONSchema7Definition;
121
+ } | undefined;
122
+ additionalProperties?: JSONSchema7Definition | undefined;
123
+ dependencies?: {
124
+ [key: string]: JSONSchema7Definition | string[];
125
+ } | undefined;
126
+ propertyNames?: JSONSchema7Definition | undefined;
127
+
128
+ /**
129
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.6
130
+ */
131
+ if?: JSONSchema7Definition | undefined;
132
+ then?: JSONSchema7Definition | undefined;
133
+ else?: JSONSchema7Definition | undefined;
134
+
135
+ /**
136
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.7
137
+ */
138
+ allOf?: JSONSchema7Definition[] | undefined;
139
+ anyOf?: JSONSchema7Definition[] | undefined;
140
+ oneOf?: JSONSchema7Definition[] | undefined;
141
+ not?: JSONSchema7Definition | undefined;
142
+
143
+ /**
144
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-7
145
+ */
146
+ format?: string | undefined;
147
+
148
+ /**
149
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-8
150
+ */
151
+ contentMediaType?: string | undefined;
152
+ contentEncoding?: string | undefined;
153
+
154
+ /**
155
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-9
156
+ */
157
+ definitions?: {
158
+ [key: string]: JSONSchema7Definition;
159
+ } | undefined;
160
+
161
+ /**
162
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-10
163
+ */
164
+ title?: string | undefined;
165
+ description?: string | undefined;
166
+ default?: JSONSchema7Type | undefined;
167
+ readOnly?: boolean | undefined;
168
+ writeOnly?: boolean | undefined;
169
+ examples?: JSONSchema7Type | undefined;
170
+ }
171
+
172
+ declare function convertToOpenAPISchema(jsonSchema: JSONSchema7, context: ToOpenAPISchemaContext): OpenAPIV3_1.SchemaObject | OpenAPIV3_1.ReferenceObject;
173
+
174
+ export { convertToOpenAPISchema };
@@ -0,0 +1,174 @@
1
+ import { OpenAPIV3_1 } from 'openapi-types';
2
+ import { T as ToOpenAPISchemaContext } from '../utils-D4f8cMSa.js';
3
+ import '@standard-schema/spec';
4
+
5
+ // ==================================================================================================
6
+ // JSON Schema Draft 07
7
+ // ==================================================================================================
8
+ // https://tools.ietf.org/html/draft-handrews-json-schema-validation-01
9
+ // --------------------------------------------------------------------------------------------------
10
+
11
+ /**
12
+ * Primitive type
13
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.1.1
14
+ */
15
+ type JSONSchema7TypeName =
16
+ | "string" //
17
+ | "number"
18
+ | "integer"
19
+ | "boolean"
20
+ | "object"
21
+ | "array"
22
+ | "null";
23
+
24
+ /**
25
+ * Primitive type
26
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.1.1
27
+ */
28
+ type JSONSchema7Type =
29
+ | string //
30
+ | number
31
+ | boolean
32
+ | JSONSchema7Object
33
+ | JSONSchema7Array
34
+ | null;
35
+
36
+ // Workaround for infinite type recursion
37
+ interface JSONSchema7Object {
38
+ [key: string]: JSONSchema7Type;
39
+ }
40
+
41
+ // Workaround for infinite type recursion
42
+ // https://github.com/Microsoft/TypeScript/issues/3496#issuecomment-128553540
43
+ interface JSONSchema7Array extends Array<JSONSchema7Type> {}
44
+
45
+ /**
46
+ * Meta schema
47
+ *
48
+ * Recommended values:
49
+ * - 'http://json-schema.org/schema#'
50
+ * - 'http://json-schema.org/hyper-schema#'
51
+ * - 'http://json-schema.org/draft-07/schema#'
52
+ * - 'http://json-schema.org/draft-07/hyper-schema#'
53
+ *
54
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-5
55
+ */
56
+ type JSONSchema7Version = string;
57
+
58
+ /**
59
+ * JSON Schema v7
60
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01
61
+ */
62
+ type JSONSchema7Definition = JSONSchema7 | boolean;
63
+ interface JSONSchema7 {
64
+ $id?: string | undefined;
65
+ $ref?: string | undefined;
66
+ $schema?: JSONSchema7Version | undefined;
67
+ $comment?: string | undefined;
68
+
69
+ /**
70
+ * @see https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-00#section-8.2.4
71
+ * @see https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-validation-00#appendix-A
72
+ */
73
+ $defs?: {
74
+ [key: string]: JSONSchema7Definition;
75
+ } | undefined;
76
+
77
+ /**
78
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.1
79
+ */
80
+ type?: JSONSchema7TypeName | JSONSchema7TypeName[] | undefined;
81
+ enum?: JSONSchema7Type[] | undefined;
82
+ const?: JSONSchema7Type | undefined;
83
+
84
+ /**
85
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.2
86
+ */
87
+ multipleOf?: number | undefined;
88
+ maximum?: number | undefined;
89
+ exclusiveMaximum?: number | undefined;
90
+ minimum?: number | undefined;
91
+ exclusiveMinimum?: number | undefined;
92
+
93
+ /**
94
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.3
95
+ */
96
+ maxLength?: number | undefined;
97
+ minLength?: number | undefined;
98
+ pattern?: string | undefined;
99
+
100
+ /**
101
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.4
102
+ */
103
+ items?: JSONSchema7Definition | JSONSchema7Definition[] | undefined;
104
+ additionalItems?: JSONSchema7Definition | undefined;
105
+ maxItems?: number | undefined;
106
+ minItems?: number | undefined;
107
+ uniqueItems?: boolean | undefined;
108
+ contains?: JSONSchema7Definition | undefined;
109
+
110
+ /**
111
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.5
112
+ */
113
+ maxProperties?: number | undefined;
114
+ minProperties?: number | undefined;
115
+ required?: string[] | undefined;
116
+ properties?: {
117
+ [key: string]: JSONSchema7Definition;
118
+ } | undefined;
119
+ patternProperties?: {
120
+ [key: string]: JSONSchema7Definition;
121
+ } | undefined;
122
+ additionalProperties?: JSONSchema7Definition | undefined;
123
+ dependencies?: {
124
+ [key: string]: JSONSchema7Definition | string[];
125
+ } | undefined;
126
+ propertyNames?: JSONSchema7Definition | undefined;
127
+
128
+ /**
129
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.6
130
+ */
131
+ if?: JSONSchema7Definition | undefined;
132
+ then?: JSONSchema7Definition | undefined;
133
+ else?: JSONSchema7Definition | undefined;
134
+
135
+ /**
136
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.7
137
+ */
138
+ allOf?: JSONSchema7Definition[] | undefined;
139
+ anyOf?: JSONSchema7Definition[] | undefined;
140
+ oneOf?: JSONSchema7Definition[] | undefined;
141
+ not?: JSONSchema7Definition | undefined;
142
+
143
+ /**
144
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-7
145
+ */
146
+ format?: string | undefined;
147
+
148
+ /**
149
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-8
150
+ */
151
+ contentMediaType?: string | undefined;
152
+ contentEncoding?: string | undefined;
153
+
154
+ /**
155
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-9
156
+ */
157
+ definitions?: {
158
+ [key: string]: JSONSchema7Definition;
159
+ } | undefined;
160
+
161
+ /**
162
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-10
163
+ */
164
+ title?: string | undefined;
165
+ description?: string | undefined;
166
+ default?: JSONSchema7Type | undefined;
167
+ readOnly?: boolean | undefined;
168
+ writeOnly?: boolean | undefined;
169
+ examples?: JSONSchema7Type | undefined;
170
+ }
171
+
172
+ declare function convertToOpenAPISchema(jsonSchema: JSONSchema7, context: ToOpenAPISchemaContext): OpenAPIV3_1.SchemaObject | OpenAPIV3_1.ReferenceObject;
173
+
174
+ export { convertToOpenAPISchema };
@@ -76,4 +76,4 @@ function convertToOpenAPISchema(jsonSchema, context) {
76
76
  return _jsonSchema;
77
77
  }
78
78
 
79
- export { convertToOpenAPISchema as c };
79
+ export { convertToOpenAPISchema };
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var standardJson = require('@standard-community/standard-json');
4
- var convert = require('./convert--bmLap0k.cjs');
4
+ var convert = require('./convert.cjs');
5
5
 
6
6
  function getToOpenAPISchemaFn() {
7
7
  return (schema, context) => standardJson.toJsonSchema(schema, {
@@ -32,4 +32,4 @@ function getToOpenAPISchemaFn() {
32
32
  });
33
33
  }
34
34
 
35
- exports.default = getToOpenAPISchemaFn;
35
+ module.exports = getToOpenAPISchemaFn;
@@ -0,0 +1,7 @@
1
+ import { a as ToOpenAPISchemaFn } from '../utils-D4f8cMSa.js';
2
+ import '@standard-schema/spec';
3
+ import 'openapi-types';
4
+
5
+ declare function getToOpenAPISchemaFn(): ToOpenAPISchemaFn;
6
+
7
+ export { getToOpenAPISchemaFn as default };
@@ -0,0 +1,7 @@
1
+ import { a as ToOpenAPISchemaFn } from '../utils-D4f8cMSa.js';
2
+ import '@standard-schema/spec';
3
+ import 'openapi-types';
4
+
5
+ declare function getToOpenAPISchemaFn(): ToOpenAPISchemaFn;
6
+
7
+ export { getToOpenAPISchemaFn as default };
@@ -1,5 +1,5 @@
1
1
  import { toJsonSchema } from '@standard-community/standard-json';
2
- import { c as convertToOpenAPISchema } from './convert-BrW5dcj8.js';
2
+ import { convertToOpenAPISchema } from './convert.js';
3
3
 
4
4
  function getToOpenAPISchemaFn() {
5
5
  return (schema, context) => toJsonSchema(schema, {
@@ -1,9 +1,8 @@
1
1
  'use strict';
2
2
 
3
3
  var standardJson = require('@standard-community/standard-json');
4
- var convert = require('./convert--bmLap0k.cjs');
5
- var index = require('./index-lYeS5F9z.cjs');
6
- require('quansync');
4
+ var convert = require('./convert.cjs');
5
+ var utils = require('../utils-DibZ0_jm.cjs');
7
6
 
8
7
  async function getToOpenAPISchemaFn() {
9
8
  return async (schema, context) => {
@@ -29,10 +28,10 @@ async function getToOpenAPISchemaFn() {
29
28
  return _schema;
30
29
  } catch {
31
30
  throw new Error(
32
- index.errorMessageWrapper(`Missing dependencies "zod-openapi v4".`)
31
+ utils.errorMessageWrapper(`Missing dependencies "zod-openapi v4".`)
33
32
  );
34
33
  }
35
34
  };
36
35
  }
37
36
 
38
- exports.default = getToOpenAPISchemaFn;
37
+ module.exports = getToOpenAPISchemaFn;
@@ -0,0 +1,7 @@
1
+ import { a as ToOpenAPISchemaFn } from '../utils-D4f8cMSa.js';
2
+ import '@standard-schema/spec';
3
+ import 'openapi-types';
4
+
5
+ declare function getToOpenAPISchemaFn(): Promise<ToOpenAPISchemaFn>;
6
+
7
+ export { getToOpenAPISchemaFn as default };
@@ -0,0 +1,7 @@
1
+ import { a as ToOpenAPISchemaFn } from '../utils-D4f8cMSa.js';
2
+ import '@standard-schema/spec';
3
+ import 'openapi-types';
4
+
5
+ declare function getToOpenAPISchemaFn(): Promise<ToOpenAPISchemaFn>;
6
+
7
+ export { getToOpenAPISchemaFn as default };
@@ -1,7 +1,6 @@
1
1
  import { toJsonSchema } from '@standard-community/standard-json';
2
- import { c as convertToOpenAPISchema } from './convert-BrW5dcj8.js';
3
- import { e as errorMessageWrapper } from './index-B2FrwPUq.js';
4
- import 'quansync';
2
+ import { convertToOpenAPISchema } from './convert.js';
3
+ import { e as errorMessageWrapper } from '../utils-Dhi4Aks8.js';
5
4
 
6
5
  async function getToOpenAPISchemaFn() {
7
6
  return async (schema, context) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@standard-community/standard-openapi",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.cjs",
@@ -29,13 +29,45 @@
29
29
  "url": "https://github.com/standard-community/standard-openapi/issues"
30
30
  },
31
31
  "exports": {
32
- "import": {
33
- "types": "./dist/index.d.ts",
34
- "default": "./dist/index.js"
32
+ ".": {
33
+ "import": {
34
+ "types": "./dist/index.d.ts",
35
+ "default": "./dist/index.js"
36
+ },
37
+ "require": {
38
+ "types": "./dist/index.d.cts",
39
+ "default": "./dist/index.cjs"
40
+ }
35
41
  },
36
- "require": {
37
- "types": "./dist/index.d.cts",
38
- "default": "./dist/index.cjs"
42
+ "./convert": {
43
+ "import": {
44
+ "types": "./dist/vendors/convert.d.ts",
45
+ "default": "./dist/vendors/convert.js"
46
+ },
47
+ "require": {
48
+ "types": "./dist/vendors/convert.d.cts",
49
+ "default": "./dist/vendors/convert.cjs"
50
+ }
51
+ },
52
+ "./valibot": {
53
+ "import": {
54
+ "types": "./dist/vendors/valibot.d.ts",
55
+ "default": "./dist/vendors/valibot.js"
56
+ },
57
+ "require": {
58
+ "types": "./dist/vendors/valibot.d.cts",
59
+ "default": "./dist/vendors/valibot.cjs"
60
+ }
61
+ },
62
+ "./zod": {
63
+ "import": {
64
+ "types": "./dist/vendors/zod.d.ts",
65
+ "default": "./dist/vendors/zod.js"
66
+ },
67
+ "require": {
68
+ "types": "./dist/vendors/zod.d.cts",
69
+ "default": "./dist/vendors/zod.cjs"
70
+ }
39
71
  }
40
72
  },
41
73
  "peerDependencies": {
@@ -43,7 +75,6 @@
43
75
  "@standard-schema/spec": "^1.0.0",
44
76
  "arktype": "^2.1.20",
45
77
  "openapi-types": "^12.1.3",
46
- "quansync": "^0.2.11",
47
78
  "valibot": "^1.1.0",
48
79
  "zod": "^3.25.0 || ^4.0.0",
49
80
  "zod-openapi": "^4"
@@ -1,64 +0,0 @@
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 };
@@ -1,68 +0,0 @@
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;