@standard-community/standard-openapi 0.2.9 → 0.2.10

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.
@@ -1,10 +1,10 @@
1
1
  'use strict';
2
2
 
3
3
  var standardJson = require('@standard-community/standard-json');
4
- var convert = require('./vendors/convert.cjs');
4
+ var vendors_convert = require('./vendors/convert.cjs');
5
5
 
6
6
  function getToOpenAPISchemaFn() {
7
- return async (schema, context) => convert.convertToOpenAPISchema(
7
+ return async (schema, context) => vendors_convert.convertToOpenAPISchema(
8
8
  await standardJson.toJsonSchema(schema, context.options),
9
9
  context
10
10
  );
@@ -11,13 +11,13 @@ const getToOpenAPISchemaFn = async (vendor) => {
11
11
  let vendorFn;
12
12
  switch (vendor) {
13
13
  case "valibot":
14
- vendorFn = (await Promise.resolve().then(function () { return require('./valibot-sgPHXFKJ.cjs'); })).default();
14
+ vendorFn = (await Promise.resolve().then(function () { return require('./valibot-CNm53x33.cjs'); })).default();
15
15
  break;
16
16
  case "zod":
17
- vendorFn = (await Promise.resolve().then(function () { return require('./zod-DrFzROei.cjs'); })).default();
17
+ vendorFn = (await Promise.resolve().then(function () { return require('./zod-DZIcm8dB.cjs'); })).default();
18
18
  break;
19
19
  default:
20
- vendorFn = (await Promise.resolve().then(function () { return require('./default-DyJyARWC.cjs'); })).default();
20
+ vendorFn = (await Promise.resolve().then(function () { return require('./default-DNjsfw3o.cjs'); })).default();
21
21
  }
22
22
  openapiVendorMap.set(vendor, vendorFn);
23
23
  return vendorFn;
package/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var index = require('./index-CzVFvajF.cjs');
3
+ var index = require('./index-BPRfQ1mx.cjs');
4
4
 
5
5
 
6
6
 
package/dist/index.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as openapi_types from 'openapi-types';
2
2
  import { StandardSchemaV1 } from '@standard-schema/spec';
3
- import { T as ToOpenAPISchemaContext, a as ToOpenAPISchemaFn } from './utils-D4f8cMSa.js';
3
+ import { T as ToOpenAPISchemaFn, a as ToOpenAPISchemaContext } from './utils-6SPsNbjx.cjs';
4
4
 
5
5
  /**
6
6
  * Converts a Standard Schema to a OpenAPI schema.
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as openapi_types from 'openapi-types';
2
2
  import { StandardSchemaV1 } from '@standard-schema/spec';
3
- import { T as ToOpenAPISchemaContext, a as ToOpenAPISchemaFn } from './utils-D4f8cMSa.js';
3
+ import { T as ToOpenAPISchemaFn, a as ToOpenAPISchemaContext } from './utils-6SPsNbjx.js';
4
4
 
5
5
  /**
6
6
  * Converts a Standard Schema to a OpenAPI schema.
@@ -7,4 +7,4 @@ type ToOpenAPISchemaContext = {
7
7
  };
8
8
  type ToOpenAPISchemaFn = (schema: StandardSchemaV1, context: ToOpenAPISchemaContext) => OpenAPIV3_1.SchemaObject | Promise<OpenAPIV3_1.SchemaObject>;
9
9
 
10
- export type { ToOpenAPISchemaContext as T, ToOpenAPISchemaFn as a };
10
+ export type { ToOpenAPISchemaFn as T, ToOpenAPISchemaContext as a };
@@ -0,0 +1,10 @@
1
+ import { StandardSchemaV1 } from '@standard-schema/spec';
2
+ import { OpenAPIV3_1 } from 'openapi-types';
3
+
4
+ type ToOpenAPISchemaContext = {
5
+ components: OpenAPIV3_1.ComponentsObject;
6
+ options?: Record<string, unknown>;
7
+ };
8
+ type ToOpenAPISchemaFn = (schema: StandardSchemaV1, context: ToOpenAPISchemaContext) => OpenAPIV3_1.SchemaObject | Promise<OpenAPIV3_1.SchemaObject>;
9
+
10
+ export type { ToOpenAPISchemaFn as T, ToOpenAPISchemaContext as a };
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var standardJson = require('@standard-community/standard-json');
4
- var convert = require('./vendors/convert.cjs');
4
+ var vendors_convert = require('./vendors/convert.cjs');
5
5
 
6
6
  function getToOpenAPISchemaFn() {
7
7
  return async (schema, context) => {
@@ -9,7 +9,7 @@ function getToOpenAPISchemaFn() {
9
9
  errorMode: "ignore",
10
10
  // @ts-expect-error
11
11
  overrideAction: ({ valibotAction, jsonSchema }) => {
12
- const _jsonSchema = convert.convertToOpenAPISchema(jsonSchema, context);
12
+ const _jsonSchema = vendors_convert.convertToOpenAPISchema(jsonSchema, context);
13
13
  if (valibotAction.kind === "metadata" && valibotAction.type === "metadata" && !("$ref" in _jsonSchema)) {
14
14
  const metadata = valibotAction.metadata;
15
15
  if (metadata.example !== void 0) {
@@ -65,6 +65,15 @@ function convertToOpenAPISchema(jsonSchema, context) {
65
65
  }
66
66
  }
67
67
  });
68
+ if (_jsonSchema.$defs || _jsonSchema.definitions) {
69
+ context.components.schemas = {
70
+ ..._jsonSchema.definitions,
71
+ ..._jsonSchema.$defs,
72
+ ...context.components.schemas
73
+ };
74
+ delete _jsonSchema.$defs;
75
+ delete _jsonSchema.definitions;
76
+ }
68
77
  if (_jsonSchema.ref || _jsonSchema.$id) {
69
78
  const { ref, $id, ...component } = _jsonSchema;
70
79
  const id = ref || $id;
@@ -76,12 +85,12 @@ function convertToOpenAPISchema(jsonSchema, context) {
76
85
  $ref: `#/components/schemas/${id}`
77
86
  };
78
87
  } else if (_jsonSchema.$ref) {
79
- const { $ref, $defs } = _jsonSchema;
88
+ const { $ref, ...rest } = _jsonSchema;
89
+ const lowerRef = $ref.toLowerCase();
90
+ if (lowerRef.startsWith("http://") || lowerRef.startsWith("https://") || $ref.startsWith("//")) {
91
+ return { ...rest, $ref };
92
+ }
80
93
  const ref = $ref.split("/").pop();
81
- context.components.schemas = {
82
- ...context.components.schemas,
83
- ...$defs
84
- };
85
94
  return {
86
95
  $ref: `#/components/schemas/${ref}`
87
96
  };
@@ -1,5 +1,5 @@
1
1
  import { OpenAPIV3_1 } from 'openapi-types';
2
- import { T as ToOpenAPISchemaContext } from '../utils-D4f8cMSa.js';
2
+ import { ToOpenAPISchemaContext } from '../index.cjs';
3
3
  import '@standard-schema/spec';
4
4
 
5
5
  // ==================================================================================================
@@ -1,5 +1,5 @@
1
1
  import { OpenAPIV3_1 } from 'openapi-types';
2
- import { T as ToOpenAPISchemaContext } from '../utils-D4f8cMSa.js';
2
+ import { ToOpenAPISchemaContext } from '../index.js';
3
3
  import '@standard-schema/spec';
4
4
 
5
5
  // ==================================================================================================
@@ -63,6 +63,15 @@ function convertToOpenAPISchema(jsonSchema, context) {
63
63
  }
64
64
  }
65
65
  });
66
+ if (_jsonSchema.$defs || _jsonSchema.definitions) {
67
+ context.components.schemas = {
68
+ ..._jsonSchema.definitions,
69
+ ..._jsonSchema.$defs,
70
+ ...context.components.schemas
71
+ };
72
+ delete _jsonSchema.$defs;
73
+ delete _jsonSchema.definitions;
74
+ }
66
75
  if (_jsonSchema.ref || _jsonSchema.$id) {
67
76
  const { ref, $id, ...component } = _jsonSchema;
68
77
  const id = ref || $id;
@@ -74,12 +83,12 @@ function convertToOpenAPISchema(jsonSchema, context) {
74
83
  $ref: `#/components/schemas/${id}`
75
84
  };
76
85
  } else if (_jsonSchema.$ref) {
77
- const { $ref, $defs } = _jsonSchema;
86
+ const { $ref, ...rest } = _jsonSchema;
87
+ const lowerRef = $ref.toLowerCase();
88
+ if (lowerRef.startsWith("http://") || lowerRef.startsWith("https://") || $ref.startsWith("//")) {
89
+ return { ...rest, $ref };
90
+ }
78
91
  const ref = $ref.split("/").pop();
79
- context.components.schemas = {
80
- ...context.components.schemas,
81
- ...$defs
82
- };
83
92
  return {
84
93
  $ref: `#/components/schemas/${ref}`
85
94
  };
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var _default = require('./default-DyJyARWC.cjs');
4
- var index = require('./index-CzVFvajF.cjs');
3
+ var _default = require('./default-DNjsfw3o.cjs');
4
+ var index = require('./index-BPRfQ1mx.cjs');
5
5
  require('@standard-community/standard-json');
6
6
  require('./vendors/convert.cjs');
7
7
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@standard-community/standard-openapi",
3
- "version": "0.2.9",
3
+ "version": "0.2.10",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.cjs",
@@ -54,11 +54,11 @@
54
54
  "@standard-community/standard-json": "^0.3.5",
55
55
  "@standard-schema/spec": "^1.0.0",
56
56
  "arktype": "^2.1.20",
57
- "effect": "^3.17.14",
57
+ "effect": "^3.20.0",
58
58
  "openapi-types": "^12.1.3",
59
59
  "sury": "^10.0.0",
60
60
  "typebox": "^1.0.0",
61
- "valibot": "^1.1.0",
61
+ "valibot": "^1.4.2",
62
62
  "zod": "^3.25.0 || ^4.0.0",
63
63
  "zod-openapi": "^4"
64
64
  },
@@ -90,9 +90,11 @@
90
90
  "@types/json-schema": "^7.0.15",
91
91
  "@types/node": "^24.3.1",
92
92
  "@valibot/to-json-schema": "^1.3.0",
93
- "pkgroll": "^2.13.1",
93
+ "pkgroll": "^2.28.1",
94
+ "typebox": "1.0.17",
94
95
  "typescript": "^5.8.3",
95
- "vitest": "^3.2.4",
96
+ "vitest": "^3.2.6",
97
+ "zod": "^3.25.67",
96
98
  "zod-to-json-schema": "^3.24.6"
97
99
  },
98
100
  "scripts": {