@orpc/openapi 2.0.0-beta.40 → 2.0.0-beta.42

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.
Files changed (38) hide show
  1. package/README.md +5 -5
  2. package/dist/adapters/aws-lambda/index.d.mts +1 -1
  3. package/dist/adapters/aws-lambda/index.d.ts +1 -1
  4. package/dist/adapters/aws-lambda/index.mjs +2 -2
  5. package/dist/adapters/fastify/index.d.mts +1 -1
  6. package/dist/adapters/fastify/index.d.ts +1 -1
  7. package/dist/adapters/fastify/index.mjs +2 -2
  8. package/dist/adapters/fetch/index.d.mts +1 -1
  9. package/dist/adapters/fetch/index.d.ts +1 -1
  10. package/dist/adapters/fetch/index.mjs +3 -3
  11. package/dist/adapters/node/index.d.mts +1 -1
  12. package/dist/adapters/node/index.d.ts +1 -1
  13. package/dist/adapters/node/index.mjs +2 -2
  14. package/dist/adapters/standard/index.d.mts +2 -2
  15. package/dist/adapters/standard/index.d.ts +2 -2
  16. package/dist/adapters/standard/index.mjs +3 -3
  17. package/dist/extensions/route.d.mts +1 -1
  18. package/dist/extensions/route.d.ts +1 -1
  19. package/dist/index.d.mts +11 -7
  20. package/dist/index.d.ts +11 -7
  21. package/dist/index.mjs +58 -153
  22. package/dist/plugins/index.d.mts +17 -3
  23. package/dist/plugins/index.d.ts +17 -3
  24. package/dist/plugins/index.mjs +8 -8
  25. package/dist/shared/{openapi.fnBK1ELE.d.mts → openapi.BDiBd3_k.d.mts} +2 -1
  26. package/dist/shared/{openapi.wQKxWEI2.mjs → openapi.BJRea9Uu.mjs} +81 -36
  27. package/dist/shared/{openapi.DI21x5Yo.d.mts → openapi.BTq9wym2.d.mts} +6 -4
  28. package/dist/shared/{openapi.DI21x5Yo.d.ts → openapi.BTq9wym2.d.ts} +6 -4
  29. package/dist/shared/{openapi.B1LWf28E.mjs → openapi.Bu_PfTtX.mjs} +10 -1
  30. package/dist/shared/{openapi.Dl3gew1x.d.mts → openapi.C2LayTNZ.d.mts} +1 -1
  31. package/dist/shared/{openapi.Dl3gew1x.d.ts → openapi.C2LayTNZ.d.ts} +1 -1
  32. package/dist/shared/{openapi.DE5kXinS.d.mts → openapi.Cg9h6jpm.d.mts} +1 -1
  33. package/dist/shared/{openapi.EM8eC1Xn.d.ts → openapi.CkzUS83v.d.ts} +2 -1
  34. package/dist/shared/{openapi.BwNINoeN.d.ts → openapi.D0yWs-uW.d.ts} +1 -1
  35. package/dist/shared/{openapi.BdClbrwk.mjs → openapi.D326pNzT.mjs} +7 -3
  36. package/dist/shared/{openapi.Cem81Zhm.d.ts → openapi.r98bZ3Ig.d.mts} +1 -1
  37. package/dist/shared/{openapi.Cem81Zhm.d.mts → openapi.r98bZ3Ig.d.ts} +1 -1
  38. package/package.json +12 -12
package/dist/index.mjs CHANGED
@@ -1,20 +1,22 @@
1
1
  export { B as BracketNotationSerializer } from './shared/openapi.B2G-HeFn.mjs';
2
2
  import { createContractClientFactory, getAsyncIteratorObjectSchemaDetails, ProcedureContract, resolveMetaPlugins } from '@orpc/contract';
