@orpc/openapi 2.0.0-beta.49 → 2.0.0-beta.50

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 (65) hide show
  1. package/dist/adapters/aws-lambda/index.d.ts +3 -15
  2. package/dist/adapters/aws-lambda/index.js +1 -1
  3. package/dist/adapters/aws-lambda/openapi-handler.d.ts +8 -9
  4. package/dist/adapters/aws-lambda/openapi-handler.js +19 -17
  5. package/dist/adapters/fastify/index.d.ts +2 -1
  6. package/dist/adapters/fastify/index.js +1 -1
  7. package/dist/adapters/fastify/openapi-handler.d.ts +8 -9
  8. package/dist/adapters/fastify/openapi-handler.js +16 -14
  9. package/dist/adapters/fetch/index.d.ts +3 -2
  10. package/dist/adapters/fetch/index.js +2 -2
  11. package/dist/adapters/fetch/openapi-handler.d.ts +8 -9
  12. package/dist/adapters/fetch/openapi-handler.js +16 -14
  13. package/dist/adapters/fetch/openapi-link.d.ts +9 -10
  14. package/dist/adapters/fetch/openapi-link.js +21 -19
  15. package/dist/adapters/node/index.d.ts +2 -1
  16. package/dist/adapters/node/index.js +1 -1
  17. package/dist/adapters/node/openapi-handler.d.ts +8 -9
  18. package/dist/adapters/node/openapi-handler.js +16 -14
  19. package/dist/adapters/standard/index.d.ts +4 -3
  20. package/dist/adapters/standard/index.js +3 -3
  21. package/dist/adapters/standard/openapi-handler-codec.d.ts +56 -57
  22. package/dist/adapters/standard/openapi-handler-codec.js +143 -205
  23. package/dist/adapters/standard/openapi-link-codec.d.ts +55 -59
  24. package/dist/adapters/standard/openapi-link-codec.js +262 -377
  25. package/dist/adapters/standard/openapi-matcher.d.ts +26 -26
  26. package/dist/adapters/standard/openapi-matcher.js +78 -108
  27. package/dist/adapters/standard/utils.js +28 -44
  28. package/dist/bracket-notation.d.ts +22 -22
  29. package/dist/bracket-notation.js +123 -173
  30. package/dist/client-factory.d.ts +12 -12
  31. package/dist/client-factory.js +13 -11
  32. package/dist/constants.d.ts +1 -4
  33. package/dist/constants.js +5 -4
  34. package/dist/extensions/route.d.ts +36 -36
  35. package/dist/extensions/route.js +7 -6
  36. package/dist/helpers/form-data.d.ts +1 -1
  37. package/dist/helpers/form-data.js +74 -86
  38. package/dist/helpers/index.d.ts +2 -1
  39. package/dist/helpers/index.js +1 -1
  40. package/dist/index.d.ts +15 -13
  41. package/dist/index.js +11 -11
  42. package/dist/meta.d.ts +298 -298
  43. package/dist/meta.js +54 -72
  44. package/dist/openapi-generator-components.d.ts +2 -31
  45. package/dist/openapi-generator-components.js +200 -248
  46. package/dist/openapi-generator-operation.d.ts +12 -33
  47. package/dist/openapi-generator-operation.js +369 -437
  48. package/dist/openapi-generator.d.ts +75 -80
  49. package/dist/openapi-generator.js +114 -142
  50. package/dist/openapi-json-serializer.d.ts +65 -65
  51. package/dist/openapi-json-serializer.js +218 -257
  52. package/dist/openapi-serializer.d.ts +31 -32
  53. package/dist/openapi-serializer.js +68 -92
  54. package/dist/plugins/index.d.ts +2 -1
  55. package/dist/plugins/index.js +1 -1
  56. package/dist/plugins/openapi-reference.d.ts +99 -102
  57. package/dist/plugins/openapi-reference.js +109 -132
  58. package/dist/router-utils.d.ts +7 -10
  59. package/dist/router-utils.js +30 -34
  60. package/dist/types.d.ts +8 -12
  61. package/dist/utils.d.ts +5 -10
  62. package/dist/utils.js +39 -42
  63. package/package.json +12 -12
  64. package/dist/adapters/standard/utils.d.ts +0 -4
  65. package/dist/types.js +0 -1
