@standard-community/standard-openapi 0.1.1 → 0.2.0-rc.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 +1 -0
- package/dist/convert-B1hz_0d-.js +64 -0
- package/dist/convert-Bgc7pB9z.cjs +66 -0
- package/dist/default-BKxWl1Ae.cjs +15 -0
- package/dist/default-CRzfiS4W.js +13 -0
- package/dist/index-Dy32JbZt.js +30 -0
- package/dist/index-iywZ_eHa.cjs +33 -0
- package/dist/index.cjs +7 -1
- package/dist/index.d.cts +9 -59
- package/dist/index.d.ts +9 -59
- package/dist/index.js +1 -1
- package/dist/valibot-BGJahbVY.cjs +38 -0
- package/dist/valibot-CIrrN3QZ.js +36 -0
- package/dist/zod-DCcSUcb6.js +37 -0
- package/dist/zod-DwEveHyt.cjs +39 -0
- package/package.json +22 -15
- package/dist/default-C7_LgS8R.cjs +0 -1
- package/dist/default-PnsbTDiK.js +0 -1
- package/dist/zod-B4Z3YRnT.js +0 -1
- package/dist/zod-hd0-fbCt.cjs +0 -1
package/README.md
CHANGED
|
@@ -50,6 +50,7 @@ List of supported validators -
|
|
|
50
50
|
| Zod | ✅ |
|
|
51
51
|
| Valibot | ✅ |
|
|
52
52
|
| ArkType | ✅ |
|
|
53
|
+
| Typebox | ✅ (Using [TypeMap](https://github.com/sinclairzx81/typemap) |
|
|
53
54
|
| Effect Schema | 🛠️ |
|
|
54
55
|
|
|
55
56
|
You can check the compatibility versions at [standardschema.dev](https://standardschema.dev/)
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
function convertToOpenAPISchema(jsonSchema) {
|
|
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
|
+
);
|
|
47
|
+
}
|
|
48
|
+
} else if (key === "allOf" || key === "anyOf" || key === "oneOf") {
|
|
49
|
+
_jsonSchema[key] = _jsonSchema[key].map(convertToOpenAPISchema);
|
|
50
|
+
} else if (key === "items") {
|
|
51
|
+
if (Array.isArray(_jsonSchema[key])) {
|
|
52
|
+
_jsonSchema[key] = _jsonSchema[key].map(convertToOpenAPISchema);
|
|
53
|
+
} else {
|
|
54
|
+
_jsonSchema[key] = convertToOpenAPISchema(_jsonSchema[key]);
|
|
55
|
+
}
|
|
56
|
+
} else {
|
|
57
|
+
_jsonSchema[key] = convertToOpenAPISchema(_jsonSchema[key]);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
return _jsonSchema;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export { convertToOpenAPISchema as c };
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function convertToOpenAPISchema(jsonSchema) {
|
|
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
|
+
);
|
|
49
|
+
}
|
|
50
|
+
} else if (key === "allOf" || key === "anyOf" || key === "oneOf") {
|
|
51
|
+
_jsonSchema[key] = _jsonSchema[key].map(convertToOpenAPISchema);
|
|
52
|
+
} else if (key === "items") {
|
|
53
|
+
if (Array.isArray(_jsonSchema[key])) {
|
|
54
|
+
_jsonSchema[key] = _jsonSchema[key].map(convertToOpenAPISchema);
|
|
55
|
+
} else {
|
|
56
|
+
_jsonSchema[key] = convertToOpenAPISchema(_jsonSchema[key]);
|
|
57
|
+
}
|
|
58
|
+
} else {
|
|
59
|
+
_jsonSchema[key] = convertToOpenAPISchema(_jsonSchema[key]);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
return _jsonSchema;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
exports.convertToOpenAPISchema = convertToOpenAPISchema;
|
|
@@ -0,0 +1,15 @@
|
|
|
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) => convert.convertToOpenAPISchema(
|
|
8
|
+
await standardJson.toJsonSchema(
|
|
9
|
+
schema,
|
|
10
|
+
context.options
|
|
11
|
+
)
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
exports.default = getToOpenAPISchemaFn;
|
|
@@ -0,0 +1,13 @@
|
|
|
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) => convertToOpenAPISchema(
|
|
6
|
+
await toJsonSchema(
|
|
7
|
+
schema,
|
|
8
|
+
context.options
|
|
9
|
+
)
|
|
10
|
+
);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { getToOpenAPISchemaFn as default };
|
|
@@ -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-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 };
|
|
@@ -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-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;
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var index = require('./index-iywZ_eHa.cjs');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
exports.toOpenAPISchema = index.toOpenAPISchema;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,62 +1,12 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
|
+
import { OpenAPIV3_1 } from 'openapi-types';
|
|
2
3
|
|
|
3
|
-
/**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
|
1
|
+
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
|
+
import { OpenAPIV3_1 } from 'openapi-types';
|
|
2
3
|
|
|
3
|
-
/**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
1
|
+
export { t as toOpenAPISchema } from './index-Dy32JbZt.js';
|
|
@@ -0,0 +1,38 @@
|
|
|
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;
|
|
@@ -0,0 +1,36 @@
|
|
|
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 };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { e as errorMessageWrapper } from './index-Dy32JbZt.js';
|
|
2
|
+
import { toJsonSchema } from '@standard-community/standard-json';
|
|
3
|
+
import { c as convertToOpenAPISchema } from './convert-B1hz_0d-.js';
|
|
4
|
+
|
|
5
|
+
async function getToOpenAPISchemaFn() {
|
|
6
|
+
return async (schema, context) => {
|
|
7
|
+
if ("_zod" in schema) {
|
|
8
|
+
return convertToOpenAPISchema(
|
|
9
|
+
await toJsonSchema(
|
|
10
|
+
schema,
|
|
11
|
+
context.options
|
|
12
|
+
)
|
|
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
|
+
errorMessageWrapper(`Missing dependencies "zod-openapi".`)
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export { getToOpenAPISchemaFn as default };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var index = require('./index-iywZ_eHa.cjs');
|
|
4
|
+
var standardJson = require('@standard-community/standard-json');
|
|
5
|
+
var convert = require('./convert-Bgc7pB9z.cjs');
|
|
6
|
+
|
|
7
|
+
async function getToOpenAPISchemaFn() {
|
|
8
|
+
return async (schema, context) => {
|
|
9
|
+
if ("_zod" in schema) {
|
|
10
|
+
return convert.convertToOpenAPISchema(
|
|
11
|
+
await standardJson.toJsonSchema(
|
|
12
|
+
schema,
|
|
13
|
+
context.options
|
|
14
|
+
)
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
try {
|
|
18
|
+
const { createSchema } = await import('zod-openapi');
|
|
19
|
+
const { schema: _schema, components } = createSchema(
|
|
20
|
+
// @ts-expect-error
|
|
21
|
+
schema,
|
|
22
|
+
context.options
|
|
23
|
+
);
|
|
24
|
+
if (components) {
|
|
25
|
+
context.components.schemas = {
|
|
26
|
+
...context.components.schemas,
|
|
27
|
+
...components
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
return _schema;
|
|
31
|
+
} catch {
|
|
32
|
+
throw new Error(
|
|
33
|
+
index.errorMessageWrapper(`Missing dependencies "zod-openapi".`)
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
exports.default = getToOpenAPISchemaFn;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@standard-community/standard-openapi",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0-rc.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
@@ -40,32 +40,39 @@
|
|
|
40
40
|
}
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
|
-
"@standard-community/standard-json": "^0.
|
|
44
|
-
"
|
|
45
|
-
"
|
|
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.67"
|
|
46
49
|
},
|
|
47
50
|
"peerDependenciesMeta": {
|
|
48
|
-
"
|
|
51
|
+
"arktype": {
|
|
49
52
|
"optional": true
|
|
50
53
|
},
|
|
51
|
-
"
|
|
54
|
+
"valibot": {
|
|
52
55
|
"optional": true
|
|
53
56
|
},
|
|
54
|
-
"
|
|
57
|
+
"zod": {
|
|
55
58
|
"optional": true
|
|
56
59
|
}
|
|
57
60
|
},
|
|
58
61
|
"devDependencies": {
|
|
59
|
-
"@
|
|
60
|
-
"@standard-schema/spec": "^1.0.0",
|
|
62
|
+
"@biomejs/biome": "^2.0.4",
|
|
61
63
|
"@types/json-schema": "^7.0.15",
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
"zod": "^3.24.
|
|
64
|
+
"@valibot/to-json-schema": "^1.3.0",
|
|
65
|
+
"pkgroll": "^2.13.1",
|
|
66
|
+
"typescript": "^5.8.3",
|
|
67
|
+
"vitest": "^3.2.4",
|
|
68
|
+
"zod-to-json-schema": "^3.24.6"
|
|
69
|
+
},
|
|
70
|
+
"dependencies": {
|
|
71
|
+
"zod-openapi": "^4.2.4"
|
|
67
72
|
},
|
|
68
73
|
"scripts": {
|
|
69
|
-
"build": "pkgroll --
|
|
74
|
+
"build": "pkgroll --clean-dist",
|
|
75
|
+
"format": "biome check --write .",
|
|
76
|
+
"test": "vitest"
|
|
70
77
|
}
|
|
71
78
|
}
|
|
@@ -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;
|
package/dist/default-PnsbTDiK.js
DELETED
|
@@ -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};
|
package/dist/zod-B4Z3YRnT.js
DELETED
|
@@ -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};
|
package/dist/zod-hd0-fbCt.cjs
DELETED
|
@@ -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;
|