3
- import { D as DEFAULT_OPENAPI_METHOD, a as DEFAULT_OPENAPI_INPUT_STRUCTURE, c as DEFAULT_OPENAPI_SUCCESS_DESCRIPTION, b as DEFAULT_OPENAPI_OUTPUT_STRUCTURE, i as isBodylessMethod, O as OpenAPISerializer, g as getDynamicPathParams } from './shared/openapi.B1LWf28E.mjs';
4
- export { d as OpenAPIJsonSerializer } from './shared/openapi.B1LWf28E.mjs';
3
+ import { D as DEFAULT_OPENAPI_METHOD, a as DEFAULT_OPENAPI_INPUT_STRUCTURE, c as DEFAULT_OPENAPI_SUCCESS_DESCRIPTION, b as DEFAULT_OPENAPI_OUTPUT_STRUCTURE, i as isBodylessMethod, O as OpenAPISerializer, g as getDynamicPathParams } from './shared/openapi.Bu_PfTtX.mjs';
4
+ export { d as OpenAPIJsonSerializer } from './shared/openapi.Bu_PfTtX.mjs';
5
5
  import { g as getOpenAPIMeta, o as openapi } from './shared/openapi.B9PQzqBn.mjs';
6
6
  import { downgradeSpecV32ToV31, downgradeSpecV31ToV30 } from '@openapi-spec/downgrader';
7
7
  import { COMMON_ERROR_STATUS_MAP } from '@orpc/client';
8
8
  export { COMMON_ERROR_STATUS_MAP } from '@orpc/client';
9
- import { encodeJsonPointerSegment, ensureJsonSchemaObject, mapJsonSchemaRefs, decodeJsonPointerSegment, isUnconstrainedSchema, combineJsonSchemasWithComposition, extractJsonObjectSchemaEntries, combineJsonObjectSchemaEntries, flattenJsonUnionSchema, isJsonPrimitiveSchema, matchArrayableJsonSchema, isJsonFileSchema, DelegatingJsonSchemaConverter, StandardJsonSchemaConverter } from '@orpc/json-schema';
9
+ import { encodeJsonPointerSegment, ensureJsonSchemaObject, mapJsonSchemaRefs, decodeJsonPointerSegment, isUnconstrainedSchema, combineJsonSchemasWithComposition, extractJsonObjectSchemaEntries, combineJsonObjectSchemaEntries, flattenJsonUnionSchema, isJsonPrimitiveSchema, matchArrayableJsonSchema, isJsonFileSchema, DelegatingJsonSchemaConverter, StandardJsonSchemaConverter, hoistRecursiveRefToDef } from '@orpc/json-schema';
10
10
  import { DEFAULT_SUCCESS_STATUS, DEFAULT_ERROR_STATUS, walkProcedureContractsAsync } from '@orpc/server';
11
- import { isDeepEqual, value, findDeepMatches, isPlainObject, stringifyJSON, toArray, clone, pathToHttpPath, mergeHttpPath, isTypescriptObject } from '@orpc/shared';
11
+ import { setOwn, getOwn, isDeepEqual, value, findDeepMatches, isPlainObject, stringifyJSON, toArray, clone, pathToHttpPath, mergeHttpPath, isTypescriptObject } from '@orpc/shared';
12
12
  import '@standard-server/core';
13
13
 
14
14
  function createContractJsonifiedClientFactory(link, options = {}) {
15
15
  return createContractClientFactory(link, options);
16
16
  }
17
17
 
