@standard-community/standard-openapi 0.2.3 → 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 +12 -9
- package/dist/vendors/valibot.cjs +31 -25
- package/dist/vendors/valibot.js +31 -25
- 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 { z } from "zod/v4";
|
|
68
|
+
import { toJSONSchema } from "zod/v4/core";
|
|
67
69
|
import { toOpenAPISchema, loadVendor } from "@standard-community/standard-openapi";
|
|
68
|
-
import
|
|
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);
|
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/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",
|