@standard-community/standard-openapi 0.2.2 → 0.2.4
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 +13 -10
- package/dist/{default-Cw7W_z8T.cjs → default-DyJyARWC.cjs} +1 -1
- package/dist/{default-yM7Nawqg.js → default-u_dwuiYb.js} +1 -1
- package/dist/index.cjs +4 -5
- package/dist/index.js +4 -5
- package/dist/vendors/valibot.cjs +31 -25
- package/dist/vendors/valibot.js +31 -25
- package/dist/vendors/zod.cjs +9 -8
- package/dist/vendors/zod.d.cts +1 -1
- package/dist/vendors/zod.d.ts +1 -1
- package/dist/vendors/zod.js +9 -8
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -64,20 +64,23 @@ const openapiSchema = toOpenAPISchema(schema);
|
|
|
64
64
|
#### Customize the toOpenAPISchema of a supported lib
|
|
65
65
|
|
|
66
66
|
```ts
|
|
67
|
-
import {
|
|
68
|
-
import
|
|
67
|
+
import { z } from "zod/v4";
|
|
68
|
+
import { toJSONSchema } from "zod/v4/core";
|
|
69
|
+
import { toOpenAPISchema, loadVendor } from "@standard-community/standard-openapi";
|
|
70
|
+
import { convertToOpenAPISchema } from "@standard-community/standard-openapi/convert";
|
|
69
71
|
|
|
70
72
|
// Or pass a custom implmentation
|
|
71
|
-
loadVendor("zod",
|
|
73
|
+
loadVendor("zod", (schema, context) => {
|
|
74
|
+
return convertToOpenAPISchema(toJSONSchema(schema, {
|
|
75
|
+
io: "input"
|
|
76
|
+
}), context);
|
|
77
|
+
})
|
|
72
78
|
|
|
73
79
|
// Define your schema
|
|
74
|
-
const schema =
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}),
|
|
79
|
-
v.description("My neat object schema"),
|
|
80
|
-
);
|
|
80
|
+
const schema = z.object({
|
|
81
|
+
myString: z.string(),
|
|
82
|
+
myUnion: z.union([z.number(), z.boolean()]),
|
|
83
|
+
}),
|
|
81
84
|
|
|
82
85
|
// Convert it to OpenAPI Schema
|
|
83
86
|
const openapiSchema = await toOpenAPISchema(schema);
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
var standardJson = require('@standard-community/standard-json');
|
|
4
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
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
|
@@ -9,24 +9,23 @@ const getToOpenAPISchemaFn = async (vendor) => {
|
|
|
9
9
|
if (cached) {
|
|
10
10
|
return cached;
|
|
11
11
|
}
|
|
12
|
-
let
|
|
12
|
+
let vendorFn;
|
|
13
13
|
switch (vendor) {
|
|
14
14
|
case "valibot":
|
|
15
|
-
|
|
15
|
+
vendorFn = (await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespaceDefaultOnly(require('./vendors/valibot.cjs')); })).default();
|
|
16
16
|
break;
|
|
17
17
|
case "zod":
|
|
18
|
-
|
|
18
|
+
vendorFn = (await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespaceDefaultOnly(require('./vendors/zod.cjs')); })).default();
|
|
19
19
|
break;
|
|
20
20
|
case "arktype":
|
|
21
21
|
case "effect":
|
|
22
|
-
|
|
22
|
+
vendorFn = (await Promise.resolve().then(function () { return require('./default-DyJyARWC.cjs'); })).default();
|
|
23
23
|
break;
|
|
24
24
|
default:
|
|
25
25
|
throw new Error(
|
|
26
26
|
utils.errorMessageWrapper(`Unsupported schema vendor "${vendor}".`)
|
|
27
27
|
);
|
|
28
28
|
}
|
|
29
|
-
const vendorFn = await vendorFnPromise;
|
|
30
29
|
utils.openapiVendorMap.set(vendor, vendorFn);
|
|
31
30
|
return vendorFn;
|
|
32
31
|
};
|
package/dist/index.js
CHANGED
|
@@ -5,24 +5,23 @@ const getToOpenAPISchemaFn = async (vendor) => {
|
|
|
5
5
|
if (cached) {
|
|
6
6
|
return cached;
|
|
7
7
|
}
|
|
8
|
-
let
|
|
8
|
+
let vendorFn;
|
|
9
9
|
switch (vendor) {
|
|
10
10
|
case "valibot":
|
|
11
|
-
|
|
11
|
+
vendorFn = (await import('./vendors/valibot.js')).default();
|
|
12
12
|
break;
|
|
13
13
|
case "zod":
|
|
14
|
-
|
|
14
|
+
vendorFn = (await import('./vendors/zod.js')).default();
|
|
15
15
|
break;
|
|
16
16
|
case "arktype":
|
|
17
17
|
case "effect":
|
|
18
|
-
|
|
18
|
+
vendorFn = (await import('./default-u_dwuiYb.js')).default();
|
|
19
19
|
break;
|
|
20
20
|
default:
|
|
21
21
|
throw new Error(
|
|
22
22
|
errorMessageWrapper(`Unsupported schema vendor "${vendor}".`)
|
|
23
23
|
);
|
|
24
24
|
}
|
|
25
|
-
const vendorFn = await vendorFnPromise;
|
|
26
25
|
openapiVendorMap.set(vendor, vendorFn);
|
|
27
26
|
return vendorFn;
|
|
28
27
|
};
|
package/dist/vendors/valibot.cjs
CHANGED
|
@@ -4,32 +4,38 @@ var standardJson = require('@standard-community/standard-json');
|
|
|
4
4
|
var convert = require('./convert.cjs');
|
|
5
5
|
|
|
6
6
|
function getToOpenAPISchemaFn() {
|
|
7
|
-
return (schema, context) =>
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
7
|
+
return async (schema, context) => {
|
|
8
|
+
const openapiSchema = await standardJson.toJsonSchema(schema, {
|
|
9
|
+
// @ts-expect-error
|
|
10
|
+
overrideAction: ({ valibotAction, jsonSchema }) => {
|
|
11
|
+
const _jsonSchema = convert.convertToOpenAPISchema(jsonSchema, context);
|
|
12
|
+
if (valibotAction.kind === "metadata" && valibotAction.type === "metadata" && !("$ref" in _jsonSchema)) {
|
|
13
|
+
const metadata = valibotAction.metadata;
|
|
14
|
+
if (metadata.example !== void 0) {
|
|
15
|
+
_jsonSchema.example = metadata.example;
|
|
16
|
+
}
|
|
17
|
+
if (metadata.examples && metadata.examples.length > 0) {
|
|
18
|
+
_jsonSchema.examples = metadata.examples;
|
|
19
|
+
}
|
|
20
|
+
if (metadata.ref) {
|
|
21
|
+
context.components.schemas = {
|
|
22
|
+
...context.components.schemas,
|
|
23
|
+
[metadata.ref]: _jsonSchema
|
|
24
|
+
};
|
|
25
|
+
return {
|
|
26
|
+
$ref: `#/components/schemas/${metadata.ref}`
|
|
27
|
+
};
|
|
28
|
+
}
|
|
15
29
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
$ref: `#/components/schemas/${metadata.ref}`
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
return _jsonSchema;
|
|
30
|
-
},
|
|
31
|
-
...context.options
|
|
32
|
-
});
|
|
30
|
+
return _jsonSchema;
|
|
31
|
+
},
|
|
32
|
+
...context.options
|
|
33
|
+
});
|
|
34
|
+
if ("$schema" in openapiSchema) {
|
|
35
|
+
delete openapiSchema.$schema;
|
|
36
|
+
}
|
|
37
|
+
return openapiSchema;
|
|
38
|
+
};
|
|
33
39
|
}
|
|
34
40
|
|
|
35
41
|
module.exports = getToOpenAPISchemaFn;
|
package/dist/vendors/valibot.js
CHANGED
|
@@ -2,32 +2,38 @@ import { toJsonSchema } from '@standard-community/standard-json';
|
|
|
2
2
|
import { convertToOpenAPISchema } from './convert.js';
|
|
3
3
|
|
|
4
4
|
function getToOpenAPISchemaFn() {
|
|
5
|
-
return (schema, context) =>
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
return async (schema, context) => {
|
|
6
|
+
const openapiSchema = await toJsonSchema(schema, {
|
|
7
|
+
// @ts-expect-error
|
|
8
|
+
overrideAction: ({ valibotAction, jsonSchema }) => {
|
|
9
|
+
const _jsonSchema = convertToOpenAPISchema(jsonSchema, context);
|
|
10
|
+
if (valibotAction.kind === "metadata" && valibotAction.type === "metadata" && !("$ref" in _jsonSchema)) {
|
|
11
|
+
const metadata = valibotAction.metadata;
|
|
12
|
+
if (metadata.example !== void 0) {
|
|
13
|
+
_jsonSchema.example = metadata.example;
|
|
14
|
+
}
|
|
15
|
+
if (metadata.examples && metadata.examples.length > 0) {
|
|
16
|
+
_jsonSchema.examples = metadata.examples;
|
|
17
|
+
}
|
|
18
|
+
if (metadata.ref) {
|
|
19
|
+
context.components.schemas = {
|
|
20
|
+
...context.components.schemas,
|
|
21
|
+
[metadata.ref]: _jsonSchema
|
|
22
|
+
};
|
|
23
|
+
return {
|
|
24
|
+
$ref: `#/components/schemas/${metadata.ref}`
|
|
25
|
+
};
|
|
26
|
+
}
|
|
13
27
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
$ref: `#/components/schemas/${metadata.ref}`
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
return _jsonSchema;
|
|
28
|
-
},
|
|
29
|
-
...context.options
|
|
30
|
-
});
|
|
28
|
+
return _jsonSchema;
|
|
29
|
+
},
|
|
30
|
+
...context.options
|
|
31
|
+
});
|
|
32
|
+
if ("$schema" in openapiSchema) {
|
|
33
|
+
delete openapiSchema.$schema;
|
|
34
|
+
}
|
|
35
|
+
return openapiSchema;
|
|
36
|
+
};
|
|
31
37
|
}
|
|
32
38
|
|
|
33
39
|
export { getToOpenAPISchemaFn as default };
|
package/dist/vendors/zod.cjs
CHANGED
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var convert = require('./convert.cjs');
|
|
3
|
+
var _default = require('../default-DyJyARWC.cjs');
|
|
5
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 = {
|
package/dist/vendors/zod.d.cts
CHANGED
|
@@ -2,6 +2,6 @@ import { a as ToOpenAPISchemaFn } from '../utils-D4f8cMSa.js';
|
|
|
2
2
|
import '@standard-schema/spec';
|
|
3
3
|
import 'openapi-types';
|
|
4
4
|
|
|
5
|
-
declare function getToOpenAPISchemaFn():
|
|
5
|
+
declare function getToOpenAPISchemaFn(): ToOpenAPISchemaFn;
|
|
6
6
|
|
|
7
7
|
export { getToOpenAPISchemaFn as default };
|
package/dist/vendors/zod.d.ts
CHANGED
|
@@ -2,6 +2,6 @@ import { a as ToOpenAPISchemaFn } from '../utils-D4f8cMSa.js';
|
|
|
2
2
|
import '@standard-schema/spec';
|
|
3
3
|
import 'openapi-types';
|
|
4
4
|
|
|
5
|
-
declare function getToOpenAPISchemaFn():
|
|
5
|
+
declare function getToOpenAPISchemaFn(): ToOpenAPISchemaFn;
|
|
6
6
|
|
|
7
7
|
export { getToOpenAPISchemaFn as default };
|
package/dist/vendors/zod.js
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { convertToOpenAPISchema } from './convert.js';
|
|
1
|
+
import getToOpenAPISchemaFn$1 from '../default-u_dwuiYb.js';
|
|
3
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.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
}
|
|
72
72
|
},
|
|
73
73
|
"peerDependencies": {
|
|
74
|
-
"@standard-community/standard-json": "^0.3.
|
|
74
|
+
"@standard-community/standard-json": "^0.3.1",
|
|
75
75
|
"@standard-schema/spec": "^1.0.0",
|
|
76
76
|
"arktype": "^2.1.20",
|
|
77
77
|
"openapi-types": "^12.1.3",
|