@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 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 zodHandler from "@standard-community/standard-openapi/zod";
70
+ import { convertToOpenAPISchema } from "@standard-community/standard-openapi/convert";
69
71
 
70
72
  // Or pass a custom implmentation
71
- loadVendor("zod", zodHandler())
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 = 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
- );
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);
@@ -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) => standardJson.toJsonSchema(schema, {
8
- // @ts-expect-error
9
- overrideAction: ({ valibotAction, jsonSchema }) => {
10
- const _jsonSchema = convert.convertToOpenAPISchema(jsonSchema, context);
11
- if (valibotAction.kind === "metadata" && valibotAction.type === "metadata" && !("$ref" in _jsonSchema)) {
12
- const metadata = valibotAction.metadata;
13
- if (metadata.example !== void 0) {
14
- _jsonSchema.example = metadata.example;
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
- if (metadata.examples && metadata.examples.length > 0) {
17
- _jsonSchema.examples = metadata.examples;
18
- }
19
- if (metadata.ref) {
20
- context.components.schemas = {
21
- ...context.components.schemas,
22
- [metadata.ref]: _jsonSchema
23
- };
24
- return {
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;
@@ -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) => toJsonSchema(schema, {
6
- // @ts-expect-error
7
- overrideAction: ({ valibotAction, jsonSchema }) => {
8
- const _jsonSchema = convertToOpenAPISchema(jsonSchema, context);
9
- if (valibotAction.kind === "metadata" && valibotAction.type === "metadata" && !("$ref" in _jsonSchema)) {
10
- const metadata = valibotAction.metadata;
11
- if (metadata.example !== void 0) {
12
- _jsonSchema.example = metadata.example;
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
- if (metadata.examples && metadata.examples.length > 0) {
15
- _jsonSchema.examples = metadata.examples;
16
- }
17
- if (metadata.ref) {
18
- context.components.schemas = {
19
- ...context.components.schemas,
20
- [metadata.ref]: _jsonSchema
21
- };
22
- return {
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",
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.0",
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",