@@ -1,275 +1,227 @@
1
- import { decodeJsonPointerSegment, encodeJsonPointerSegment, ensureJsonSchemaObject, getJsonSchemaKeywordKind, mapJsonSchemaRefs, } from '@orpc/json-schema';
2
- import { getOwn, isDeepEqual, isPlainObject, setOwn } from '@orpc/shared';
3
- const DEFS_REF_PREFIX = '#/$defs/';
4
- const COMPONENTS_REF_PREFIX = '#/components/schemas/';
1
+ import { getOwn, isDeepEqual, isPlainObject, isPlainObjectOrArray, setOwn } from "@orpc/shared";
2
+ import { decodeJsonPointerSegment, encodeJsonPointerSegment, ensureJsonSchemaObject, getJsonSchemaKeywordKind, mapJsonSchemaRefs } from "@orpc/json-schema";
3
+ // src/openapi-generator-components.ts
4
+ const DEFS_REF_PREFIX = "#/$defs/";
5
+ const COMPONENTS_REF_PREFIX = "#/components/schemas/";
5
6
  /**
6
- * Replaces characters OpenAPI does not allow in component keys (`^[a-zA-Z0-9._-]+$`) with `_`.
7
- * Minted names are always valid keys, so refs to them need no JSON Pointer or URI escaping.
8
- */
7
+ * Replaces characters OpenAPI does not allow in component keys (`^[a-zA-Z0-9._-]+$`) with `_`.
8
+ * Minted names are always valid keys, so refs to them need no JSON Pointer or URI escaping.
9
+ */
9
10
  function toValidComponentName(name) {
10
- return name.replace(/[^a-zA-Z0-9._-]/gu, '_') || '_';
11
+ return name.replace(/[^a-zA-Z0-9._-]/gu, "_") || "_";
11
12
  }
