@standard-community/standard-openapi 0.2.1 → 0.2.3
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 +24 -5
- package/dist/{default-CLvGm-jP.cjs → default-DyJyARWC.cjs} +2 -2
- package/dist/{default-B3j_H5mf.js → default-u_dwuiYb.js} +2 -2
- package/dist/index.cjs +42 -3
- package/dist/index.d.cts +6 -8
- package/dist/index.d.ts +6 -8
- package/dist/index.js +42 -1
- package/dist/utils-D4f8cMSa.d.ts +10 -0
- package/dist/utils-Dhi4Aks8.js +4 -0
- package/dist/utils-DibZ0_jm.cjs +7 -0
- package/dist/vendors/convert.d.cts +174 -0
- package/dist/vendors/convert.d.ts +174 -0
- package/dist/{convert-BrW5dcj8.js → vendors/convert.js} +1 -1
- package/dist/{valibot-CmK54MCp.cjs → vendors/valibot.cjs} +2 -2
- package/dist/vendors/valibot.d.cts +7 -0
- package/dist/vendors/valibot.d.ts +7 -0
- package/dist/{valibot-pYvQeYpK.js → vendors/valibot.js} +1 -1
- package/dist/{zod-Dcc_GKUA.cjs → vendors/zod.cjs} +12 -11
- package/dist/vendors/zod.d.cts +7 -0
- package/dist/vendors/zod.d.ts +7 -0
- package/dist/{zod-FmKJCmIM.js → vendors/zod.js} +10 -9
- package/package.json +39 -7
- package/dist/index-2CxeAJPp.js +0 -44
- package/dist/index-DbUgUmtU.cjs +0 -48
- /package/dist/{convert--bmLap0k.cjs → vendors/convert.cjs} +0 -0
package/README.md
CHANGED
|
@@ -41,16 +41,13 @@ const openapiSchema = await toOpenAPISchema(schema);
|
|
|
41
41
|
|
|
42
42
|
### Sync Usage
|
|
43
43
|
|
|
44
|
-
|
|
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, loadVendor } 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,9 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var standardJson = require('@standard-community/standard-json');
|
|
4
|
-
var convert = require('./convert
|
|
4
|
+
var convert = require('./vendors/convert.cjs');
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
function getToOpenAPISchemaFn() {
|
|
7
7
|
return async (schema, context) => convert.convertToOpenAPISchema(
|
|
8
8
|
await standardJson.toJsonSchema(schema, context.options),
|
|
9
9
|
context
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { toJsonSchema } from '@standard-community/standard-json';
|
|
2
|
-
import {
|
|
2
|
+
import { convertToOpenAPISchema } from './vendors/convert.js';
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
function getToOpenAPISchemaFn() {
|
|
5
5
|
return async (schema, context) => convertToOpenAPISchema(
|
|
6
6
|
await toJsonSchema(schema, context.options),
|
|
7
7
|
context
|
package/dist/index.cjs
CHANGED
|
@@ -1,8 +1,47 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var utils = require('./utils-DibZ0_jm.cjs');
|
|
4
4
|
|
|
5
|
+
function _interopNamespaceDefaultOnly (e) { return Object.freeze({ __proto__: null, default: e }); }
|
|
5
6
|
|
|
7
|
+
const getToOpenAPISchemaFn = async (vendor) => {
|
|
8
|
+
const cached = utils.openapiVendorMap.get(vendor);
|
|
9
|
+
if (cached) {
|
|
10
|
+
return cached;
|
|
11
|
+
}
|
|
12
|
+
let vendorFn;
|
|
13
|
+
switch (vendor) {
|
|
14
|
+
case "valibot":
|
|
15
|
+
vendorFn = (await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespaceDefaultOnly(require('./vendors/valibot.cjs')); })).default();
|
|
16
|
+
break;
|
|
17
|
+
case "zod":
|
|
18
|
+
vendorFn = (await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespaceDefaultOnly(require('./vendors/zod.cjs')); })).default();
|
|
19
|
+
break;
|
|
20
|
+
case "arktype":
|
|
21
|
+
case "effect":
|
|
22
|
+
vendorFn = (await Promise.resolve().then(function () { return require('./default-DyJyARWC.cjs'); })).default();
|
|
23
|
+
break;
|
|
24
|
+
default:
|
|
25
|
+
throw new Error(
|
|
26
|
+
utils.errorMessageWrapper(`Unsupported schema vendor "${vendor}".`)
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
utils.openapiVendorMap.set(vendor, vendorFn);
|
|
30
|
+
return vendorFn;
|
|
31
|
+
};
|
|
6
32
|
|
|
7
|
-
|
|
8
|
-
|
|
33
|
+
const toOpenAPISchema = async (schema, context = {}) => {
|
|
34
|
+
const fn = await getToOpenAPISchemaFn(schema["~standard"].vendor);
|
|
35
|
+
const { components = {}, options } = context;
|
|
36
|
+
const _schema = await fn(schema, { components, options });
|
|
37
|
+
return {
|
|
38
|
+
schema: _schema,
|
|
39
|
+
components: Object.keys(components).length > 0 ? components : void 0
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
function loadVendor(vendor, fn) {
|
|
43
|
+
utils.openapiVendorMap.set(vendor, fn);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
exports.loadVendor = loadVendor;
|
|
47
|
+
exports.toOpenAPISchema = toOpenAPISchema;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
import * as openapi_types from 'openapi-types';
|
|
2
|
-
import { OpenAPIV3_1 } from 'openapi-types';
|
|
3
2
|
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
4
|
-
|
|
5
|
-
type ToOpenAPISchemaContext = {
|
|
6
|
-
components: OpenAPIV3_1.ComponentsObject;
|
|
7
|
-
options?: Record<string, unknown>;
|
|
8
|
-
};
|
|
9
|
-
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';
|
|
10
4
|
|
|
11
5
|
/**
|
|
12
6
|
* Converts a Standard Schema to a OpenAPI schema.
|
|
@@ -15,6 +9,10 @@ declare const toOpenAPISchema: (schema: StandardSchemaV1, context?: Partial<ToOp
|
|
|
15
9
|
schema: openapi_types.OpenAPIV3_1.SchemaObject;
|
|
16
10
|
components: openapi_types.OpenAPIV3_1.ComponentsObject | undefined;
|
|
17
11
|
}>;
|
|
12
|
+
/**
|
|
13
|
+
* Load vendor before calling toOpenAPISchema,
|
|
14
|
+
* for imporving performance and adding support for unsupported vendors
|
|
15
|
+
*/
|
|
18
16
|
declare function loadVendor(vendor: string, fn: ToOpenAPISchemaFn): void;
|
|
19
17
|
|
|
20
|
-
export { loadVendor, toOpenAPISchema };
|
|
18
|
+
export { ToOpenAPISchemaContext, ToOpenAPISchemaFn, loadVendor, toOpenAPISchema };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
import * as openapi_types from 'openapi-types';
|
|
2
|
-
import { OpenAPIV3_1 } from 'openapi-types';
|
|
3
2
|
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
4
|
-
|
|
5
|
-
type ToOpenAPISchemaContext = {
|
|
6
|
-
components: OpenAPIV3_1.ComponentsObject;
|
|
7
|
-
options?: Record<string, unknown>;
|
|
8
|
-
};
|
|
9
|
-
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';
|
|
10
4
|
|
|
11
5
|
/**
|
|
12
6
|
* Converts a Standard Schema to a OpenAPI schema.
|
|
@@ -15,6 +9,10 @@ declare const toOpenAPISchema: (schema: StandardSchemaV1, context?: Partial<ToOp
|
|
|
15
9
|
schema: openapi_types.OpenAPIV3_1.SchemaObject;
|
|
16
10
|
components: openapi_types.OpenAPIV3_1.ComponentsObject | undefined;
|
|
17
11
|
}>;
|
|
12
|
+
/**
|
|
13
|
+
* Load vendor before calling toOpenAPISchema,
|
|
14
|
+
* for imporving performance and adding support for unsupported vendors
|
|
15
|
+
*/
|
|
18
16
|
declare function loadVendor(vendor: string, fn: ToOpenAPISchemaFn): void;
|
|
19
17
|
|
|
20
|
-
export { loadVendor, toOpenAPISchema };
|
|
18
|
+
export { ToOpenAPISchemaContext, ToOpenAPISchemaFn, loadVendor, toOpenAPISchema };
|
package/dist/index.js
CHANGED
|
@@ -1 +1,42 @@
|
|
|
1
|
-
|
|
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 vendorFn;
|
|
9
|
+
switch (vendor) {
|
|
10
|
+
case "valibot":
|
|
11
|
+
vendorFn = (await import('./vendors/valibot.js')).default();
|
|
12
|
+
break;
|
|
13
|
+
case "zod":
|
|
14
|
+
vendorFn = (await import('./vendors/zod.js')).default();
|
|
15
|
+
break;
|
|
16
|
+
case "arktype":
|
|
17
|
+
case "effect":
|
|
18
|
+
vendorFn = (await import('./default-u_dwuiYb.js')).default();
|
|
19
|
+
break;
|
|
20
|
+
default:
|
|
21
|
+
throw new Error(
|
|
22
|
+
errorMessageWrapper(`Unsupported schema vendor "${vendor}".`)
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
openapiVendorMap.set(vendor, vendorFn);
|
|
26
|
+
return vendorFn;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const toOpenAPISchema = async (schema, context = {}) => {
|
|
30
|
+
const fn = await getToOpenAPISchemaFn(schema["~standard"].vendor);
|
|
31
|
+
const { components = {}, options } = context;
|
|
32
|
+
const _schema = await fn(schema, { components, options });
|
|
33
|
+
return {
|
|
34
|
+
schema: _schema,
|
|
35
|
+
components: Object.keys(components).length > 0 ? components : void 0
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
function loadVendor(vendor, fn) {
|
|
39
|
+
openapiVendorMap.set(vendor, fn);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
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,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 };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var standardJson = require('@standard-community/standard-json');
|
|
4
|
-
var convert = require('./convert
|
|
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
|
|
35
|
+
module.exports = getToOpenAPISchemaFn;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { toJsonSchema } from '@standard-community/standard-json';
|
|
2
|
-
import {
|
|
2
|
+
import { convertToOpenAPISchema } from './convert.js';
|
|
3
3
|
|
|
4
4
|
function getToOpenAPISchemaFn() {
|
|
5
5
|
return (schema, context) => toJsonSchema(schema, {
|
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
|
|
3
|
+
var _default = require('../default-DyJyARWC.cjs');
|
|
4
|
+
var utils = require('../utils-DibZ0_jm.cjs');
|
|
5
|
+
require('@standard-community/standard-json');
|
|
6
|
+
require('./convert.cjs');
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
function getToOpenAPISchemaFn() {
|
|
8
9
|
return async (schema, context) => {
|
|
9
10
|
if ("_zod" in schema) {
|
|
10
|
-
return
|
|
11
|
-
|
|
12
|
-
context
|
|
13
|
-
);
|
|
11
|
+
return _default.default()(schema, {
|
|
12
|
+
components: context.components,
|
|
13
|
+
options: { io: "input", ...context.options }
|
|
14
|
+
});
|
|
14
15
|
}
|
|
15
16
|
try {
|
|
16
17
|
const { createSchema } = await import('zod-openapi');
|
|
17
18
|
const { schema: _schema, components } = createSchema(
|
|
18
19
|
// @ts-expect-error
|
|
19
20
|
schema,
|
|
20
|
-
context.options
|
|
21
|
+
{ schemaType: "input", ...context.options }
|
|
21
22
|
);
|
|
22
23
|
if (components) {
|
|
23
24
|
context.components.schemas = {
|
|
@@ -28,10 +29,10 @@ async function getToOpenAPISchemaFn() {
|
|
|
28
29
|
return _schema;
|
|
29
30
|
} catch {
|
|
30
31
|
throw new Error(
|
|
31
|
-
|
|
32
|
+
utils.errorMessageWrapper(`Missing dependencies "zod-openapi v4".`)
|
|
32
33
|
);
|
|
33
34
|
}
|
|
34
35
|
};
|
|
35
36
|
}
|
|
36
37
|
|
|
37
|
-
exports
|
|
38
|
+
module.exports = getToOpenAPISchemaFn;
|
|
@@ -1,21 +1,22 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
1
|
+
import getToOpenAPISchemaFn$1 from '../default-u_dwuiYb.js';
|
|
2
|
+
import { e as errorMessageWrapper } from '../utils-Dhi4Aks8.js';
|
|
3
|
+
import '@standard-community/standard-json';
|
|
4
|
+
import './convert.js';
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
function getToOpenAPISchemaFn() {
|
|
6
7
|
return async (schema, context) => {
|
|
7
8
|
if ("_zod" in schema) {
|
|
8
|
-
return
|
|
9
|
-
|
|
10
|
-
context
|
|
11
|
-
);
|
|
9
|
+
return getToOpenAPISchemaFn$1()(schema, {
|
|
10
|
+
components: context.components,
|
|
11
|
+
options: { io: "input", ...context.options }
|
|
12
|
+
});
|
|
12
13
|
}
|
|
13
14
|
try {
|
|
14
15
|
const { createSchema } = await import('zod-openapi');
|
|
15
16
|
const { schema: _schema, components } = createSchema(
|
|
16
17
|
// @ts-expect-error
|
|
17
18
|
schema,
|
|
18
|
-
context.options
|
|
19
|
+
{ schemaType: "input", ...context.options }
|
|
19
20
|
);
|
|
20
21
|
if (components) {
|
|
21
22
|
context.components.schemas = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@standard-community/standard-openapi",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
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
|
-
"
|
|
33
|
-
"
|
|
34
|
-
|
|
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
|
-
"
|
|
37
|
-
"
|
|
38
|
-
|
|
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": {
|
package/dist/index-2CxeAJPp.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
const errorMessageWrapper = (message) => `standard-openapi: ${message}`;
|
|
2
|
-
const openapiVendorMap = /* @__PURE__ */ new Map();
|
|
3
|
-
|
|
4
|
-
const getToOpenAPISchemaFn = async (vendor) => {
|
|
5
|
-
const cached = openapiVendorMap.get(vendor);
|
|
6
|
-
if (cached) {
|
|
7
|
-
return cached;
|
|
8
|
-
}
|
|
9
|
-
let vendorFnPromise;
|
|
10
|
-
switch (vendor) {
|
|
11
|
-
case "valibot":
|
|
12
|
-
vendorFnPromise = (await import('./valibot-pYvQeYpK.js')).default();
|
|
13
|
-
break;
|
|
14
|
-
case "zod":
|
|
15
|
-
vendorFnPromise = (await import('./zod-FmKJCmIM.js')).default();
|
|
16
|
-
break;
|
|
17
|
-
case "arktype":
|
|
18
|
-
case "effect":
|
|
19
|
-
vendorFnPromise = (await import('./default-B3j_H5mf.js')).default();
|
|
20
|
-
break;
|
|
21
|
-
default:
|
|
22
|
-
throw new Error(
|
|
23
|
-
errorMessageWrapper(`Unsupported schema vendor "${vendor}".`)
|
|
24
|
-
);
|
|
25
|
-
}
|
|
26
|
-
const vendorFn = await vendorFnPromise;
|
|
27
|
-
openapiVendorMap.set(vendor, vendorFn);
|
|
28
|
-
return vendorFn;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
const toOpenAPISchema = async (schema, context = {}) => {
|
|
32
|
-
const fn = await getToOpenAPISchemaFn(schema["~standard"].vendor);
|
|
33
|
-
const { components = {}, options } = context;
|
|
34
|
-
const _schema = await fn(schema, { components, options });
|
|
35
|
-
return {
|
|
36
|
-
schema: _schema,
|
|
37
|
-
components: Object.keys(components).length > 0 ? components : void 0
|
|
38
|
-
};
|
|
39
|
-
};
|
|
40
|
-
function loadVendor(vendor, fn) {
|
|
41
|
-
openapiVendorMap.set(vendor, fn);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export { errorMessageWrapper as e, loadVendor as l, toOpenAPISchema as t };
|
package/dist/index-DbUgUmtU.cjs
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
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 Promise.resolve().then(function () { return require('./valibot-CmK54MCp.cjs'); })).default();
|
|
15
|
-
break;
|
|
16
|
-
case "zod":
|
|
17
|
-
vendorFnPromise = (await Promise.resolve().then(function () { return require('./zod-Dcc_GKUA.cjs'); })).default();
|
|
18
|
-
break;
|
|
19
|
-
case "arktype":
|
|
20
|
-
case "effect":
|
|
21
|
-
vendorFnPromise = (await Promise.resolve().then(function () { return require('./default-CLvGm-jP.cjs'); })).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 = async (schema, context = {}) => {
|
|
34
|
-
const fn = await getToOpenAPISchemaFn(schema["~standard"].vendor);
|
|
35
|
-
const { components = {}, options } = context;
|
|
36
|
-
const _schema = await fn(schema, { components, options });
|
|
37
|
-
return {
|
|
38
|
-
schema: _schema,
|
|
39
|
-
components: Object.keys(components).length > 0 ? components : void 0
|
|
40
|
-
};
|
|
41
|
-
};
|
|
42
|
-
function loadVendor(vendor, fn) {
|
|
43
|
-
openapiVendorMap.set(vendor, fn);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
exports.errorMessageWrapper = errorMessageWrapper;
|
|
47
|
-
exports.loadVendor = loadVendor;
|
|
48
|
-
exports.toOpenAPISchema = toOpenAPISchema;
|
|
File without changes
|