@orpc/openapi 2.0.0-beta.46 → 2.0.0-beta.48
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 +6 -4
- package/dist/adapters/aws-lambda/index.d.mts +14 -26
- package/dist/adapters/aws-lambda/index.mjs +1 -21
- package/dist/adapters/aws-lambda/openapi-handler.d.mts +17 -0
- package/dist/adapters/aws-lambda/openapi-handler.mjs +11 -0
- package/dist/adapters/fastify/index.d.mts +1 -23
- package/dist/adapters/fastify/index.mjs +1 -21
- package/dist/adapters/fastify/openapi-handler.d.mts +14 -0
- package/dist/adapters/fastify/openapi-handler.mjs +11 -0
- package/dist/adapters/fetch/index.d.mts +2 -37
- package/dist/adapters/fetch/index.mjs +2 -34
- package/dist/adapters/fetch/openapi-handler.d.mts +14 -0
- package/dist/adapters/fetch/openapi-handler.mjs +11 -0
- package/dist/adapters/fetch/openapi-link.d.mts +15 -0
- package/dist/adapters/fetch/openapi-link.mjs +11 -0
- package/dist/adapters/node/index.d.mts +1 -23
- package/dist/adapters/node/index.mjs +1 -21
- package/dist/adapters/node/openapi-handler.d.mts +14 -0
- package/dist/adapters/node/openapi-handler.mjs +11 -0
- package/dist/adapters/standard/index.d.mts +3 -48
- package/dist/adapters/standard/index.mjs +3 -12
- package/dist/adapters/standard/openapi-handler-codec.d.mts +61 -0
- package/dist/adapters/standard/openapi-handler-codec.mjs +203 -0
- package/dist/adapters/standard/openapi-link-codec.d.mts +53 -0
- package/dist/adapters/standard/openapi-link-codec.mjs +356 -0
- package/dist/adapters/standard/openapi-matcher.d.mts +29 -0
- package/dist/adapters/standard/openapi-matcher.mjs +105 -0
- package/dist/adapters/standard/utils.d.mts +4 -0
- package/dist/adapters/standard/utils.mjs +36 -0
- package/dist/bracket-notation.d.mts +26 -0
- package/dist/bracket-notation.mjs +156 -0
- package/dist/client-factory.d.mts +24 -0
- package/dist/client-factory.mjs +5 -0
- package/dist/constants.d.mts +4 -0
- package/dist/constants.mjs +4 -0
- package/dist/extensions/route.d.mts +74 -39
- package/dist/extensions/route.mjs +8 -10
- package/dist/helpers/form-data.d.mts +57 -0
- package/dist/helpers/form-data.mjs +36 -0
- package/dist/helpers/index.d.mts +1 -59
- package/dist/helpers/index.mjs +1 -39
- package/dist/index.d.mts +13 -159
- package/dist/index.mjs +11 -778
- package/dist/meta.d.mts +345 -0
- package/dist/meta.mjs +56 -0
- package/dist/openapi-generator-components.d.mts +24 -0
- package/dist/openapi-generator-components.mjs +227 -0
- package/dist/openapi-generator-operation.d.mts +29 -0
- package/dist/openapi-generator-operation.mjs +447 -0
- package/dist/openapi-generator.d.mts +87 -0
- package/dist/openapi-generator.mjs +115 -0
- package/dist/openapi-json-serializer.d.mts +86 -0
- package/dist/openapi-json-serializer.mjs +229 -0
- package/dist/openapi-serializer.d.mts +43 -0
- package/dist/openapi-serializer.mjs +87 -0
- package/dist/plugins/index.d.mts +1 -121
- package/dist/plugins/index.mjs +1 -167
- package/dist/plugins/openapi-reference.d.mts +118 -0
- package/dist/plugins/openapi-reference.mjs +157 -0
- package/dist/router-utils.d.mts +18 -0
- package/dist/router-utils.mjs +29 -0
- package/dist/types.d.mts +27 -0
- package/dist/types.mjs +1 -0
- package/dist/utils.d.mts +14 -0
- package/dist/utils.mjs +40 -0
- package/package.json +15 -15
- package/dist/adapters/aws-lambda/index.d.ts +0 -27
- package/dist/adapters/fastify/index.d.ts +0 -23
- package/dist/adapters/fetch/index.d.ts +0 -37
- package/dist/adapters/node/index.d.ts +0 -23
- package/dist/adapters/standard/index.d.ts +0 -48
- package/dist/extensions/route.d.ts +0 -41
- package/dist/helpers/index.d.ts +0 -59
- package/dist/index.d.ts +0 -159
- package/dist/plugins/index.d.ts +0 -121
- package/dist/shared/openapi.B9PQzqBn.mjs +0 -49
- package/dist/shared/openapi.BCrrWRbv.d.mts +0 -87
- package/dist/shared/openapi.BNe1y1cD.mjs +0 -360
- package/dist/shared/openapi.B_SoJfYz.d.mts +0 -328
- package/dist/shared/openapi.B_SoJfYz.d.ts +0 -328
- package/dist/shared/openapi.BkjX_6hE.d.ts +0 -87
- package/dist/shared/openapi.Covi8zVE.d.mts +0 -33
- package/dist/shared/openapi.Covi8zVE.d.ts +0 -33
- package/dist/shared/openapi.DXqJL3gB.mjs +0 -408
- package/dist/shared/openapi.DtEVcxuW.mjs +0 -149
- package/dist/shared/openapi.E3ZBiweM.mjs +0 -353
- package/dist/shared/openapi.YMRD3b4R.d.mts +0 -157
- package/dist/shared/openapi.YMRD3b4R.d.ts +0 -157
package/dist/index.mjs
CHANGED
|
@@ -1,778 +1,11 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
import '@standard-server/core';
|
|
13
|
-
|
|
14
|
-
function createContractJsonifiedClientFactory(link, options = {}) {
|
|
15
|
-
return createContractClientFactory(link, options);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const DEFS_REF_PREFIX = "#/$defs/";
|
|
19
|
-
const COMPONENTS_REF_PREFIX = "#/components/schemas/";
|
|
20
|
-
class OpenAPIComponentRegistry {
|
|
21
|
-
constructor(doc, customComponentName) {
|
|
22
|
-
this.doc = doc;
|
|
23
|
-
this.customComponentName = customComponentName;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Registers `schema` as a component under `preferredName` (or an equivalent/postfixed name)
|
|
27
|
-
* and returns a `$ref` to it.
|
|
28
|
-
*/
|
|
29
|
-
register(preferredName, schema) {
|
|
30
|
-
const { $defs, ...body } = schema;
|
|
31
|
-
let defName = preferredName;
|
|
32
|
-
if ($defs) {
|
|
33
|
-
for (let i = 2; Object.hasOwn($defs, defName); i++) {
|
|
34
|
-
defName = `${preferredName}${i}`;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
return this.hoistDefs({
|
|
38
|
-
$defs: { ...$defs, [defName]: body },
|
|
39
|
-
$ref: `${DEFS_REF_PREFIX}${encodeJsonPointerSegment(defName)}`
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Moves a schema's root-level `$defs` into `doc.components.schemas` and rewrites
|
|
44
|
-
* its refs accordingly.
|
|
45
|
-
*/
|
|
46
|
-
hoistDefs(schema, direction) {
|
|
47
|
-
if (typeof schema !== "object" || !schema.$defs) {
|
|
48
|
-
return schema;
|
|
49
|
-
}
|
|
50
|
-
const { $defs, ...rest } = schema;
|
|
51
|
-
const defs = /* @__PURE__ */ new Map();
|
|
52
|
-
for (const defName of Object.keys($defs)) {
|
|
53
|
-
const defSchema = $defs[defName];
|
|
54
|
-
if (defSchema !== void 0) {
|
|
55
|
-
defs.set(defName, ensureJsonSchemaObject(defSchema));
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
if (defs.size === 0) {
|
|
59
|
-
return schema;
|
|
60
|
-
}
|
|
61
|
-
this.doc.components ??= {};
|
|
62
|
-
this.doc.components.schemas ??= {};
|
|
63
|
-
const componentsSchemas = this.doc.components.schemas;
|
|
64
|
-
const renameMap = /* @__PURE__ */ new Map();
|
|
65
|
-
const pendingSchemas = [];
|
|
66
|
-
for (const [defName, cleanSchema] of defs) {
|
|
67
|
-
const [componentName, reuseExisting] = resolveComponentName(
|
|
68
|
-
componentsSchemas,
|
|
69
|
-
new Set(renameMap.values()),
|
|
70
|
-
defName,
|
|
71
|
-
this.customComponentName?.(defName, cleanSchema) ?? defName,
|
|
72
|
-
defs,
|
|
73
|
-
direction
|
|
74
|
-
);
|
|
75
|
-
renameMap.set(defName, componentName);
|
|
76
|
-
if (!reuseExisting) {
|
|
77
|
-
pendingSchemas.push({ cleanSchema, componentName });
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
for (const { cleanSchema, componentName } of pendingSchemas) {
|
|
81
|
-
setOwn(componentsSchemas, componentName, rewriteComponentSchemaRefs(cleanSchema, renameMap));
|
|
82
|
-
}
|
|
83
|
-
return rewriteComponentSchemaRefs(rest, renameMap);
|
|
84
|
-
}
|
|
85
|
-
toOpenAPISchema(schema, direction) {
|
|
86
|
-
return ensureJsonSchemaObject(this.hoistDefs(schema, direction));
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
function resolveComponentName(componentsSchemas, claimedNames, defName, preferredName, defs, direction) {
|
|
90
|
-
let mintName;
|
|
91
|
-
for (let i = 1; ; i++) {
|
|
92
|
-
const [componentName, mintable, tail] = componentNameCandidate(preferredName, direction, i);
|
|
93
|
-
const existingSchema = getOwn(componentsSchemas, componentName);
|
|
94
|
-
if (existingSchema === void 0) {
|
|
95
|
-
if (mintable && !claimedNames.has(componentName)) {
|
|
96
|
-
mintName ??= componentName;
|
|
97
|
-
if (tail) {
|
|
98
|
-
return [mintName, false];
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
continue;
|
|
102
|
-
}
|
|
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() }
|
|
107
|
-
)) {
|
|
108
|
-
return [componentName, true];
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
function componentNameCandidate(preferredName, direction, attempt) {
|
|
113
|
-
if (attempt === 1) {
|
|
114
|
-
return [preferredName, true, false];
|
|
115
|
-
}
|
|
116
|
-
if (direction !== void 0) {
|
|
117
|
-
if (attempt === 2) {
|
|
118
|
-
return [`${preferredName}${direction === "input" ? "Input" : "Output"}`, true, false];
|
|
119
|
-
}
|
|
120
|
-
if (attempt === 3) {
|
|
121
|
-
return [`${preferredName}${direction === "input" ? "Output" : "Input"}`, false, false];
|
|
122
|
-
}
|
|
123
|
-
return [`${preferredName}${attempt - 2}`, true, true];
|
|
124
|
-
}
|
|
125
|
-
return [`${preferredName}${attempt}`, true, true];
|
|
126
|
-
}
|
|
127
|
-
function definedKeysOf(object) {
|
|
128
|
-
return Object.keys(object).filter((key) => object[key] !== void 0).sort();
|
|
129
|
-
}
|
|
130
|
-
function isSchemaContainer(value) {
|
|
131
|
-
return Array.isArray(value) || isPlainObject(value);
|
|
132
|
-
}
|
|
133
|
-
function areSchemasEquivalentForReuse(candidate, existing, ctx) {
|
|
134
|
-
if (candidate === existing) {
|
|
135
|
-
return true;
|
|
136
|
-
}
|
|
137
|
-
if (!isSchemaContainer(candidate) || !isSchemaContainer(existing)) {
|
|
138
|
-
return isDeepEqual(candidate, existing);
|
|
139
|
-
}
|
|
140
|
-
const seenExisting = ctx.visited.get(candidate);
|
|
141
|
-
if (seenExisting?.has(existing)) {
|
|
142
|
-
return true;
|
|
143
|
-
}
|
|
144
|
-
if (seenExisting) {
|
|
145
|
-
seenExisting.add(existing);
|
|
146
|
-
} else {
|
|
147
|
-
ctx.visited.set(candidate, new WeakSet([existing]));
|
|
148
|
-
}
|
|
149
|
-
if (Array.isArray(candidate) || Array.isArray(existing)) {
|
|
150
|
-
if (!Array.isArray(candidate) || !Array.isArray(existing) || candidate.length !== existing.length) {
|
|
151
|
-
return false;
|
|
152
|
-
}
|
|
153
|
-
return candidate.every((item, index) => areSchemasEquivalentForReuse(item, existing[index], ctx));
|
|
154
|
-
}
|
|
155
|
-
const candidateObject = candidate;
|
|
156
|
-
const existingObject = existing;
|
|
157
|
-
const candidateKeys = definedKeysOf(candidateObject);
|
|
158
|
-
const existingKeys = definedKeysOf(existingObject);
|
|
159
|
-
if (!isDeepEqual(candidateKeys, existingKeys)) {
|
|
160
|
-
return false;
|
|
161
|
-
}
|
|
162
|
-
return candidateKeys.every((key) => {
|
|
163
|
-
const candidateValue = candidateObject[key];
|
|
164
|
-
const existingValue = existingObject[key];
|
|
165
|
-
if (key === "$ref" && typeof candidateValue === "string" && typeof existingValue === "string") {
|
|
166
|
-
return areSchemaRefsEquivalentForReuse(candidateValue, existingValue, ctx);
|
|
167
|
-
}
|
|
168
|
-
return areSchemasEquivalentForReuse(candidateValue, existingValue, ctx);
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
function parseRefName(ref, prefix) {
|
|
172
|
-
if (!ref.startsWith(prefix)) {
|
|
173
|
-
return void 0;
|
|
174
|
-
}
|
|
175
|
-
return ref.slice(prefix.length).split("/").map(decodeJsonPointerSegment).join("/");
|
|
176
|
-
}
|
|
177
|
-
function resolveNamedRef(ref, prefix, getNamed) {
|
|
178
|
-
const name = parseRefName(ref, prefix);
|
|
179
|
-
if (name === void 0) {
|
|
180
|
-
return void 0;
|
|
181
|
-
}
|
|
182
|
-
const schema = getNamed(name);
|
|
183
|
-
return schema === void 0 ? void 0 : { key: prefix + name, schema };
|
|
184
|
-
}
|
|
185
|
-
function areSchemaRefsEquivalentForReuse(candidateRef, existingRef, ctx) {
|
|
186
|
-
const getComponent = (name) => getOwn(ctx.componentsSchemas, name);
|
|
187
|
-
const candidate = resolveNamedRef(candidateRef, DEFS_REF_PREFIX, (name) => ctx.defs.get(name)) ?? resolveNamedRef(candidateRef, COMPONENTS_REF_PREFIX, getComponent);
|
|
188
|
-
const existing = resolveNamedRef(existingRef, COMPONENTS_REF_PREFIX, getComponent);
|
|
189
|
-
if (candidate === void 0 || existing === void 0) {
|
|
190
|
-
return !candidate && !existing && candidateRef === existingRef;
|
|
191
|
-
}
|
|
192
|
-
const pairedExisting = ctx.candidateToExistingKeys.get(candidate.key);
|
|
193
|
-
if (pairedExisting !== existing.key) {
|
|
194
|
-
if (pairedExisting !== void 0 || ctx.pairedExistingKeys.has(existing.key)) {
|
|
195
|
-
return false;
|
|
196
|
-
}
|
|
197
|
-
ctx.candidateToExistingKeys.set(candidate.key, existing.key);
|
|
198
|
-
ctx.pairedExistingKeys.add(existing.key);
|
|
199
|
-
}
|
|
200
|
-
return areSchemasEquivalentForReuse(candidate.schema, existing.schema, ctx);
|
|
201
|
-
}
|
|
202
|
-
function rewriteComponentSchemaRefs(schema, renameMap) {
|
|
203
|
-
return mapJsonSchemaRefs(schema, (ref) => {
|
|
204
|
-
const refName = parseRefName(ref, DEFS_REF_PREFIX);
|
|
205
|
-
if (refName === void 0) {
|
|
206
|
-
return ref;
|
|
207
|
-
}
|
|
208
|
-
const renamedName = renameMap.get(refName);
|
|
209
|
-
if (renamedName === void 0) {
|
|
210
|
-
return ref;
|
|
211
|
-
}
|
|
212
|
-
return COMPONENTS_REF_PREFIX + encodeJsonPointerSegment(renamedName);
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
class OpenAPIGeneratorError extends TypeError {
|
|
217
|
-
}
|
|
218
|
-
function toOpenAPIPath(path, dynamicPathParams) {
|
|
219
|
-
if (!dynamicPathParams?.length) {
|
|
220
|
-
return path;
|
|
221
|
-
}
|
|
222
|
-
let normalized = "";
|
|
223
|
-
let currentIndex = 0;
|
|
224
|
-
for (const param of dynamicPathParams) {
|
|
225
|
-
normalized += path.slice(currentIndex, param.startIndex);
|
|
226
|
-
normalized += `{${param.parameterName}}`;
|
|
227
|
-
currentIndex = param.startIndex + param.segment.length;
|
|
228
|
-
}
|
|
229
|
-
normalized += path.slice(currentIndex);
|
|
230
|
-
return normalized;
|
|
231
|
-
}
|
|
232
|
-
function buildRequest(ctx, operation, def, meta, dynamicPathParams) {
|
|
233
|
-
const method = meta?.method ?? DEFAULT_OPENAPI_METHOD;
|
|
234
|
-
const inputStructure = meta?.inputStructure ?? DEFAULT_OPENAPI_INPUT_STRUCTURE;
|
|
235
|
-
if (inputStructure === "compact") {
|
|
236
|
-
const iteratorDetails = getAsyncIteratorObjectSchemasDetails(def.inputSchemas);
|
|
237
|
-
if (iteratorDetails) {
|
|
238
|
-
operation.requestBody = {
|
|
239
|
-
required: true,
|
|
240
|
-
content: toAsyncIteratorObjectContent(
|
|
241
|
-
ctx,
|
|
242
|
-
"input",
|
|
243
|
-
ctx.convertSchemas(iteratorDetails.yieldSchemas, "input"),
|
|
244
|
-
ctx.convertSchemas(iteratorDetails.returnSchemas, "input")
|
|
245
|
-
)
|
|
246
|
-
};
|
|
247
|
-
return;
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
const dynamicParams = dynamicPathParams?.map((v) => v.parameterName);
|
|
251
|
-
const [schema, optional] = ctx.convertSchemas(def.inputSchemas, "input");
|
|
252
|
-
if (isUnconstrainedSchema(schema) && !dynamicParams?.length) {
|
|
253
|
-
return;
|
|
254
|
-
}
|
|
255
|
-
const parts = inputStructure === "compact" ? extractCompactRequestParts(schema, optional, method, dynamicParams) : extractDetailedRequestParts(schema);
|
|
256
|
-
renderPathParameters(ctx, operation, dynamicParams, parts.paramsEntries, meta?.paramsStyles);
|
|
257
|
-
renderQueryParameters(ctx, operation, parts.queryEntries, meta?.queryStyles);
|
|
258
|
-
renderHeaderParameters(ctx, operation, parts.headersEntries);
|
|
259
|
-
if (parts.bodySchema !== void 0) {
|
|
260
|
-
operation.requestBody = {
|
|
261
|
-
required: parts.bodyOptional ? void 0 : true,
|
|
262
|
-
content: toBodyContent(ctx, "input", parts.bodySchema)
|
|
263
|
-
};
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
function extractCompactRequestParts(schema, optional, method, dynamicParams) {
|
|
267
|
-
const entries = extractJsonObjectSchemaEntries(schema);
|
|
268
|
-
if (!entries && isBodylessMethod(method)) {
|
|
269
|
-
throw new OpenAPIGeneratorError(
|
|
270
|
-
`method is ${method} but the input schema is not an object.
|
|
271
|
-
${method} sends every input field as a query parameter, so the input must be an object schema.
|
|
272
|
-
Fix: make the input an object, or use a method with a request body (POST, PUT, PATCH, DELETE).`
|
|
273
|
-
);
|
|
274
|
-
}
|
|
275
|
-
const paramsEntries = entries?.filter(([name]) => dynamicParams?.includes(name));
|
|
276
|
-
const restEntries = entries?.filter(([name]) => !dynamicParams?.includes(name));
|
|
277
|
-
const hasBody = !isBodylessMethod(method);
|
|
278
|
-
const bodySchema = !hasBody ? void 0 : !dynamicParams?.length ? schema : restEntries ? combineJsonObjectSchemaEntries(restEntries) : void 0;
|
|
279
|
-
return {
|
|
280
|
-
paramsEntries,
|
|
281
|
-
queryEntries: isBodylessMethod(method) ? restEntries : void 0,
|
|
282
|
-
headersEntries: void 0,
|
|
283
|
-
bodySchema,
|
|
284
|
-
bodyOptional: !dynamicParams?.length ? optional : restEntries?.every(([, , optional2]) => optional2)
|
|
285
|
-
};
|
|
286
|
-
}
|
|
287
|
-
function extractDetailedRequestParts(schema) {
|
|
288
|
-
const entries = extractJsonObjectSchemaEntries(schema);
|
|
289
|
-
if (!entries) {
|
|
290
|
-
throw new OpenAPIGeneratorError(
|
|
291
|
-
`inputStructure is "detailed" but the input schema is not an object.
|
|
292
|
-
Expected an object shaped like: { params?: object, query?: object, headers?: object, body?: unknown }`
|
|
293
|
-
);
|
|
294
|
-
}
|
|
295
|
-
const section = (name) => entries.find(([entryName]) => entryName === name);
|
|
296
|
-
return {
|
|
297
|
-
paramsEntries: extractJsonObjectSchemaEntries(section("params")?.[1] ?? false),
|
|
298
|
-
queryEntries: extractJsonObjectSchemaEntries(section("query")?.[1] ?? false),
|
|
299
|
-
headersEntries: extractJsonObjectSchemaEntries(section("headers")?.[1] ?? false),
|
|
300
|
-
bodySchema: section("body")?.[1],
|
|
301
|
-
bodyOptional: section("body")?.[2]
|
|
302
|
-
};
|
|
303
|
-
}
|
|
304
|
-
function renderPathParameters(ctx, operation, dynamicParams, paramsEntries, paramsStyles) {
|
|
305
|
-
if (!dynamicParams?.length) {
|
|
306
|
-
return;
|
|
307
|
-
}
|
|
308
|
-
if (!paramsEntries) {
|
|
309
|
-
throw new OpenAPIGeneratorError(
|
|
310
|
-
`the route declares path params (${dynamicParams.map((p) => `{${p}}`).join(", ")}) but there is no object schema to source them from.
|
|
311
|
-
compact mode: the input schema must be an object containing each param.
|
|
312
|
-
detailed mode: the input's "params" section must be an object containing each param.`
|
|
313
|
-
);
|
|
314
|
-
}
|
|
315
|
-
for (const name of dynamicParams) {
|
|
316
|
-
const entry = paramsEntries.find(([entryName]) => entryName === name);
|
|
317
|
-
if (!entry) {
|
|
318
|
-
throw new OpenAPIGeneratorError(
|
|
319
|
-
`dynamic param "{${name}}" is missing from the input schema.
|
|
320
|
-
Route params: ${dynamicParams.map((p) => `{${p}}`).join(", ")}
|
|
321
|
-
Schema keys: ${paramsEntries.map(([n]) => n).join(", ") || "(none)"}`
|
|
322
|
-
);
|
|
323
|
-
}
|
|
324
|
-
if (entry[2]) {
|
|
325
|
-
throw new OpenAPIGeneratorError(
|
|
326
|
-
`dynamic param "${name}" is optional in the input schema.
|
|
327
|
-
OpenAPI requires path params to be required. Make "${name}" required.`
|
|
328
|
-
);
|
|
329
|
-
}
|
|
330
|
-
const style = paramsStyles?.[name];
|
|
331
|
-
const parameter = {
|
|
332
|
-
in: "path",
|
|
333
|
-
required: true,
|
|
334
|
-
name,
|
|
335
|
-
schema: ctx.registry.toOpenAPISchema(entry[1], "input")
|
|
336
|
-
};
|
|
337
|
-
if (style === "comma-delimited-array" || style === "comma-delimited-object") {
|
|
338
|
-
parameter.style = "simple";
|
|
339
|
-
parameter.explode = false;
|
|
340
|
-
}
|
|
341
|
-
operation.parameters ??= [];
|
|
342
|
-
operation.parameters.push(parameter);
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
function renderQueryParameters(ctx, operation, queryEntries, queryStyles) {
|
|
346
|
-
for (const [name, schema, optional] of queryEntries ?? []) {
|
|
347
|
-
const style = queryStyles?.[name];
|
|
348
|
-
const parameter = {
|
|
349
|
-
in: "query",
|
|
350
|
-
name,
|
|
351
|
-
schema: ctx.registry.toOpenAPISchema(schema, "input"),
|
|
352
|
-
allowEmptyValue: true,
|
|
353
|
-
allowReserved: true
|
|
354
|
-
};
|
|
355
|
-
if (!optional) {
|
|
356
|
-
parameter.required = true;
|
|
357
|
-
}
|
|
358
|
-
if (style === "comma-delimited-array" || style === "comma-delimited-object") {
|
|
359
|
-
parameter.explode = false;
|
|
360
|
-
} else if (style === "pipe-delimited-array" || style === "pipe-delimited-object") {
|
|
361
|
-
parameter.style = "pipeDelimited";
|
|
362
|
-
} else if (style === "space-delimited-array" || style === "space-delimited-object") {
|
|
363
|
-
parameter.style = "spaceDelimited";
|
|
364
|
-
} else if (style === "json") {
|
|
365
|
-
parameter.content = {
|
|
366
|
-
"application/json": { schema: parameter.schema }
|
|
367
|
-
};
|
|
368
|
-
delete parameter.schema;
|
|
369
|
-
} else if (style === void 0) {
|
|
370
|
-
if (flattenJsonUnionSchema(schema).some((s) => !isJsonPrimitiveSchema(s))) {
|
|
371
|
-
const arrayable = matchArrayableJsonSchema(schema);
|
|
372
|
-
if (!arrayable || flattenJsonUnionSchema(arrayable[0]).some((s) => !isJsonPrimitiveSchema(s))) {
|
|
373
|
-
parameter.style = "deepObject";
|
|
374
|
-
parameter.explode = true;
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
} else ;
|
|
378
|
-
operation.parameters ??= [];
|
|
379
|
-
operation.parameters.push(parameter);
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
function renderHeaderParameters(ctx, operation, headersEntries) {
|
|
383
|
-
for (const [name, schema, optional] of headersEntries ?? []) {
|
|
384
|
-
operation.parameters ??= [];
|
|
385
|
-
operation.parameters.push({
|
|
386
|
-
in: "header",
|
|
387
|
-
name,
|
|
388
|
-
required: optional ? void 0 : true,
|
|
389
|
-
schema: ctx.registry.toOpenAPISchema(schema, "input")
|
|
390
|
-
});
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
function buildSuccessResponse(ctx, operation, def, meta) {
|
|
394
|
-
const status = meta?.successStatus ?? DEFAULT_SUCCESS_STATUS;
|
|
395
|
-
const description = meta?.successDescription ?? DEFAULT_OPENAPI_SUCCESS_DESCRIPTION;
|
|
396
|
-
const outputStructure = meta?.outputStructure ?? DEFAULT_OPENAPI_OUTPUT_STRUCTURE;
|
|
397
|
-
if (outputStructure === "compact") {
|
|
398
|
-
const iteratorDetails = getAsyncIteratorObjectSchemasDetails(def.outputSchemas);
|
|
399
|
-
if (iteratorDetails) {
|
|
400
|
-
operation.responses ??= {};
|
|
401
|
-
operation.responses[toResponseStatusKey(status)] = {
|
|
402
|
-
description,
|
|
403
|
-
content: toAsyncIteratorObjectContent(
|
|
404
|
-
ctx,
|
|
405
|
-
"output",
|
|
406
|
-
ctx.convertSchemas(iteratorDetails.yieldSchemas, "output"),
|
|
407
|
-
ctx.convertSchemas(iteratorDetails.returnSchemas, "output")
|
|
408
|
-
)
|
|
409
|
-
};
|
|
410
|
-
return;
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
const [schema] = ctx.convertSchemas(def.outputSchemas, "output");
|
|
414
|
-
if (isUnconstrainedSchema(schema) || outputStructure === "compact") {
|
|
415
|
-
operation.responses ??= {};
|
|
416
|
-
operation.responses[toResponseStatusKey(status)] = {
|
|
417
|
-
description,
|
|
418
|
-
content: toBodyContent(ctx, "output", schema)
|
|
419
|
-
};
|
|
420
|
-
return;
|
|
421
|
-
}
|
|
422
|
-
for (const [responseStatus, parts] of extractDetailedResponseParts(schema, status)) {
|
|
423
|
-
const responseObject = {
|
|
424
|
-
description: parts.descriptions.length ? parts.descriptions.join(", ") : description
|
|
425
|
-
};
|
|
426
|
-
if (parts.bodies.length) {
|
|
427
|
-
responseObject.content = toBodyContent(ctx, "output", combineJsonSchemasWithComposition("anyOf", parts.bodies));
|
|
428
|
-
}
|
|
429
|
-
if (parts.headers.length) {
|
|
430
|
-
const entries = extractJsonObjectSchemaEntries(combineJsonSchemasWithComposition("anyOf", parts.headers));
|
|
431
|
-
entries?.forEach(([name, schema2, optional]) => {
|
|
432
|
-
responseObject.headers ??= {};
|
|
433
|
-
responseObject.headers[name] = {
|
|
434
|
-
required: optional ? void 0 : true,
|
|
435
|
-
schema: ctx.registry.toOpenAPISchema(schema2, "output")
|
|
436
|
-
};
|
|
437
|
-
});
|
|
438
|
-
}
|
|
439
|
-
operation.responses ??= {};
|
|
440
|
-
operation.responses[toResponseStatusKey(responseStatus)] = responseObject;
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
function toResponseStatusKey(status) {
|
|
444
|
-
return String(status);
|
|
445
|
-
}
|
|
446
|
-
function extractDetailedResponseParts(schema, defaultStatus) {
|
|
447
|
-
const partsByStatus = /* @__PURE__ */ new Map();
|
|
448
|
-
for (const item of flattenJsonUnionSchema(schema)) {
|
|
449
|
-
const entries = extractJsonObjectSchemaEntries(item);
|
|
450
|
-
if (!entries) {
|
|
451
|
-
throw new OpenAPIGeneratorError(
|
|
452
|
-
`outputStructure is "detailed" but the output schema (or one of its union members) is not an object.
|
|
453
|
-
Expected each member shaped like: { status?: number (< 400), headers?: object, body?: unknown }`
|
|
454
|
-
);
|
|
455
|
-
}
|
|
456
|
-
const statusSchema = entries.find(([name]) => name === "status")?.[1];
|
|
457
|
-
const statuses = statusSchema === void 0 ? /* @__PURE__ */ new Map([[defaultStatus, void 0]]) : extractDetailedStatuses(statusSchema);
|
|
458
|
-
if (!statuses) {
|
|
459
|
-
throw new OpenAPIGeneratorError(
|
|
460
|
-
`invalid "status" field in the detailed output schema.
|
|
461
|
-
Expected: literal integers below 400 (const, enum, or a union of them)
|
|
462
|
-
Received: ${stringifyJSON(statusSchema)}`
|
|
463
|
-
);
|
|
464
|
-
}
|
|
465
|
-
const headersSchema = entries.find(([name]) => name === "headers")?.[1];
|
|
466
|
-
const bodySchema = entries.find(([name]) => name === "body")?.[1];
|
|
467
|
-
for (const [status, description] of statuses) {
|
|
468
|
-
let parts = partsByStatus.get(status);
|
|
469
|
-
if (!parts) {
|
|
470
|
-
parts = { descriptions: [], bodies: [], headers: [] };
|
|
471
|
-
partsByStatus.set(status, parts);
|
|
472
|
-
}
|
|
473
|
-
if (description !== void 0) {
|
|
474
|
-
parts.descriptions.push(description);
|
|
475
|
-
}
|
|
476
|
-
if (headersSchema !== void 0) {
|
|
477
|
-
parts.headers.push(headersSchema);
|
|
478
|
-
}
|
|
479
|
-
if (bodySchema !== void 0) {
|
|
480
|
-
parts.bodies.push(bodySchema);
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
return partsByStatus;
|
|
485
|
-
}
|
|
486
|
-
function extractDetailedStatuses(schema) {
|
|
487
|
-
const statuses = /* @__PURE__ */ new Map();
|
|
488
|
-
for (const member of flattenJsonUnionSchema(schema)) {
|
|
489
|
-
if (typeof member !== "object") {
|
|
490
|
-
return void 0;
|
|
491
|
-
}
|
|
492
|
-
const values = member.const !== void 0 ? [member.const] : member.enum;
|
|
493
|
-
if (!values?.length) {
|
|
494
|
-
return void 0;
|
|
495
|
-
}
|
|
496
|
-
for (const value2 of values) {
|
|
497
|
-
if (!Number.isInteger(value2) || value2 >= 400) {
|
|
498
|
-
return void 0;
|
|
499
|
-
}
|
|
500
|
-
if (!statuses.has(value2)) {
|
|
501
|
-
statuses.set(value2, member.description);
|
|
502
|
-
}
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
return statuses.size ? statuses : void 0;
|
|
506
|
-
}
|
|
507
|
-
function buildErrorResponse(ctx, operation, def) {
|
|
508
|
-
const definitionsByStatus = /* @__PURE__ */ new Map();
|
|
509
|
-
for (const code of Object.keys(def.errorMap)) {
|
|
510
|
-
const config = def.errorMap[code];
|
|
511
|
-
if (!config) {
|
|
512
|
-
continue;
|
|
513
|
-
}
|
|
514
|
-
const status = ctx.errorStatusMap[code] ?? DEFAULT_ERROR_STATUS;
|
|
515
|
-
const [dataJsonSchema, dataOptional] = ctx.convertSchemas(config.data !== void 0 ? [config.data] : void 0, "output");
|
|
516
|
-
let definitions = definitionsByStatus.get(status);
|
|
517
|
-
if (!definitions) {
|
|
518
|
-
definitions = [];
|
|
519
|
-
definitionsByStatus.set(status, definitions);
|
|
520
|
-
}
|
|
521
|
-
definitions.push({ code, dataJsonSchema, dataOptional, defaultMessage: config.message });
|
|
522
|
-
}
|
|
523
|
-
if (!definitionsByStatus.size) {
|
|
524
|
-
return;
|
|
525
|
-
}
|
|
526
|
-
const undefinedErrorSchema = ctx.registry.register("UndefinedError", {
|
|
527
|
-
title: "UndefinedError",
|
|
528
|
-
type: "object",
|
|
529
|
-
properties: {
|
|
530
|
-
defined: { const: false },
|
|
531
|
-
code: { type: "string" },
|
|
532
|
-
message: { type: "string" },
|
|
533
|
-
data: {}
|
|
534
|
-
},
|
|
535
|
-
required: ["defined", "code", "message"]
|
|
536
|
-
});
|
|
537
|
-
for (const [status, definitions] of definitionsByStatus.entries()) {
|
|
538
|
-
const descriptions = definitions.map(({ defaultMessage }) => defaultMessage).filter((m) => m !== void 0);
|
|
539
|
-
const customBodySchema = value(
|
|
540
|
-
ctx.customErrorResponseBodySchema,
|
|
541
|
-
definitions.map((def2) => ({ ...def2, dataJsonSchema: ctx.registry.hoistDefs(def2.dataJsonSchema, "output") })),
|
|
542
|
-
status
|
|
543
|
-
);
|
|
544
|
-
const responseSchema = customBodySchema ?? combineJsonSchemasWithComposition("oneOf", [
|
|
545
|
-
...definitions.map(({ code, dataJsonSchema, dataOptional }) => {
|
|
546
|
-
return ctx.registry.register(toErrorComponentName(code), {
|
|
547
|
-
title: code,
|
|
548
|
-
...combineJsonObjectSchemaEntries([
|
|
549
|
-
["defined", { const: true }, false],
|
|
550
|
-
["code", { const: code }, false],
|
|
551
|
-
// avoid using the defaultMessage here to improve component reusability
|
|
552
|
-
["message", { type: "string" }, false],
|
|
553
|
-
["data", ctx.registry.hoistDefs(dataJsonSchema, "output"), dataOptional]
|
|
554
|
-
])
|
|
555
|
-
});
|
|
556
|
-
}),
|
|
557
|
-
undefinedErrorSchema
|
|
558
|
-
]);
|
|
559
|
-
operation.responses ??= {};
|
|
560
|
-
operation.responses[toResponseStatusKey(status)] = {
|
|
561
|
-
description: descriptions.length ? descriptions.join(", ") : status.toString(),
|
|
562
|
-
content: {
|
|
563
|
-
"application/json": {
|
|
564
|
-
schema: ctx.registry.toOpenAPISchema(responseSchema, "output")
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
};
|
|
568
|
-
}
|
|
569
|
-
}
|
|
570
|
-
function toErrorComponentName(code) {
|
|
571
|
-
const name = code.split(/[^a-z0-9]+/i).filter(Boolean).map((part) => {
|
|
572
|
-
const rest = part.slice(1);
|
|
573
|
-
return part.charAt(0).toUpperCase() + (rest === rest.toUpperCase() ? rest.toLowerCase() : rest);
|
|
574
|
-
}).join("");
|
|
575
|
-
return name || "Error";
|
|
576
|
-
}
|
|
577
|
-
function toAsyncIteratorObjectContent(ctx, direction, [yieldSchema, yieldOptional], [returnSchema, returnOptional]) {
|
|
578
|
-
const schema = combineJsonSchemasWithComposition("oneOf", [
|
|
579
|
-
combineJsonObjectSchemaEntries([
|
|
580
|
-
["event", { const: "message" }, false],
|
|
581
|
-
["data", yieldSchema, yieldOptional],
|
|
582
|
-
["id", { type: "string" }, true],
|
|
583
|
-
["retry", { type: "number" }, true]
|
|
584
|
-
]),
|
|
585
|
-
combineJsonObjectSchemaEntries([
|
|
586
|
-
["event", { const: "close" }, false],
|
|
587
|
-
["data", returnSchema, returnOptional],
|
|
588
|
-
["id", { type: "string" }, true],
|
|
589
|
-
["retry", { type: "number" }, true]
|
|
590
|
-
]),
|
|
591
|
-
{
|
|
592
|
-
type: "object",
|
|
593
|
-
properties: {
|
|
594
|
-
event: { const: "error" },
|
|
595
|
-
data: {},
|
|
596
|
-
id: { type: "string" },
|
|
597
|
-
retry: { type: "number" }
|
|
598
|
-
},
|
|
599
|
-
required: ["event"]
|
|
600
|
-
}
|
|
601
|
-
]);
|
|
602
|
-
return {
|
|
603
|
-
"text/event-stream": {
|
|
604
|
-
schema: ctx.registry.toOpenAPISchema(schema, direction)
|
|
605
|
-
}
|
|
606
|
-
};
|
|
607
|
-
}
|
|
608
|
-
function toBodyContent(ctx, direction, schema) {
|
|
609
|
-
const fileSchemasByMediaType = /* @__PURE__ */ new Map();
|
|
610
|
-
const rest = flattenJsonUnionSchema(schema).filter((s) => {
|
|
611
|
-
if (!isJsonFileSchema(s)) {
|
|
612
|
-
return !isUnconstrainedSchema(s);
|
|
613
|
-
}
|
|
614
|
-
const contentMediaType = s.contentMediaType ?? "*/*";
|
|
615
|
-
const schemas = fileSchemasByMediaType.get(contentMediaType);
|
|
616
|
-
if (schemas) {
|
|
617
|
-
schemas.push(s);
|
|
618
|
-
} else {
|
|
619
|
-
fileSchemasByMediaType.set(contentMediaType, [s]);
|
|
620
|
-
}
|
|
621
|
-
return false;
|
|
622
|
-
});
|
|
623
|
-
const content = {};
|
|
624
|
-
if (rest.length > 0) {
|
|
625
|
-
const restSchema = fileSchemasByMediaType.size ? combineJsonSchemasWithComposition("anyOf", rest) : schema;
|
|
626
|
-
const hasNestedFiles = containsJsonFileSchema(restSchema);
|
|
627
|
-
const contentType = hasNestedFiles ? "multipart/form-data" : "application/json";
|
|
628
|
-
const fileSchemas = fileSchemasByMediaType.get(contentType);
|
|
629
|
-
fileSchemasByMediaType.delete(contentType);
|
|
630
|
-
content[contentType] = {
|
|
631
|
-
schema: ctx.registry.toOpenAPISchema(combineJsonSchemasWithComposition("anyOf", [restSchema, ...fileSchemas ?? []]), direction)
|
|
632
|
-
};
|
|
633
|
-
}
|
|
634
|
-
for (const [contentType, schemas] of fileSchemasByMediaType.entries()) {
|
|
635
|
-
content[contentType] = {
|
|
636
|
-
schema: ctx.registry.toOpenAPISchema(combineJsonSchemasWithComposition("anyOf", schemas), direction)
|
|
637
|
-
};
|
|
638
|
-
}
|
|
639
|
-
return content;
|
|
640
|
-
}
|
|
641
|
-
|
|
642
|
-
class OpenAPIGenerator {
|
|
643
|
-
serializer;
|
|
644
|
-
converter;
|
|
645
|
-
constructor(options = {}) {
|
|
646
|
-
this.serializer = options.serializer ?? new OpenAPIJsonSerializer();
|
|
647
|
-
this.converter = new DelegatingJsonSchemaConverter([
|
|
648
|
-
...toArray(options.converters),
|
|
649
|
-
new StandardJsonSchemaConverter()
|
|
650
|
-
]);
|
|
651
|
-
}
|
|
652
|
-
async generate(router, options = {}) {
|
|
653
|
-
const version = options.version ?? "3.2.0";
|
|
654
|
-
const doc = {
|
|
655
|
-
...clone(options.base),
|
|
656
|
-
openapi: "3.2.0",
|
|
657
|
-
info: options.base?.info ?? { title: "API Reference", version: "0.0.0" }
|
|
658
|
-
};
|
|
659
|
-
const ctx = {
|
|
660
|
-
registry: new OpenAPIComponentRegistry(doc, options.customComponentName),
|
|
661
|
-
convertSchemas: (schemas, direction) => this.convertSchemas(schemas, direction),
|
|
662
|
-
errorStatusMap: options.errorStatusMap ?? COMMON_ERROR_STATUS_MAP,
|
|
663
|
-
customErrorResponseBodySchema: options.customErrorResponseBodySchema
|
|
664
|
-
};
|
|
665
|
-
const errors = [];
|
|
666
|
-
await walkProcedureContractsAsync(router, (contract, path) => {
|
|
667
|
-
if (value(options.filter, contract, path) === false) {
|
|
668
|
-
return;
|
|
669
|
-
}
|
|
670
|
-
try {
|
|
671
|
-
const def = contract["~orpc"];
|
|
672
|
-
const meta = getOpenAPIMeta(contract);
|
|
673
|
-
const method = (meta?.method ?? DEFAULT_OPENAPI_METHOD).toLowerCase();
|
|
674
|
-
if (method === "query" && !version.startsWith("3.2.")) {
|
|
675
|
-
throw new OpenAPIGeneratorError(
|
|
676
|
-
`QUERY operations require OpenAPI 3.2, but version "${version}" was requested.`
|
|
677
|
-
);
|
|
678
|
-
}
|
|
679
|
-
const postPath = meta?.path ?? pathToHttpPath(path);
|
|
680
|
-
const httpPath = meta?.prefix ? mergeHttpPath(meta.prefix, postPath) : postPath;
|
|
681
|
-
const dynamicPathParams = getDynamicPathParams(httpPath);
|
|
682
|
-
const openApiPath = toOpenAPIPath(httpPath, dynamicPathParams);
|
|
683
|
-
let operation;
|
|
684
|
-
if (meta?.spec !== void 0 && typeof meta.spec !== "function") {
|
|
685
|
-
operation = meta.spec;
|
|
686
|
-
} else {
|
|
687
|
-
operation = {
|
|
688
|
-
operationId: meta?.operationId ?? path.join("."),
|
|
689
|
-
summary: meta?.summary,
|
|
690
|
-
description: meta?.description,
|
|
691
|
-
deprecated: meta?.deprecated,
|
|
692
|
-
tags: meta?.tags?.map((tag) => tag)
|
|
693
|
-
};
|
|
694
|
-
buildRequest(ctx, operation, def, meta, dynamicPathParams);
|
|
695
|
-
buildSuccessResponse(ctx, operation, def, meta);
|
|
696
|
-
buildErrorResponse(ctx, operation, def);
|
|
697
|
-
}
|
|
698
|
-
if (typeof meta?.spec === "function") {
|
|
699
|
-
operation = meta.spec(operation);
|
|
700
|
-
}
|
|
701
|
-
doc.paths ??= {};
|
|
702
|
-
doc.paths[openApiPath] ??= {};
|
|
703
|
-
doc.paths[openApiPath][method] = operation;
|
|
704
|
-
} catch (e) {
|
|
705
|
-
if (!(e instanceof OpenAPIGeneratorError)) {
|
|
706
|
-
throw e;
|
|
707
|
-
}
|
|
708
|
-
errors.push(`Procedure at ${path.join(".") || "(root)"}: ${e.message}`);
|
|
709
|
-
}
|
|
710
|
-
});
|
|
711
|
-
if (errors.length) {
|
|
712
|
-
throw new OpenAPIGeneratorError(
|
|
713
|
-
`[OpenAPIGenerator] Failed to generate the OpenAPI document (${errors.length} error${errors.length === 1 ? "" : "s"}):
|
|
714
|
-
|
|
715
|
-
${errors.join("\n\n")}`
|
|
716
|
-
);
|
|
717
|
-
}
|
|
718
|
-
const versioned = toVersionedOpenAPIDocument(doc, version);
|
|
719
|
-
return this.serializer.serializeJson(versioned).json;
|
|
720
|
-
}
|
|
721
|
-
convertSchema(schema, direction) {
|
|
722
|
-
const [jsonSchema, optional] = this.converter.convert(schema, direction);
|
|
723
|
-
return [hoistRecursiveRefToDef(strip$schemaField(jsonSchema)), optional];
|
|
724
|
-
}
|
|
725
|
-
convertSchemas(schemas, direction) {
|
|
726
|
-
if (!schemas || schemas.length <= 1) {
|
|
727
|
-
return this.convertSchema(schemas?.[0], direction);
|
|
728
|
-
}
|
|
729
|
-
const results = schemas.map((s) => this.convertSchema(s, direction));
|
|
730
|
-
return [
|
|
731
|
-
combineJsonSchemasWithComposition("allOf", results.map(([jsonSchema]) => jsonSchema)),
|
|
732
|
-
results.every(([, optional]) => optional)
|
|
733
|
-
];
|
|
734
|
-
}
|
|
735
|
-
}
|
|
736
|
-
function toVersionedOpenAPIDocument(doc, version) {
|
|
737
|
-
const downgraded = version.startsWith("3.2.") ? doc : version.startsWith("3.1.") ? downgradeSpecV32ToV31(doc) : downgradeSpecV31ToV30(downgradeSpecV32ToV31(doc));
|
|
738
|
-
return { ...downgraded, openapi: version };
|
|
739
|
-
}
|
|
740
|
-
function strip$schemaField(schema) {
|
|
741
|
-
if (typeof schema !== "object") {
|
|
742
|
-
return schema;
|
|
743
|
-
}
|
|
744
|
-
const { $schema, ...rest } = schema;
|
|
745
|
-
return rest;
|
|
746
|
-
}
|
|
747
|
-
|
|
748
|
-
function populateRouterContractOpenAPIPaths(router, options = {}) {
|
|
749
|
-
const path = toArray(options.path);
|
|
750
|
-
if (router instanceof ProcedureContract) {
|
|
751
|
-
if (getOpenAPIMeta(router)?.path !== void 0) {
|
|
752
|
-
return router;
|
|
753
|
-
}
|
|
754
|
-
const [meta, metaPlugins] = resolveMetaPlugins(
|
|
755
|
-
router["~orpc"].meta,
|
|
756
|
-
router["~orpc"].metaPlugins,
|
|
757
|
-
[openapi({ path: pathToHttpPath(path) })]
|
|
758
|
-
);
|
|
759
|
-
return new ProcedureContract({
|
|
760
|
-
...router["~orpc"],
|
|
761
|
-
meta,
|
|
762
|
-
metaPlugins
|
|
763
|
-
});
|
|
764
|
-
}
|
|
765
|
-
if (!isTypescriptObject(router)) {
|
|
766
|
-
return router;
|
|
767
|
-
}
|
|
768
|
-
const populated = {};
|
|
769
|
-
for (const key of Object.keys(router)) {
|
|
770
|
-
populated[key] = populateRouterContractOpenAPIPaths(
|
|
771
|
-
router[key],
|
|
772
|
-
{ ...options, path: [...path, key] }
|
|
773
|
-
);
|
|
774
|
-
}
|
|
775
|
-
return populated;
|
|
776
|
-
}
|
|
777
|
-
|
|
778
|
-
export { DEFAULT_OPENAPI_METHOD, OpenAPIGenerator, OpenAPIGeneratorError, OpenAPIJsonSerializer, createContractJsonifiedClientFactory, getDynamicPathParams, getOpenAPIMeta, openapi, populateRouterContractOpenAPIPaths };
|
|
1
|
+
export * from "./bracket-notation.mjs";
|
|
2
|
+
export * from "./client-factory.mjs";
|
|
3
|
+
export { DEFAULT_OPENAPI_METHOD } from "./constants.mjs";
|
|
4
|
+
export * from "./meta.mjs";
|
|
5
|
+
export * from "./openapi-generator.mjs";
|
|
6
|
+
export * from "./openapi-json-serializer.mjs";
|
|
7
|
+
export * from "./openapi-serializer.mjs";
|
|
8
|
+
export * from "./router-utils.mjs";
|
|
9
|
+
export * from "./types.mjs";
|
|
10
|
+
export { getDynamicPathParams } from "./utils.mjs";
|
|
11
|
+
export { COMMON_ERROR_STATUS_MAP } from "@orpc/client";
|