12
13
  /**
13
- * Collects reusable schemas into `doc.components.schemas`.
14
- *
15
- * Equivalent schemas (including recursive ones) reuse a single component, and different
16
- * schemas competing for the same name get direction-suffixed or numbered postfixes.
17
- */
18
- export class OpenAPIComponentRegistry {
19
- doc;
20
- componentName;
21
- /**
22
- * The unsanitized name each minted component was requested under, so distinct names
23
- * that sanitize to the same key (`User Profile`, `User_Profile`) are never merged.
24
- * Components the registry did not mint are reusable only when the requested name needs
25
- * no sanitizing, which keeps `base.components` family reuse (`Planet`, `Planet2`) intact.
26
- */
27
- componentSources = new Map();
28
- constructor(doc, componentName) {
29
- this.doc = doc;
30
- this.componentName = componentName;
31
- }
32
- /**
33
- * Registers `schema` as a component under `preferredName` (or an equivalent/postfixed name)
34
- * and returns a `$ref` to it.
35
- */
36
- register(preferredName, schema) {
37
- const { $defs, ...body } = schema;
38
- // the schema can carry its own local $defs, keep the registered name unique among them
39
- let defName = preferredName;
40
- if ($defs) {
41
- for (let i = 2; Object.hasOwn($defs, defName); i++) {
42
- defName = `${preferredName}${i}`;
43
- }
44
- }
45
- return this.hoistDefs({
46
- $defs: { ...$defs, [defName]: body },
47
- $ref: `${DEFS_REF_PREFIX}${encodeJsonPointerSegment(defName)}`,
48
- });
49
- }
50
- /**
51
- * Moves a schema's root-level `$defs` into `doc.components.schemas` and rewrites
52
- * its refs accordingly.
53
- */
54
- hoistDefs(schema, direction) {
55
- if (typeof schema !== 'object' || !schema.$defs) {
56
- return schema;
57
- }
58
- const { $defs, ...rest } = schema;
59
- const defs = new Map();
60
- for (const defName of Object.keys($defs)) {
61
- const defSchema = $defs[defName];
62
- if (defSchema !== undefined) {
63
- defs.set(defName, ensureJsonSchemaObject(defSchema));
64
- }
65
- }
66
- if (defs.size === 0) {
67
- return schema;
68
- }
69
- this.doc.components ??= {};
70
- this.doc.components.schemas ??= {};
71
- const componentsSchemas = this.doc.components.schemas;
72
- const renameMap = new Map();
73
- const pendingSchemas = [];
74
- for (const [defName, cleanSchema] of defs) {
75
- const sourceName = this.componentName ? this.componentName(defName, cleanSchema) : defName;
76
- const preferredName = toValidComponentName(sourceName);
77
- const [componentName, reuseExisting] = resolveComponentName(componentsSchemas, new Set(renameMap.values()), defName, preferredName, (name) => (this.componentSources.get(name) ?? preferredName) === sourceName, defs, direction);
78
- renameMap.set(defName, componentName);
79
- if (!reuseExisting) {
80
- this.componentSources.set(componentName, sourceName);
81
- pendingSchemas.push({ cleanSchema, componentName });
82
- }
83
- }
84
- for (const { cleanSchema, componentName } of pendingSchemas) {
85
- setOwn(componentsSchemas, componentName, rewriteComponentSchemaRefs(cleanSchema, renameMap));
86
- }
87
- return rewriteComponentSchemaRefs(rest, renameMap);
88
- }
89
- toOpenAPISchema(schema, direction) {
90
- return ensureJsonSchemaObject(this.hoistDefs(schema, direction));
91
- }
92
- }
14
+ * Collects reusable schemas into `doc.components.schemas`.
15
+ *
16
+ * Equivalent schemas (including recursive ones) reuse a single component, and different
17
+ * schemas competing for the same name get direction-suffixed or numbered postfixes.
18
+ */
19
+ var OpenAPIComponentRegistry = class {
20
+ doc;
21
+ componentName;
22
+ /**
23
+ * The unsanitized name each minted component was requested under, so distinct names
24
+ * that sanitize to the same key (`User Profile`, `User_Profile`) are never merged.
25
+ * Components the registry did not mint are reusable only when the requested name needs
26
+ * no sanitizing, which keeps `base.components` family reuse (`Planet`, `Planet2`) intact.
27
+ */
28
+ componentSources = /* @__PURE__ */ new Map();
29
+ constructor(doc, componentName) {
30
+ this.doc = doc;
31
+ this.componentName = componentName;
32
+ }
33
+ /**
34
+ * Registers `schema` as a component under `preferredName` (or an equivalent/postfixed name)
35
+ * and returns a `$ref` to it.
36
+ */
37
+ register(preferredName, schema) {
38
+ const { $defs, ...body } = schema;
39
+ let defName = preferredName;
40
+ if ($defs) for (let i = 2; Object.hasOwn($defs, defName); i++) defName = `${preferredName}${i}`;
41
+ return this.hoistDefs({
42
+ $defs: {
43
+ ...$defs,
44
+ [defName]: body
45
+ },
46
+ $ref: `${DEFS_REF_PREFIX}${encodeJsonPointerSegment(defName)}`
47
+ });
48
+ }
49
+ /**
50
+ * Moves a schema's root-level `$defs` into `doc.components.schemas` and rewrites
51
+ * its refs accordingly.
52
+ */
53
+ hoistDefs(schema, direction) {
54
+ if (typeof schema !== "object" || !schema.$defs) return schema;
55
+ const { $defs, ...rest } = schema;
56
+ const defs = /* @__PURE__ */ new Map();
57
+ for (const defName of Object.keys($defs)) {
58
+ const defSchema = $defs[defName];
59
+ if (defSchema !== void 0) defs.set(defName, ensureJsonSchemaObject(defSchema));
60
+ }
61
+ if (defs.size === 0) return schema;
62
+ this.doc.components ??= {};
63
+ this.doc.components.schemas ??= {};
64
+ const componentsSchemas = this.doc.components.schemas;
65
+ const renameMap = /* @__PURE__ */ new Map();
66
+ const pendingSchemas = [];
67
+ for (const [defName, cleanSchema] of defs) {
68
+ const sourceName = this.componentName ? this.componentName(defName, cleanSchema) : defName;
69
+ const preferredName = toValidComponentName(sourceName);
70
+ const [componentName, reuseExisting] = resolveComponentName(componentsSchemas, new Set(renameMap.values()), defName, preferredName, (name) => (this.componentSources.get(name) ?? preferredName) === sourceName, defs, direction);
71
+ renameMap.set(defName, componentName);
72
+ if (!reuseExisting) {
73
+ this.componentSources.set(componentName, sourceName);
74
+ pendingSchemas.push({
75
+ cleanSchema,
76
+ componentName
77
+ });
78
+ }
79
+ }
80
+ for (const { cleanSchema, componentName } of pendingSchemas) setOwn(componentsSchemas, componentName, rewriteComponentSchemaRefs(cleanSchema, renameMap));
81
+ return rewriteComponentSchemaRefs(rest, renameMap);
82
+ }
83
+ toOpenAPISchema(schema, direction) {
84
+ return ensureJsonSchemaObject(this.hoistDefs(schema, direction));
85
+ }
86
+ };
93
87
  /**
94
- * Walks a def's name family until it finds an equivalent existing component to reuse or
95
- * runs out of family members, then fills the first free mintable slot. Equal schemas under
96
- * unrelated names are never merged: a different name signals a different purpose.
97
- *
98
- * The family is the bare name, the direction-suffixed names when the conversion direction
99
- * is known, then plain numeric postfixes (`Planet`, `PlanetOutput`, `PlanetInput`,
100
- * `Planet2`, ...). Every member is checked for reuse, including the opposite direction,
101
- * but new components are only minted under the bare, own-direction, or numeric names.
102
- */
88
+ * Walks a def's name family until it finds an equivalent existing component to reuse or
89
+ * runs out of family members, then fills the first free mintable slot. Equal schemas under
90
+ * unrelated names are never merged: a different name signals a different purpose.
91
+ *
92
+ * The family is the bare name, the direction-suffixed names when the conversion direction
93
+ * is known, then plain numeric postfixes (`Planet`, `PlanetOutput`, `PlanetInput`,
94
+ * `Planet2`, ...). Every member is checked for reuse, including the opposite direction,
95
+ * but new components are only minted under the bare, own-direction, or numeric names.
96
+ */
103
97
  function resolveComponentName(componentsSchemas, claimedNames, defName, preferredName, isReusable, defs, direction) {
104
- let mintName;
105
- for (let i = 1;; i++) {
106
- const [componentName, mintable, tail] = componentNameCandidate(preferredName, direction, i);
107
- const existingSchema = getOwn(componentsSchemas, componentName);
108
- if (existingSchema === undefined) {
109
- // a sibling def can claim a slot before its schema is written, keep probing past it
110
- if (mintable && !claimedNames.has(componentName)) {
111
- mintName ??= componentName;
112
- if (tail) {
113
- return [mintName, false];
114
- }
115
- }
116
- continue;
117
- }
118
- if (isReusable(componentName) &&
119
- areSchemaRefsEquivalentForReuse(DEFS_REF_PREFIX + encodeJsonPointerSegment(defName), COMPONENTS_REF_PREFIX + componentName, {
120
- defs,
121
- componentsSchemas,
122
- candidateToExistingKeys: new Map(),
123
- pairedExistingKeys: new Set(),
124
- visited: new WeakMap(),
125
- })) {
126
- return [componentName, true];
127
- }
128
- }
98
+ let mintName;
99
+ for (let i = 1;; i++) {
100
+ const [componentName, mintable, tail] = componentNameCandidate(preferredName, direction, i);
101
+ if (getOwn(componentsSchemas, componentName) === void 0) {
102
+ if (mintable && !claimedNames.has(componentName)) {
103
+ mintName ??= componentName;
104
+ if (tail) return [mintName, false];
105
+ }
106
+ continue;
107
+ }
108
+ if (isReusable(componentName) && areSchemaRefsEquivalentForReuse(DEFS_REF_PREFIX + encodeJsonPointerSegment(defName), COMPONENTS_REF_PREFIX + componentName, {
109
+ defs,
110
+ componentsSchemas,
111
+ candidateToExistingKeys: /* @__PURE__ */ new Map(),
112
+ pairedExistingKeys: /* @__PURE__ */ new Set(),
113
+ visited: /* @__PURE__ */ new WeakMap()
114
+ })) return [componentName, true];
115
+ }
129
116
  }