18
+ const DEFS_REF_PREFIX = "#/$defs/";
19
+ const COMPONENTS_REF_PREFIX = "#/components/schemas/";
18
20
  class OpenAPIComponentRegistry {
19
21
  constructor(doc, customComponentName) {
20
22
  this.doc = doc;
@@ -28,13 +30,13 @@ class OpenAPIComponentRegistry {
28
30
  const { $defs, ...body } = schema;
29
31
  let defName = preferredName;
30
32
  if ($defs) {
31
- for (let i = 2; defName in $defs; i++) {
33
+ for (let i = 2; Object.hasOwn($defs, defName); i++) {
32
34
  defName = `${preferredName}${i}`;
33
35
  }
34
36
  }
35
37
  return this.hoistDefs({
36
38
  $defs: { ...$defs, [defName]: body },
37
- $ref: `#/$defs/${encodeJsonPointerSegment(defName)}`
39
+ $ref: `${DEFS_REF_PREFIX}${encodeJsonPointerSegment(defName)}`
38
40
  });
39
41
  }
40
42
  /**
@@ -46,60 +48,37 @@ class OpenAPIComponentRegistry {
46
48
  return schema;
47
49
  }
48
50
  const { $defs, ...rest } = schema;
49
- const defs = {};
50
- const preferredNames = {};
51
+ const defs = /* @__PURE__ */ new Map();
51
52
  for (const defName of Object.keys($defs)) {
52
53
  const defSchema = $defs[defName];
53
- if (defSchema === void 0) {
54
- continue;
54
+ if (defSchema !== void 0) {
55
+ defs.set(defName, ensureJsonSchemaObject(defSchema));
55
56
  }
56
- const normalized = ensureJsonSchemaObject(defSchema);
57
- defs[defName] = normalized;
58
- preferredNames[defName] = this.customComponentName?.(defName, normalized) ?? defName;
59
57
  }
60
- const defNames = Object.keys(defs);
61
- if (defNames.length === 0) {
58
+ if (defs.size === 0) {
62
59
  return schema;
63
60
  }
64
61
  this.doc.components ??= {};
65
62
  this.doc.components.schemas ??= {};
66
63
  const componentsSchemas = this.doc.components.schemas;
67
- const identityRenameMap = Object.fromEntries(
68
- defNames.map((defName) => [defName, preferredNames[defName]])
69
- );
70
- const renameMap = {};
64
+ const renameMap = /* @__PURE__ */ new Map();
71
65
  const pendingSchemas = [];
72
- for (const defName of defNames) {
73
- const cleanSchema = defs[defName];
74
- const candidateSchemas = Object.fromEntries(
75
- defNames.map((currentDefName) => [
76
- preferredNames[currentDefName],
77
- rewriteComponentSchemaRefs(defs[currentDefName], {
78
- ...identityRenameMap,
79
- ...renameMap
80
- })
81
- ])
82
- );
83
- const preferredName = preferredNames[defName];
84
- const prelimSchema = candidateSchemas[preferredName];
66
+ for (const [defName, cleanSchema] of defs) {
85
67
  const [componentName, reuseExisting] = resolveComponentName(
86
68
  componentsSchemas,
87
- new Set(Object.values(renameMap)),
88
- preferredName,
89
- prelimSchema,
90
- candidateSchemas,
69
+ new Set(renameMap.values()),
70
+ defName,
71
+ this.customComponentName?.(defName, cleanSchema) ?? defName,
72
+ defs,
91
73
  direction
92
74
  );
93
- renameMap[defName] = componentName;
75
+ renameMap.set(defName, componentName);
94
76
  if (!reuseExisting) {
95
77
  pendingSchemas.push({ cleanSchema, componentName });
96
78
  }
97
79
  }
98
80
  for (const { cleanSchema, componentName } of pendingSchemas) {
99
- componentsSchemas[componentName] = rewriteComponentSchemaRefs(
100
- cleanSchema,
101
- renameMap
102
- );
81
+ setOwn(componentsSchemas, componentName, rewriteComponentSchemaRefs(cleanSchema, renameMap));
103
82
  }
104
83
  return rewriteComponentSchemaRefs(rest, renameMap);
105
84
  }
@@ -107,11 +86,11 @@ class OpenAPIComponentRegistry {
107
86
  return ensureJsonSchemaObject(this.hoistDefs(schema, direction));
108
87
  }
109
88
  }
110
- function resolveComponentName(componentsSchemas, claimedNames, preferredName, schema, candidateSchemas, direction) {
89
+ function resolveComponentName(componentsSchemas, claimedNames, defName, preferredName, defs, direction) {
111
90
  let mintName;
112
91
  for (let i = 1; ; i++) {
113
92
  const [componentName, mintable, tail] = componentNameCandidate(preferredName, direction, i);
114
- const existingSchema = componentsSchemas[componentName];
93
+ const existingSchema = getOwn(componentsSchemas, componentName);
115
94
  if (existingSchema === void 0) {
116
95
  if (mintable && !claimedNames.has(componentName)) {
117
96
  mintName ??= componentName;
@@ -121,15 +100,10 @@ function resolveComponentName(componentsSchemas, claimedNames, preferredName, sc
121
100
  }
122
101
  continue;
123
102
  }
124
- if (areSchemasEquivalentForReuse(
125
- schema,
126
- existingSchema,
127
- schema,
128
- existingSchema,
129
- candidateSchemas,
130
- componentsSchemas,
131
- /* @__PURE__ */ new Map([[preferredName, componentName]]),
132
- /* @__PURE__ */ new Map([[componentName, preferredName]])
103
+ if (areSchemaRefsEquivalentForReuse(
104
+ DEFS_REF_PREFIX + encodeJsonPointerSegment(defName),
105
+ COMPONENTS_REF_PREFIX + encodeJsonPointerSegment(componentName),
106
+ { defs, componentsSchemas, candidateToExistingKeys: /* @__PURE__ */ new Map(), pairedExistingKeys: /* @__PURE__ */ new Set(), visited: /* @__PURE__ */ new WeakMap() }
133
107
  )) {
134
108
  return [componentName, true];
135
109
  }
@@ -153,7 +127,7 @@ function componentNameCandidate(preferredName, direction, attempt) {
153
127
  function definedKeysOf(object) {
154
128
  return Object.keys(object).filter((key) => object[key] !== void 0).sort();
155
129
  }
156
- function areSchemasEquivalentForReuse(candidate, existing, candidateRootSchema, existingRootSchema, candidateSchemas, existingSchemas, candidateToExistingComponentNames, existingToCandidateComponentNames, visited = /* @__PURE__ */ new WeakMap()) {
130
+ function areSchemasEquivalentForReuse(candidate, existing, ctx) {
157
131
  if (candidate === existing) {
158
132
  return true;
159
133
  }
@@ -166,30 +140,20 @@ function areSchemasEquivalentForReuse(candidate, existing, candidateRootSchema,
166
140
  if (typeof candidate !== "object" || typeof existing !== "object") {
167
141
  return isDeepEqual(candidate, existing);
168
142
  }
169
- const seenExisting = visited.get(candidate);
143
+ const seenExisting = ctx.visited.get(candidate);
170
144
  if (seenExisting?.has(existing)) {
171
145
  return true;
172
146
  }
173
147
  if (seenExisting) {
174
148
  seenExisting.add(existing);
175
149
  } else {
176
- visited.set(candidate, new WeakSet([existing]));
150
+ ctx.visited.set(candidate, new WeakSet([existing]));
177
151
  }
178
152
  if (Array.isArray(candidate) || Array.isArray(existing)) {
179
153
  if (!Array.isArray(candidate) || !Array.isArray(existing) || candidate.length !== existing.length) {
180
154
  return false;
181
155
  }
182
- return candidate.every((item, index) => areSchemasEquivalentForReuse(
183
- item,
184
- existing[index],
185
- candidateRootSchema,
186
- existingRootSchema,
187
- candidateSchemas,
188
- existingSchemas,
189
- candidateToExistingComponentNames,
190
- existingToCandidateComponentNames,
191
- visited
192
- ));
156
+ return candidate.every((item, index) => areSchemasEquivalentForReuse(item, existing[index], ctx));
193
157
  }
194
158
  const candidateObject = candidate;
195
159
  const existingObject = existing;
@@ -202,112 +166,53 @@ function areSchemasEquivalentForReuse(candidate, existing, candidateRootSchema,
202
166
  const candidateValue = candidateObject[key];
203
167
  const existingValue = existingObject[key];
204
168
  if (key === "$ref" && typeof candidateValue === "string" && typeof existingValue === "string") {
205
- return areSchemaRefsEquivalentForReuse(
206
- candidateValue,
207
- existingValue,
208
- candidateRootSchema,
209
- existingRootSchema,
210
- candidateSchemas,
211
- existingSchemas,
212
- candidateToExistingComponentNames,
213
- existingToCandidateComponentNames,
214
- visited
215
- );
169
+ return areSchemaRefsEquivalentForReuse(candidateValue, existingValue, ctx);
216
170
  }
217
- return areSchemasEquivalentForReuse(
218
- candidateValue,
219
- existingValue,
220
- candidateRootSchema,
221
- existingRootSchema,
222
- candidateSchemas,
223
- existingSchemas,
224
- candidateToExistingComponentNames,
225
- existingToCandidateComponentNames,
226
- visited
227
- );
171
+ return areSchemasEquivalentForReuse(candidateValue, existingValue, ctx);
228
172
  });
229
173
  }
230
- function parseComponentRefName(ref) {
231
- if (!ref.startsWith("#/components/schemas/")) {
174
+ function parseRefName(ref, prefix) {
175
+ if (!ref.startsWith(prefix)) {
232
176
  return void 0;
233
177
  }
234
- return ref.slice("#/components/schemas/".length).split("/").map(decodeJsonPointerSegment).join("/");
178
+ return ref.slice(prefix.length).split("/").map(decodeJsonPointerSegment).join("/");
235
179
  }
236
- function resolveSchemaComparisonRef(ref, rootSchema, componentsSchemas) {
237
- const localDefName = parseLocalDefRefName(ref);
238
- if (localDefName !== void 0 && typeof rootSchema === "object" && rootSchema !== null) {
239
- const localDef = rootSchema.$defs?.[localDefName];
240
- if (localDef !== void 0) {
241
- return {
242
- schema: localDef,
243
- rootSchema
244
- };
245
- }
246
- }
247
- const componentName = parseComponentRefName(ref);
248
- if (componentName !== void 0) {
249
- const componentSchema = componentsSchemas[componentName];
250
- if (componentSchema !== void 0) {
251
- return {
252
- schema: componentSchema,
253
- rootSchema: componentSchema
254
- };
255
- }
180
+ function resolveNamedRef(ref, prefix, getNamed) {
181
+ const name = parseRefName(ref, prefix);
182
+ if (name === void 0) {
183
+ return void 0;
256
184
  }
257
- return void 0;
185
+ const schema = getNamed(name);
186
+ return schema === void 0 ? void 0 : { key: prefix + name, schema };
258
187
  }
259
- function areSchemaRefsEquivalentForReuse(candidateRef, existingRef, candidateRootSchema, existingRootSchema, candidateSchemas, existingSchemas, candidateToExistingComponentNames, existingToCandidateComponentNames, visited) {
260
- const candidateComponentName = parseComponentRefName(candidateRef);
261
- const existingComponentName = parseComponentRefName(existingRef);
262
- if (candidateComponentName === void 0 !== (existingComponentName === void 0)) {
263
- return false;
264
- }
265
- if (candidateComponentName !== void 0 && existingComponentName !== void 0) {
266
- const mappedExisting = candidateToExistingComponentNames.get(candidateComponentName);
267
- if (mappedExisting !== void 0 && mappedExisting !== existingComponentName) {
188
+ function areSchemaRefsEquivalentForReuse(candidateRef, existingRef, ctx) {
189
+ const getComponent = (name) => getOwn(ctx.componentsSchemas, name);
190
+ const candidate = resolveNamedRef(candidateRef, DEFS_REF_PREFIX, (name) => ctx.defs.get(name)) ?? resolveNamedRef(candidateRef, COMPONENTS_REF_PREFIX, getComponent);
191
+ const existing = resolveNamedRef(existingRef, COMPONENTS_REF_PREFIX, getComponent);
192
+ if (candidate === void 0 || existing === void 0) {
193
+ return !candidate && !existing && candidateRef === existingRef;
194
+ }
195
+ const pairedExisting = ctx.candidateToExistingKeys.get(candidate.key);
196
+ if (pairedExisting !== existing.key) {
197
+ if (pairedExisting !== void 0 || ctx.pairedExistingKeys.has(existing.key)) {
268
198
  return false;
269
199
  }
270
- const mappedCandidate = existingToCandidateComponentNames.get(existingComponentName);
271
- if (mappedCandidate !== void 0 && mappedCandidate !== candidateComponentName) {
272
- return false;
273
- }
274
- candidateToExistingComponentNames.set(candidateComponentName, existingComponentName);
275
- existingToCandidateComponentNames.set(existingComponentName, candidateComponentName);
276
- }
277
- const resolvedCandidate = resolveSchemaComparisonRef(candidateRef, candidateRootSchema, candidateSchemas);
278
- const resolvedExisting = resolveSchemaComparisonRef(existingRef, existingRootSchema, existingSchemas);
279
- if (resolvedCandidate === void 0 || resolvedExisting === void 0) {
280
- return candidateRef === existingRef;
281
- }
282
- return areSchemasEquivalentForReuse(
283
- resolvedCandidate.schema,
284
- resolvedExisting.schema,
285
- resolvedCandidate.rootSchema,
286
- resolvedExisting.rootSchema,
287
- candidateSchemas,
288
- existingSchemas,
289
- candidateToExistingComponentNames,
290
- existingToCandidateComponentNames,
291
- visited
292
- );
293
- }
294
- function parseLocalDefRefName(ref) {
295
- if (!ref.startsWith("#/$defs/")) {
296
- return void 0;
200
+ ctx.candidateToExistingKeys.set(candidate.key, existing.key);
201
+ ctx.pairedExistingKeys.add(existing.key);
297
202
  }
298
- return ref.slice("#/$defs/".length).split("/").map(decodeJsonPointerSegment).join("/");
203
+ return areSchemasEquivalentForReuse(candidate.schema, existing.schema, ctx);
299
204
  }
300
205
  function rewriteComponentSchemaRefs(schema, renameMap) {
301
206
  return mapJsonSchemaRefs(schema, (ref) => {
302
- const refName = parseLocalDefRefName(ref);
207
+ const refName = parseRefName(ref, DEFS_REF_PREFIX);
303
208
  if (refName === void 0) {
304
209
  return ref;
305
210
  }
306
- const renamedName = renameMap[refName];
211
+ const renamedName = renameMap.get(refName);
307
212
  if (renamedName === void 0) {
308
213
  return ref;
309
214
  }
310
- return `#/components/schemas/${encodeJsonPointerSegment(renamedName)}`;
215
+ return COMPONENTS_REF_PREFIX + encodeJsonPointerSegment(renamedName);
311
216
  });
312
217
  }
313
218
 
@@ -816,7 +721,7 @@ ${errors.join("\n\n")}`
816
721
  }
817
722
  convertSchema(schema, direction) {
818
723
  const [jsonSchema, optional] = this.converter.convert(schema, direction);
819
- return [strip$schemaField(jsonSchema), optional];
724
+ return [hoistRecursiveRefToDef(strip$schemaField(jsonSchema)), optional];
820
725
  }
821
726
  convertSchemas(schemas, direction) {
822
727
  if (!schemas || schemas.length <= 1) {
@@ -5,7 +5,9 @@ import { ApiReferenceConfiguration } from '@scalar/api-reference';
5
5
  import { StandardUrl } from '@standard-server/core';
6
6
  import { SwaggerUIOptions } from 'swagger-ui';
7
7
  import { OpenAPIDocument, OpenAPIVersion } from '../index.mjs';
8
- import '@openapi-spec/types';
8
+ import '@openapi-spec/types/v3.0';
9
+ import '@openapi-spec/types/v3.1';
10
+ import '@openapi-spec/types/v3.2';
9
11
  import '@orpc/client';
10
12
 
11
13
  type OpenAPIReferenceHandlerPluginProvider = 'scalar' | 'swagger';
@@ -13,8 +15,20 @@ interface OpenAPIReferenceHandlerPluginScalarConfig extends Partial<ApiReference
13
15
  }
14
16
  interface OpenAPIReferenceHandlerPluginSwaggerConfig extends Partial<Omit<SwaggerUIOptions, 'dom_id' | 'presets' | 'plugins'>> {
15
17
  dom_id?: undefined | never;
16
- presets?: undefined | `SwaggerUIBundle.${string}`[];
17
- plugins?: undefined | `SwaggerUIBundle.${string}`[];
18
+ /**
19
+ * Paths to global variables holding the presets, resolved in the browser,
20
+ * e.g. `'SwaggerUIBundle.presets.apis'`. Load custom presets through `docsHead`.
21
+ *
22
+ * @default ['SwaggerUIBundle.presets.apis']
23
+ */
24
+ presets?: undefined | string[];
25
+ /**
26
+ * Paths to global variables holding the plugins, resolved in the browser,
27
+ * e.g. `'SwaggerUIBundle.plugins.DownloadUrl'`. Load custom plugins through `docsHead`.
28
+ *
29
+ * @default ['SwaggerUIBundle.plugins.DownloadUrl']
30
+ */
31
+ plugins?: undefined | string[];
18
32
  }
19
33
  interface OpenAPIReferenceHandlerPluginOptions<T extends Context, TProvider extends OpenAPIReferenceHandlerPluginProvider> {
20
34
  /**
@@ -5,7 +5,9 @@ import { ApiReferenceConfiguration } from '@scalar/api-reference';
5
5
  import { StandardUrl } from '@standard-server/core';
6
6
  import { SwaggerUIOptions } from 'swagger-ui';
7
7
  import { OpenAPIDocument, OpenAPIVersion } from '../index.js';
8
- import '@openapi-spec/types';
8
+ import '@openapi-spec/types/v3.0';
9
+ import '@openapi-spec/types/v3.1';
10
+ import '@openapi-spec/types/v3.2';
9
11
  import '@orpc/client';
10
12
 
11
13
  type OpenAPIReferenceHandlerPluginProvider = 'scalar' | 'swagger';
@@ -13,8 +15,20 @@ interface OpenAPIReferenceHandlerPluginScalarConfig extends Partial<ApiReference
13
15
  }
14
16
  interface OpenAPIReferenceHandlerPluginSwaggerConfig extends Partial<Omit<SwaggerUIOptions, 'dom_id' | 'presets' | 'plugins'>> {
15
17
  dom_id?: undefined | never;
16
- presets?: undefined | `SwaggerUIBundle.${string}`[];
17
- plugins?: undefined | `SwaggerUIBundle.${string}`[];
18
+ /**
19
+ * Paths to global variables holding the presets, resolved in the browser,
20
+ * e.g. `'SwaggerUIBundle.presets.apis'`. Load custom presets through `docsHead`.
21
+ *
22
+ * @default ['SwaggerUIBundle.presets.apis']
23
+ */
24
+ presets?: undefined | string[];
25
+ /**
26
+ * Paths to global variables holding the plugins, resolved in the browser,
27
+ * e.g. `'SwaggerUIBundle.plugins.DownloadUrl'`. Load custom plugins through `docsHead`.
28
+ *
29
+ * @default ['SwaggerUIBundle.plugins.DownloadUrl']
30
+ */
31
+ plugins?: undefined | string[];
18
32
  }
19
33
  interface OpenAPIReferenceHandlerPluginOptions<T extends Context, TProvider extends OpenAPIReferenceHandlerPluginProvider> {
20
34
  /**
@@ -69,13 +69,8 @@ class OpenAPIReferenceHandlerPlugin {
69
69
  dom_id: "#app",
70
70
  spec,
71
71
  deepLinking: true,
72
- presets: [
73
- "SwaggerUIBundle.presets.apis",
74
- "SwaggerUIBundle.presets.standalone"
75
- ],
76
- plugins: [
77
- "SwaggerUIBundle.plugins.DownloadUrl"
78
- ],
72
+ presets: ["SwaggerUIBundle.presets.apis"],
73
+ plugins: ["SwaggerUIBundle.plugins.DownloadUrl"],
79
74
  ...this.providerConfig
80
75
  };
81
76
  html = `
@@ -95,10 +90,15 @@ class OpenAPIReferenceHandlerPlugin {
95
90
 
96
91
  <!-- IMPORTANT: assign to a variable first to prevent ), ( in values breaking the call expression. -->
97
92
  <!-- IMPORTANT: escapeJsonForHtml ensures <, > cannot terminate the <\/script> tag prematurely. -->
93
+ <!-- IMPORTANT: resolve presets/plugins global paths at runtime, never unquote them in the JSON, which also holds the spec. -->
98
94
  <script>
99
- const swaggerConfig = ${escapeJsonForHtml(config).replace(/"(SwaggerUIBundle\.[.a-zA-Z0-9]+)"/g, "$1")}
95
+ const swaggerConfig = ${escapeJsonForHtml(config)}
100
96
 
101
97
  window.onload = () => {
98
+ for (const key of ['presets', 'plugins']) {
99
+ swaggerConfig[key] &&= swaggerConfig[key].map(path => path.split('.').reduce((value, name) => value?.[name], window))
100
+ }
101
+
102
102
  window.ui = SwaggerUIBundle(swaggerConfig)
103
103
  }
104
104
  <\/script>
@@ -4,7 +4,7 @@ import { StandardHandlerCodec, ResolvedStandardHandlerHandleOptions, StandardHan
4
4
  import { Value, Public, Promisable } from '@orpc/shared';
5
5
  import { StandardLazyRequest, StandardResponse } from '@standard-server/core';
6
6
  import { AnyProcedureContract } from '@orpc/contract';
7
- import { O as OpenAPISerializer } from './openapi.Dl3gew1x.mjs';
7
+ import { O as OpenAPISerializer } from './openapi.C2LayTNZ.mjs';
8
8
 
9
9
  interface OpenAPIMatcherOptions {
10
10
  /**
@@ -26,6 +26,7 @@ declare class OpenAPIMatcher {
26
26
  procedure: AnyProcedure;
27
27
  params?: Record<string, string> | undefined;
28
28
  } | undefined>;
29
+ private findMatch;
29
30
  private resolvePendingLazyRouters;
30
31
  private loadPendingLazyRouters;
31
32
  private loadPendingLazyRouter;