@standard-community/standard-openapi 0.2.0-rc.0 → 0.2.0-rc.1

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
@@ -18,10 +18,8 @@ For some specific vendor, install the respective package also -
18
18
 
19
19
  | Vendor | Package |
20
20
  | ------- | ------- |
21
- | Zod | `zod-openapi` |
22
- | Valibot | `@standard-community/standard-json` `@valibot/to-json-schema` `json-schema-walker` |
23
- | ArkType | `@standard-community/standard-json` `json-schema-walker` |
24
- | Effect Schema | `@standard-community/standard-json` `json-schema-walker` |
21
+ | Zod v3 | `zod-openapi` |
22
+ | Valibot | `@valibot/to-json-schema` |
25
23
 
26
24
  ## Usage
27
25
 
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- function convertToOpenAPISchema(jsonSchema) {
3
+ function convertToOpenAPISchema(jsonSchema, context) {
4
4
  const _jsonSchema = JSON.parse(JSON.stringify(jsonSchema));
5
5
  if ("nullable" in _jsonSchema && _jsonSchema.nullable === true) {
6
6
  if (_jsonSchema.type) {
@@ -44,22 +44,37 @@ function convertToOpenAPISchema(jsonSchema) {
44
44
  if (key === "properties" || key === "definitions" || key === "$defs" || key === "patternProperties") {
45
45
  for (const subKey in _jsonSchema[key]) {
46
46
  _jsonSchema[key][subKey] = convertToOpenAPISchema(
47
- _jsonSchema[key][subKey]
47
+ _jsonSchema[key][subKey],
48
+ context
48
49
  );
49
50
  }
50
51
  } else if (key === "allOf" || key === "anyOf" || key === "oneOf") {
51
- _jsonSchema[key] = _jsonSchema[key].map(convertToOpenAPISchema);
52
+ _jsonSchema[key] = _jsonSchema[key].map(
53
+ (item) => convertToOpenAPISchema(item, context)
54
+ );
52
55
  } else if (key === "items") {
53
56
  if (Array.isArray(_jsonSchema[key])) {
54
- _jsonSchema[key] = _jsonSchema[key].map(convertToOpenAPISchema);
57
+ _jsonSchema[key] = _jsonSchema[key].map(
58
+ (item) => convertToOpenAPISchema(item, context)
59
+ );
55
60
  } else {
56
- _jsonSchema[key] = convertToOpenAPISchema(_jsonSchema[key]);
61
+ _jsonSchema[key] = convertToOpenAPISchema(_jsonSchema[key], context);
57
62
  }
58
63
  } else {
59
- _jsonSchema[key] = convertToOpenAPISchema(_jsonSchema[key]);
64
+ _jsonSchema[key] = convertToOpenAPISchema(_jsonSchema[key], context);
60
65
  }
61
66
  }
62
67
  });
68
+ if (_jsonSchema.ref) {
69
+ const { ref, ...component } = _jsonSchema;
70
+ context.components.schemas = {
71
+ ...context.components.schemas,
72
+ [ref]: component
73
+ };
74
+ return {
75
+ $ref: `#/components/schemas/${ref}`
76
+ };
77
+ }
63
78
  return _jsonSchema;
64
79
  }
65
80
 
@@ -1,4 +1,4 @@
1
- function convertToOpenAPISchema(jsonSchema) {
1
+ function convertToOpenAPISchema(jsonSchema, context) {
2
2
  const _jsonSchema = JSON.parse(JSON.stringify(jsonSchema));
3
3
  if ("nullable" in _jsonSchema && _jsonSchema.nullable === true) {
4
4
  if (_jsonSchema.type) {
@@ -42,22 +42,37 @@ function convertToOpenAPISchema(jsonSchema) {
42
42
  if (key === "properties" || key === "definitions" || key === "$defs" || key === "patternProperties") {
43
43
  for (const subKey in _jsonSchema[key]) {
44
44
  _jsonSchema[key][subKey] = convertToOpenAPISchema(
45
- _jsonSchema[key][subKey]
45
+ _jsonSchema[key][subKey],
46
+ context
46
47
  );
47
48
  }
48
49
  } else if (key === "allOf" || key === "anyOf" || key === "oneOf") {
49
- _jsonSchema[key] = _jsonSchema[key].map(convertToOpenAPISchema);
50
+ _jsonSchema[key] = _jsonSchema[key].map(
51
+ (item) => convertToOpenAPISchema(item, context)
52
+ );
50
53
  } else if (key === "items") {
51
54
  if (Array.isArray(_jsonSchema[key])) {
52
- _jsonSchema[key] = _jsonSchema[key].map(convertToOpenAPISchema);
55
+ _jsonSchema[key] = _jsonSchema[key].map(
56
+ (item) => convertToOpenAPISchema(item, context)
57
+ );
53
58
  } else {
54
- _jsonSchema[key] = convertToOpenAPISchema(_jsonSchema[key]);
59
+ _jsonSchema[key] = convertToOpenAPISchema(_jsonSchema[key], context);
55
60
  }
56
61
  } else {
57
- _jsonSchema[key] = convertToOpenAPISchema(_jsonSchema[key]);
62
+ _jsonSchema[key] = convertToOpenAPISchema(_jsonSchema[key], context);
58
63
  }
59
64
  }
60
65
  });
66
+ if (_jsonSchema.ref) {
67
+ const { ref, ...component } = _jsonSchema;
68
+ context.components.schemas = {
69
+ ...context.components.schemas,
70
+ [ref]: component
71
+ };
72
+ return {
73
+ $ref: `#/components/schemas/${ref}`
74
+ };
75
+ }
61
76
  return _jsonSchema;
62
77
  }
63
78
 
@@ -1,12 +1,10 @@
1
1
  import { toJsonSchema } from '@standard-community/standard-json';
2
- import { c as convertToOpenAPISchema } from './convert-B1hz_0d-.js';
2
+ import { c as convertToOpenAPISchema } from './convert-BrW5dcj8.js';
3
3
 
4
4
  async function getToOpenAPISchemaFn() {
5
5
  return async (schema, context) => convertToOpenAPISchema(
6
- await toJsonSchema(
7
- schema,
8
- context.options
9
- )
6
+ await toJsonSchema(schema, context.options),
7
+ context
10
8
  );
11
9
  }
12
10
 
@@ -1,14 +1,12 @@
1
1
  'use strict';
2
2
 
3
3
  var standardJson = require('@standard-community/standard-json');
4
- var convert = require('./convert-Bgc7pB9z.cjs');
4
+ var convert = require('./convert--bmLap0k.cjs');
5
5
 
6
6
  async function getToOpenAPISchemaFn() {
7
7
  return async (schema, context) => convert.convertToOpenAPISchema(
8
- await standardJson.toJsonSchema(
9
- schema,
10
- context.options
11
- )
8
+ await standardJson.toJsonSchema(schema, context.options),
9
+ context
12
10
  );
13
11
  }
14
12
 
@@ -5,12 +5,12 @@ const errorMessageWrapper = (message) => `standard-openapi: ${message}`;
5
5
  const getToOpenAPISchemaFn = async (vendor) => {
6
6
  switch (vendor) {
7
7
  case "valibot":
8
- return (await Promise.resolve().then(function () { return require('./valibot-BGJahbVY.cjs'); })).default();
8
+ return (await Promise.resolve().then(function () { return require('./valibot-Bhs--VcX.cjs'); })).default();
9
9
  case "zod":
10
- return (await Promise.resolve().then(function () { return require('./zod-DwEveHyt.cjs'); })).default();
10
+ return (await Promise.resolve().then(function () { return require('./zod-DBFeduLX.cjs'); })).default();
11
11
  case "arktype":
12
12
  case "effect":
13
- return (await Promise.resolve().then(function () { return require('./default-BKxWl1Ae.cjs'); })).default();
13
+ return (await Promise.resolve().then(function () { return require('./default-CLvGm-jP.cjs'); })).default();
14
14
  default:
15
15
  throw new Error(
16
16
  errorMessageWrapper(`Unsupported schema vendor "${vendor}".`)
@@ -19,7 +19,7 @@ const getToOpenAPISchemaFn = async (vendor) => {
19
19
  };
20
20
 
21
21
  const toOpenAPISchema = async (schema, options) => {
22
- let components = {};
22
+ const components = {};
23
23
  const _schema = await getToOpenAPISchemaFn(schema["~standard"].vendor).then(
24
24
  (toOpenAPISchemaFn) => toOpenAPISchemaFn(schema, { components, options })
25
25
  );
@@ -3,12 +3,12 @@ const errorMessageWrapper = (message) => `standard-openapi: ${message}`;
3
3
  const getToOpenAPISchemaFn = async (vendor) => {
4
4
  switch (vendor) {
5
5
  case "valibot":
6
- return (await import('./valibot-CIrrN3QZ.js')).default();
6
+ return (await import('./valibot-68LL3XLE.js')).default();
7
7
  case "zod":
8
- return (await import('./zod-DCcSUcb6.js')).default();
8
+ return (await import('./zod-DMhHBlXu.js')).default();
9
9
  case "arktype":
10
10
  case "effect":
11
- return (await import('./default-CRzfiS4W.js')).default();
11
+ return (await import('./default-B3j_H5mf.js')).default();
12
12
  default:
13
13
  throw new Error(
14
14
  errorMessageWrapper(`Unsupported schema vendor "${vendor}".`)
@@ -17,7 +17,7 @@ const getToOpenAPISchemaFn = async (vendor) => {
17
17
  };
18
18
 
19
19
  const toOpenAPISchema = async (schema, options) => {
20
- let components = {};
20
+ const components = {};
21
21
  const _schema = await getToOpenAPISchemaFn(schema["~standard"].vendor).then(
22
22
  (toOpenAPISchemaFn) => toOpenAPISchemaFn(schema, { components, options })
23
23
  );
package/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var index = require('./index-iywZ_eHa.cjs');
3
+ var index = require('./index-6sg7Y400.cjs');
4
4
 
5
5
 
6
6
 
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- export { t as toOpenAPISchema } from './index-Dy32JbZt.js';
1
+ export { t as toOpenAPISchema } from './index-BBkvvbCv.js';
@@ -1,5 +1,5 @@
1
1
  import { toJsonSchema } from '@standard-community/standard-json';
2
- import { c as convertToOpenAPISchema } from './convert-B1hz_0d-.js';
2
+ import { c as convertToOpenAPISchema } from './convert-BrW5dcj8.js';
3
3
 
4
4
  async function getToOpenAPISchemaFn() {
5
5
  return async (schema, context) => toJsonSchema(
@@ -7,9 +7,15 @@ async function getToOpenAPISchemaFn() {
7
7
  {
8
8
  // @ts-expect-error
9
9
  overrideAction: ({ valibotAction, jsonSchema }) => {
10
- const _jsonSchema = convertToOpenAPISchema(jsonSchema);
11
- if (valibotAction.kind === "metadata" && valibotAction.type === "metadata") {
10
+ const _jsonSchema = convertToOpenAPISchema(jsonSchema, context);
11
+ if (valibotAction.kind === "metadata" && valibotAction.type === "metadata" && !("$ref" in _jsonSchema)) {
12
12
  const metadata = valibotAction.metadata;
13
+ if (metadata.example !== void 0) {
14
+ _jsonSchema.example = metadata.example;
15
+ }
16
+ if (metadata.examples && metadata.examples.length > 0) {
17
+ _jsonSchema.examples = metadata.examples;
18
+ }
13
19
  if (metadata.ref) {
14
20
  context.components.schemas = {
15
21
  ...context.components.schemas,
@@ -19,12 +25,6 @@ async function getToOpenAPISchemaFn() {
19
25
  $ref: `#/components/schemas/${metadata.ref}`
20
26
  };
21
27
  }
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
28
  }
29
29
  return _jsonSchema;
30
30
  },
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var standardJson = require('@standard-community/standard-json');
4
- var convert = require('./convert-Bgc7pB9z.cjs');
4
+ var convert = require('./convert--bmLap0k.cjs');
5
5
 
6
6
  async function getToOpenAPISchemaFn() {
7
7
  return async (schema, context) => standardJson.toJsonSchema(
@@ -9,9 +9,15 @@ async function getToOpenAPISchemaFn() {
9
9
  {
10
10
  // @ts-expect-error
11
11
  overrideAction: ({ valibotAction, jsonSchema }) => {
12
- const _jsonSchema = convert.convertToOpenAPISchema(jsonSchema);
13
- if (valibotAction.kind === "metadata" && valibotAction.type === "metadata") {
12
+ const _jsonSchema = convert.convertToOpenAPISchema(jsonSchema, context);
13
+ if (valibotAction.kind === "metadata" && valibotAction.type === "metadata" && !("$ref" in _jsonSchema)) {
14
14
  const metadata = valibotAction.metadata;
15
+ if (metadata.example !== void 0) {
16
+ _jsonSchema.example = metadata.example;
17
+ }
18
+ if (metadata.examples && metadata.examples.length > 0) {
19
+ _jsonSchema.examples = metadata.examples;
20
+ }
15
21
  if (metadata.ref) {
16
22
  context.components.schemas = {
17
23
  ...context.components.schemas,
@@ -21,12 +27,6 @@ async function getToOpenAPISchemaFn() {
21
27
  $ref: `#/components/schemas/${metadata.ref}`
22
28
  };
23
29
  }
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
30
  }
31
31
  return _jsonSchema;
32
32
  },
@@ -1,17 +1,15 @@
1
1
  'use strict';
2
2
 
3
- var index = require('./index-iywZ_eHa.cjs');
4
3
  var standardJson = require('@standard-community/standard-json');
5
- var convert = require('./convert-Bgc7pB9z.cjs');
4
+ var convert = require('./convert--bmLap0k.cjs');
5
+ var index = require('./index-6sg7Y400.cjs');
6
6
 
7
7
  async function getToOpenAPISchemaFn() {
8
8
  return async (schema, context) => {
9
9
  if ("_zod" in schema) {
10
10
  return convert.convertToOpenAPISchema(
11
- await standardJson.toJsonSchema(
12
- schema,
13
- context.options
14
- )
11
+ await standardJson.toJsonSchema(schema, context.options),
12
+ context
15
13
  );
16
14
  }
17
15
  try {
@@ -30,7 +28,7 @@ async function getToOpenAPISchemaFn() {
30
28
  return _schema;
31
29
  } catch {
32
30
  throw new Error(
33
- index.errorMessageWrapper(`Missing dependencies "zod-openapi".`)
31
+ index.errorMessageWrapper(`Missing dependencies "zod-openapi v4".`)
34
32
  );
35
33
  }
36
34
  };
@@ -1,15 +1,13 @@
1
- import { e as errorMessageWrapper } from './index-Dy32JbZt.js';
2
1
  import { toJsonSchema } from '@standard-community/standard-json';
3
- import { c as convertToOpenAPISchema } from './convert-B1hz_0d-.js';
2
+ import { c as convertToOpenAPISchema } from './convert-BrW5dcj8.js';
3
+ import { e as errorMessageWrapper } from './index-BBkvvbCv.js';
4
4
 
5
5
  async function getToOpenAPISchemaFn() {
6
6
  return async (schema, context) => {
7
7
  if ("_zod" in schema) {
8
8
  return convertToOpenAPISchema(
9
- await toJsonSchema(
10
- schema,
11
- context.options
12
- )
9
+ await toJsonSchema(schema, context.options),
10
+ context
13
11
  );
14
12
  }
15
13
  try {
@@ -28,7 +26,7 @@ async function getToOpenAPISchemaFn() {
28
26
  return _schema;
29
27
  } catch {
30
28
  throw new Error(
31
- errorMessageWrapper(`Missing dependencies "zod-openapi".`)
29
+ errorMessageWrapper(`Missing dependencies "zod-openapi v4".`)
32
30
  );
33
31
  }
34
32
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@standard-community/standard-openapi",
3
- "version": "0.2.0-rc.0",
3
+ "version": "0.2.0-rc.1",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.cjs",
@@ -45,7 +45,8 @@
45
45
  "arktype": "^2.1.20",
46
46
  "openapi-types": "^12.1.3",
47
47
  "valibot": "^1.1.0",
48
- "zod": "^3.25.67"
48
+ "zod": "^3.25.0 || ^4.0.0",
49
+ "zod-openapi": "^4"
49
50
  },
50
51
  "peerDependenciesMeta": {
51
52
  "arktype": {
@@ -56,6 +57,9 @@
56
57
  },
57
58
  "zod": {
58
59
  "optional": true
60
+ },
61
+ "zod-openapi": {
62
+ "optional": true
59
63
  }
60
64
  },
61
65
  "devDependencies": {
@@ -67,9 +71,6 @@
67
71
  "vitest": "^3.2.4",
68
72
  "zod-to-json-schema": "^3.24.6"
69
73
  },
70
- "dependencies": {
71
- "zod-openapi": "^4.2.4"
72
- },
73
74
  "scripts": {
74
75
  "build": "pkgroll --clean-dist",
75
76
  "format": "biome check --write .",