130
117
  function componentNameCandidate(preferredName, direction, attempt) {
131
- if (attempt === 1) {
132
- return [preferredName, true, false];
133
- }
134
- if (direction !== undefined) {
135
- if (attempt === 2) {
136
- return [`${preferredName}${direction === 'input' ? 'Input' : 'Output'}`, true, false];
137
- }
138
- // the opposite direction is only ever reused, never minted
139
- if (attempt === 3) {
140
- return [`${preferredName}${direction === 'input' ? 'Output' : 'Input'}`, false, false];
141
- }
142
- return [`${preferredName}${attempt - 2}`, true, true];
143
- }
144
- return [`${preferredName}${attempt}`, true, true];
118
+ if (attempt === 1) return [
119
+ preferredName,
120
+ true,
121
+ false
122
+ ];
123
+ if (direction !== void 0) {
124
+ if (attempt === 2) return [
125
+ `${preferredName}${direction === "input" ? "Input" : "Output"}`,
126
+ true,
127
+ false
128
+ ];
129
+ if (attempt === 3) return [
130
+ `${preferredName}${direction === "input" ? "Output" : "Input"}`,
131
+ false,
132
+ false
133
+ ];
134
+ return [
135
+ `${preferredName}${attempt - 2}`,
136
+ true,
137
+ true
138
+ ];
139
+ }
140
+ return [
141
+ `${preferredName}${attempt}`,
142
+ true,
143
+ true
144
+ ];
145
145
  }
146
146
  function definedKeysOf(object) {
147
- // `undefined`-valued keys (e.g. `default: undefined`) are stripped during serialization,
148
- // so they must not affect equivalence against components from serialized documents
149
- return (Object.keys(object)
150
- .filter((key) => object[key] !== undefined)
151
- // oxlint-disable-next-line unicorn/no-array-sort
152
- .sort());
153
- }
154
- function isSchemaContainer(value) {
155
- return Array.isArray(value) || isPlainObject(value);
147
+ return Object.keys(object).filter((key) => object[key] !== void 0).sort();
156
148
  }
157
- function areSchemasEquivalentForReuse(candidate, existing, ctx, position = 'schema') {
158
- if (candidate === existing) {
159
- return true;
160
- }
161
- // Only arrays and plain objects carry schema structure; primitives and values like Date are compared as a whole
162
- if (!isSchemaContainer(candidate) || !isSchemaContainer(existing)) {
163
- return isDeepEqual(candidate, existing);
164
- }
165
- const seenExisting = ctx.visited.get(candidate);
166
- if (seenExisting?.has(existing)) {
167
- return true;
168
- }
169
- if (seenExisting) {
170
- seenExisting.add(existing);
171
- }
172
- else {
173
- ctx.visited.set(candidate, new WeakSet([existing]));
174
- }
175
- if (Array.isArray(candidate) || Array.isArray(existing)) {
176
- if (!Array.isArray(candidate) ||
177
- !Array.isArray(existing) ||
178
- candidate.length !== existing.length) {
179
- return false;
180
- }
181
- return candidate.every((item, index) => areSchemasEquivalentForReuse(item, existing[index], ctx, position));
182
- }
183
- return areObjectsEquivalentForReuse(candidate, existing, (key, candidateValue, existingValue) => {
184
- if (position === 'data') {
185
- return areSchemasEquivalentForReuse(candidateValue, existingValue, ctx, 'data');
186
- }
187
- switch (getJsonSchemaKeywordKind(key, candidateValue, position === 'schema')) {
188
- case 'ref':
189
- return areRefValuesEquivalentForReuse(candidateValue, existingValue, ctx);
190
- case 'discriminator':
191
- return areDiscriminatorsEquivalentForReuse(candidateValue, existingValue, ctx);
192
- case 'schema':
193
- return areSchemasEquivalentForReuse(candidateValue, existingValue, ctx);
194
- case 'schema-record':
195
- return areSchemasEquivalentForReuse(candidateValue, existingValue, ctx, 'schema-record');
196
- default:
197
- return areSchemasEquivalentForReuse(candidateValue, existingValue, ctx, 'data');
198
- }
199
- });
149
+ function areSchemasEquivalentForReuse(candidate, existing, ctx, position = "schema") {
150
+ if (candidate === existing) return true;
151
+ if (!isPlainObjectOrArray(candidate) || !isPlainObjectOrArray(existing)) return isDeepEqual(candidate, existing);
152
+ const seenExisting = ctx.visited.get(candidate);
153
+ if (seenExisting?.has(existing)) return true;
154
+ if (seenExisting) seenExisting.add(existing);
155
+ else ctx.visited.set(candidate, new WeakSet([existing]));
156
+ if (Array.isArray(candidate) || Array.isArray(existing)) {
157
+ if (!Array.isArray(candidate) || !Array.isArray(existing) || candidate.length !== existing.length) return false;
158
+ return candidate.every((item, index) => areSchemasEquivalentForReuse(item, existing[index], ctx, position));
159
+ }
160
+ return areObjectsEquivalentForReuse(candidate, existing, (key, candidateValue, existingValue) => {
161
+ if (position === "data") return areSchemasEquivalentForReuse(candidateValue, existingValue, ctx, "data");
162
+ switch (getJsonSchemaKeywordKind(key, candidateValue, position === "schema")) {
163
+ case "ref": return areRefValuesEquivalentForReuse(candidateValue, existingValue, ctx);
164
+ case "discriminator": return areDiscriminatorsEquivalentForReuse(candidateValue, existingValue, ctx);
165
+ case "schema": return areSchemasEquivalentForReuse(candidateValue, existingValue, ctx);
166
+ case "schema-record": return areSchemasEquivalentForReuse(candidateValue, existingValue, ctx, "schema-record");
167
+ default: return areSchemasEquivalentForReuse(candidateValue, existingValue, ctx, "data");
168
+ }
169
+ });
200
170
  }
201
171
  function areObjectsEquivalentForReuse(candidate, existing, areValuesEquivalent) {
202
- const candidateKeys = definedKeysOf(candidate);
203
- return (isDeepEqual(candidateKeys, definedKeysOf(existing)) &&
204
- candidateKeys.every((key) => areValuesEquivalent(key, candidate[key], existing[key])));
172
+ const candidateKeys = definedKeysOf(candidate);
173
+ return isDeepEqual(candidateKeys, definedKeysOf(existing)) && candidateKeys.every((key) => areValuesEquivalent(key, candidate[key], existing[key]));
205
174
  }
206
175
  function areRefValuesEquivalentForReuse(candidate, existing, ctx) {
207
- if (typeof candidate === 'string' && typeof existing === 'string') {
208
- return areSchemaRefsEquivalentForReuse(candidate, existing, ctx);
209
- }
210
- return areSchemasEquivalentForReuse(candidate, existing, ctx, 'data');
176
+ if (typeof candidate === "string" && typeof existing === "string") return areSchemaRefsEquivalentForReuse(candidate, existing, ctx);
177
+ return areSchemasEquivalentForReuse(candidate, existing, ctx, "data");
211
178
  }
212
179
  /**
213
- * `discriminator.mapping`/`defaultMapping` values can be refs, which are rewritten during hoisting like `$ref`,
214
- * so they must be compared by their targets rather than by their (prefix-dependent) strings.
215
- * Values that are not refs (bare schema names) still compare by string equality.
216
- */
180
+ * `discriminator.mapping`/`defaultMapping` values can be refs, which are rewritten during hoisting like `$ref`,
181
+ * so they must be compared by their targets rather than by their (prefix-dependent) strings.
182
+ * Values that are not refs (bare schema names) still compare by string equality.
183
+ */
217
184
  function areDiscriminatorsEquivalentForReuse(candidate, existing, ctx) {
218
- if (!isPlainObject(candidate) || !isPlainObject(existing)) {
219
- return areSchemasEquivalentForReuse(candidate, existing, ctx, 'data');
220
- }
221
- return areObjectsEquivalentForReuse(candidate, existing, (key, candidateValue, existingValue) => {
222
- if (key === 'mapping' && isPlainObject(candidateValue) && isPlainObject(existingValue)) {
223
- return areObjectsEquivalentForReuse(candidateValue, existingValue, (_, candidateRef, existingRef) => areRefValuesEquivalentForReuse(candidateRef, existingRef, ctx));
224
- }
225
- if (key === 'defaultMapping') {
226
- return areRefValuesEquivalentForReuse(candidateValue, existingValue, ctx);
227
- }
228
- return areSchemasEquivalentForReuse(candidateValue, existingValue, ctx, 'data');
229
- });
185
+ if (!isPlainObject(candidate) || !isPlainObject(existing)) return areSchemasEquivalentForReuse(candidate, existing, ctx, "data");
186
+ return areObjectsEquivalentForReuse(candidate, existing, (key, candidateValue, existingValue) => {
187
+ if (key === "mapping" && isPlainObject(candidateValue) && isPlainObject(existingValue)) return areObjectsEquivalentForReuse(candidateValue, existingValue, (_, candidateRef, existingRef) => areRefValuesEquivalentForReuse(candidateRef, existingRef, ctx));
188
+ if (key === "defaultMapping") return areRefValuesEquivalentForReuse(candidateValue, existingValue, ctx);
189
+ return areSchemasEquivalentForReuse(candidateValue, existingValue, ctx, "data");
190
+ });
230
191
  }
231
192
  function parseRefName(ref, prefix) {
232
- if (!ref.startsWith(prefix)) {
233
- return undefined;
234
- }
235
- return ref.slice(prefix.length).split('/').map(decodeJsonPointerSegment).join('/');
193
+ if (!ref.startsWith(prefix)) return;
194
+ return ref.slice(prefix.length).split("/").map(decodeJsonPointerSegment).join("/");
236
195
  }
237
196
  function resolveNamedRef(ref, prefix, getNamed) {
238
- const name = parseRefName(ref, prefix);
239
- if (name === undefined) {
240
- return undefined;
241
- }
242
- const schema = getNamed(name);
243
- return schema === undefined ? undefined : { key: prefix + name, schema };
197
+ const name = parseRefName(ref, prefix);
198
+ if (name === void 0) return;
199
+ const schema = getNamed(name);
200
+ return schema === void 0 ? void 0 : {
201
+ key: prefix + name,
202
+ schema
203
+ };
244
204
  }
245
205
  function areSchemaRefsEquivalentForReuse(candidateRef, existingRef, ctx) {
246
- const getComponent = (name) => getOwn(ctx.componentsSchemas, name);
247
- const candidate = resolveNamedRef(candidateRef, DEFS_REF_PREFIX, (name) => ctx.defs.get(name)) ??
248
- resolveNamedRef(candidateRef, COMPONENTS_REF_PREFIX, getComponent);
249
- const existing = resolveNamedRef(existingRef, COMPONENTS_REF_PREFIX, getComponent);
250
- if (candidate === undefined || existing === undefined) {
251
- return !candidate && !existing && candidateRef === existingRef;
252
- }
253
- const pairedExisting = ctx.candidateToExistingKeys.get(candidate.key);
254
- if (pairedExisting !== existing.key) {
255
- if (pairedExisting !== undefined || ctx.pairedExistingKeys.has(existing.key)) {
256
- return false;
257
- }
258
- ctx.candidateToExistingKeys.set(candidate.key, existing.key);
259
- ctx.pairedExistingKeys.add(existing.key);
260
- }
261
- return areSchemasEquivalentForReuse(candidate.schema, existing.schema, ctx);
206
+ const getComponent = (name) => getOwn(ctx.componentsSchemas, name);
207
+ const candidate = resolveNamedRef(candidateRef, DEFS_REF_PREFIX, (name) => ctx.defs.get(name)) ?? resolveNamedRef(candidateRef, COMPONENTS_REF_PREFIX, getComponent);
208
+ const existing = resolveNamedRef(existingRef, COMPONENTS_REF_PREFIX, getComponent);
209
+ if (candidate === void 0 || existing === void 0) return !candidate && !existing && candidateRef === existingRef;
210
+ const pairedExisting = ctx.candidateToExistingKeys.get(candidate.key);
211
+ if (pairedExisting !== existing.key) {
212
+ if (pairedExisting !== void 0 || ctx.pairedExistingKeys.has(existing.key)) return false;
213
+ ctx.candidateToExistingKeys.set(candidate.key, existing.key);
214
+ ctx.pairedExistingKeys.add(existing.key);
215
+ }
216
+ return areSchemasEquivalentForReuse(candidate.schema, existing.schema, ctx);
262
217
  }
263
218
  function rewriteComponentSchemaRefs(schema, renameMap) {
264
- return mapJsonSchemaRefs(schema, (ref) => {
265
- const refName = parseRefName(ref, DEFS_REF_PREFIX);
266
- if (refName === undefined) {
267
- return ref;
268
- }
269
- const renamedName = renameMap.get(refName);
270
- if (renamedName === undefined) {
271
- return ref;
272
- }
273
- return COMPONENTS_REF_PREFIX + renamedName;
274
- });
219
+ return mapJsonSchemaRefs(schema, (ref) => {
220
+ const refName = parseRefName(ref, DEFS_REF_PREFIX);
221
+ if (refName === void 0) return ref;
222
+ const renamedName = renameMap.get(refName);
223
+ if (renamedName === void 0) return ref;
224
+ return COMPONENTS_REF_PREFIX + renamedName;
225
+ });
275
226
  }
227
+ export { OpenAPIComponentRegistry };
@@ -1,34 +1,13 @@
1
- import type { AnyProcedureContract, AnySchema } from '@orpc/contract';
2
- import type { JsonSchema, JsonSchemaConverterDirection } from '@orpc/json-schema';
3
- import type { Value } from '@orpc/shared';
4
- import type { OpenAPIMeta } from './meta.ts';
5
- import type { OpenAPIComponentRegistry } from './openapi-generator-components.ts';
6
- import type { OpenAPIV3_2 } from './types.ts';
7
- import type { getDynamicPathParams } from './utils.ts';
8
- export type DynamicPathParam = NonNullable<ReturnType<typeof getDynamicPathParams>>[number];
9
- export declare class OpenAPIGeneratorError extends TypeError {
10
- }
1
+ import "./meta.js";
2
+ import "./openapi-generator-components.js";
3
+ import "./types.js";
4
+ import "@orpc/shared";
5
+ import "@orpc/contract";
6
+ import { JsonSchema } from "@orpc/json-schema";
7
+ export declare class OpenAPIGeneratorError extends TypeError {}
11
8
  export interface OpenAPIErrorBodyDefinition {
12
- code: string;
13
- defaultMessage: string | undefined;
14
- dataOptional: boolean;
15
- dataJsonSchema: JsonSchema;
16
- }
17
- /**
18
- * Everything the operation builders need from the surrounding `generate()` call.
19
- */
20
- export interface OpenAPIOperationContext {
21
- registry: OpenAPIComponentRegistry;
22
- convertSchemas: (schemas: AnySchema[] | undefined, direction: JsonSchemaConverterDirection) => [JsonSchema, boolean];
23
- errorStatusMap: Record<string, number>;
24
- errorResponseBodySchema: Value<JsonSchema | null | undefined, [
25
- definedErrors: OpenAPIErrorBodyDefinition[],
26
- status: number,
27
- defaultSchema: () => JsonSchema
28
- ]> | undefined;
29
- errorResponseContentType: string;
30
- }
31
- export declare function toOpenAPIPath(path: `/${string}`, dynamicPathParams: DynamicPathParam[] | undefined): `/${string}`;
32
- export declare function buildRequest(ctx: OpenAPIOperationContext, operation: OpenAPIV3_2.OperationObject, def: AnyProcedureContract['~orpc'], meta: OpenAPIMeta | undefined, dynamicPathParams: DynamicPathParam[] | undefined): void;
33
- export declare function buildSuccessResponse(ctx: OpenAPIOperationContext, operation: OpenAPIV3_2.OperationObject, def: AnyProcedureContract['~orpc'], meta: OpenAPIMeta | undefined): void;
34
- export declare function buildErrorResponse(ctx: OpenAPIOperationContext, operation: OpenAPIV3_2.OperationObject, def: AnyProcedureContract['~orpc']): void;
9
+ code: string;
10
+ defaultMessage: string | undefined;
11
+ dataOptional: boolean;
12
+ dataJsonSchema: JsonSchema;
13
+ }