@orpc/openapi 0.0.0-next.f99e554 → 0.0.0-next.fa75202
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 +101 -0
- package/dist/adapters/fetch/index.d.mts +17 -0
- package/dist/adapters/fetch/index.d.ts +17 -0
- package/dist/adapters/fetch/index.mjs +18 -0
- package/dist/adapters/node/index.d.mts +17 -0
- package/dist/adapters/node/index.d.ts +17 -0
- package/dist/adapters/node/index.mjs +18 -0
- package/dist/adapters/standard/index.d.mts +35 -0
- package/dist/adapters/standard/index.d.ts +35 -0
- package/dist/adapters/standard/index.mjs +9 -0
- package/dist/index.d.mts +105 -0
- package/dist/index.d.ts +105 -0
- package/dist/index.mjs +41 -0
- package/dist/plugins/index.d.mts +70 -0
- package/dist/plugins/index.d.ts +70 -0
- package/dist/plugins/index.mjs +108 -0
- package/dist/shared/openapi.C_UtQ8Us.mjs +179 -0
- package/dist/shared/openapi.CwdCLgSU.d.mts +53 -0
- package/dist/shared/openapi.CwdCLgSU.d.ts +53 -0
- package/dist/shared/openapi.D3j94c9n.d.mts +12 -0
- package/dist/shared/openapi.D3j94c9n.d.ts +12 -0
- package/dist/shared/openapi.PDTdnRIU.mjs +595 -0
- package/package.json +30 -30
- package/dist/chunk-KNYXLM77.js +0 -107
- package/dist/chunk-YXHH6XHB.js +0 -642
- package/dist/fetch.js +0 -46
- package/dist/index.js +0 -490
- package/dist/node.js +0 -46
- package/dist/src/adapters/fetch/bracket-notation.d.ts +0 -84
- package/dist/src/adapters/fetch/index.d.ts +0 -10
- package/dist/src/adapters/fetch/input-structure-compact.d.ts +0 -6
- package/dist/src/adapters/fetch/input-structure-detailed.d.ts +0 -11
- package/dist/src/adapters/fetch/openapi-handler-server.d.ts +0 -7
- package/dist/src/adapters/fetch/openapi-handler-serverless.d.ts +0 -7
- package/dist/src/adapters/fetch/openapi-handler.d.ts +0 -33
- package/dist/src/adapters/fetch/openapi-payload-codec.d.ts +0 -15
- package/dist/src/adapters/fetch/openapi-procedure-matcher.d.ts +0 -19
- package/dist/src/adapters/fetch/schema-coercer.d.ts +0 -10
- package/dist/src/adapters/node/index.d.ts +0 -5
- package/dist/src/adapters/node/openapi-handler-server.d.ts +0 -7
- package/dist/src/adapters/node/openapi-handler-serverless.d.ts +0 -7
- package/dist/src/adapters/node/openapi-handler.d.ts +0 -12
- package/dist/src/adapters/node/types.d.ts +0 -2
- package/dist/src/index.d.ts +0 -12
- package/dist/src/json-serializer.d.ts +0 -5
- package/dist/src/openapi-content-builder.d.ts +0 -10
- package/dist/src/openapi-error.d.ts +0 -3
- package/dist/src/openapi-generator.d.ts +0 -60
- package/dist/src/openapi-input-structure-parser.d.ts +0 -22
- package/dist/src/openapi-output-structure-parser.d.ts +0 -18
- package/dist/src/openapi-parameters-builder.d.ts +0 -12
- package/dist/src/openapi-path-parser.d.ts +0 -8
- package/dist/src/openapi.d.ts +0 -3
- package/dist/src/schema-converter.d.ts +0 -16
- package/dist/src/schema-utils.d.ts +0 -11
- package/dist/src/schema.d.ts +0 -12
- package/dist/src/utils.d.ts +0 -18
package/dist/index.js
DELETED
|
@@ -1,490 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
JSONSerializer,
|
|
3
|
-
forEachAllContractProcedure,
|
|
4
|
-
forEachContractProcedure,
|
|
5
|
-
standardizeHTTPPath
|
|
6
|
-
} from "./chunk-KNYXLM77.js";
|
|
7
|
-
|
|
8
|
-
// src/openapi.ts
|
|
9
|
-
import { OpenApiBuilder } from "openapi3-ts/oas31";
|
|
10
|
-
|
|
11
|
-
// src/openapi-content-builder.ts
|
|
12
|
-
import { findDeepMatches } from "@orpc/shared";
|
|
13
|
-
var OpenAPIContentBuilder = class {
|
|
14
|
-
constructor(schemaUtils) {
|
|
15
|
-
this.schemaUtils = schemaUtils;
|
|
16
|
-
}
|
|
17
|
-
build(jsonSchema, options) {
|
|
18
|
-
const isFileSchema = this.schemaUtils.isFileSchema.bind(this.schemaUtils);
|
|
19
|
-
const [matches, schema] = this.schemaUtils.filterSchemaBranches(jsonSchema, isFileSchema);
|
|
20
|
-
const files = matches;
|
|
21
|
-
const content = {};
|
|
22
|
-
for (const file of files) {
|
|
23
|
-
content[file.contentMediaType] = {
|
|
24
|
-
schema: file
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
const isStillHasFileSchema = findDeepMatches(isFileSchema, schema).values.length > 0;
|
|
28
|
-
if (schema !== void 0) {
|
|
29
|
-
content[isStillHasFileSchema ? "multipart/form-data" : "application/json"] = {
|
|
30
|
-
schema,
|
|
31
|
-
...options
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
return content;
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
// src/openapi-error.ts
|
|
39
|
-
var OpenAPIError = class extends Error {
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
// src/openapi-input-structure-parser.ts
|
|
43
|
-
var OpenAPIInputStructureParser = class {
|
|
44
|
-
constructor(schemaConverter, schemaUtils, pathParser) {
|
|
45
|
-
this.schemaConverter = schemaConverter;
|
|
46
|
-
this.schemaUtils = schemaUtils;
|
|
47
|
-
this.pathParser = pathParser;
|
|
48
|
-
}
|
|
49
|
-
parse(contract, structure) {
|
|
50
|
-
const inputSchema = this.schemaConverter.convert(contract["~orpc"].InputSchema, { strategy: "input" });
|
|
51
|
-
const method = contract["~orpc"].route?.method ?? "POST";
|
|
52
|
-
const httpPath = contract["~orpc"].route?.path;
|
|
53
|
-
if (this.schemaUtils.isAnySchema(inputSchema)) {
|
|
54
|
-
return {
|
|
55
|
-
paramsSchema: void 0,
|
|
56
|
-
querySchema: void 0,
|
|
57
|
-
headersSchema: void 0,
|
|
58
|
-
bodySchema: void 0
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
if (structure === "detailed") {
|
|
62
|
-
return this.parseDetailedSchema(inputSchema);
|
|
63
|
-
} else {
|
|
64
|
-
return this.parseCompactSchema(inputSchema, method, httpPath);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
parseDetailedSchema(inputSchema) {
|
|
68
|
-
if (!this.schemaUtils.isObjectSchema(inputSchema)) {
|
|
69
|
-
throw new OpenAPIError(`When input structure is 'detailed', input schema must be an object.`);
|
|
70
|
-
}
|
|
71
|
-
if (inputSchema.properties && Object.keys(inputSchema.properties).some((key) => !["params", "query", "headers", "body"].includes(key))) {
|
|
72
|
-
throw new OpenAPIError(`When input structure is 'detailed', input schema must be only can contain 'params', 'query', 'headers' and 'body' properties.`);
|
|
73
|
-
}
|
|
74
|
-
let paramsSchema = inputSchema.properties?.params;
|
|
75
|
-
let querySchema = inputSchema.properties?.query;
|
|
76
|
-
let headersSchema = inputSchema.properties?.headers;
|
|
77
|
-
const bodySchema = inputSchema.properties?.body;
|
|
78
|
-
if (paramsSchema !== void 0 && this.schemaUtils.isAnySchema(paramsSchema)) {
|
|
79
|
-
paramsSchema = void 0;
|
|
80
|
-
}
|
|
81
|
-
if (paramsSchema !== void 0 && !this.schemaUtils.isObjectSchema(paramsSchema)) {
|
|
82
|
-
throw new OpenAPIError(`When input structure is 'detailed', params schema in input schema must be an object.`);
|
|
83
|
-
}
|
|
84
|
-
if (querySchema !== void 0 && this.schemaUtils.isAnySchema(querySchema)) {
|
|
85
|
-
querySchema = void 0;
|
|
86
|
-
}
|
|
87
|
-
if (querySchema !== void 0 && !this.schemaUtils.isObjectSchema(querySchema)) {
|
|
88
|
-
throw new OpenAPIError(`When input structure is 'detailed', query schema in input schema must be an object.`);
|
|
89
|
-
}
|
|
90
|
-
if (headersSchema !== void 0 && this.schemaUtils.isAnySchema(headersSchema)) {
|
|
91
|
-
headersSchema = void 0;
|
|
92
|
-
}
|
|
93
|
-
if (headersSchema !== void 0 && !this.schemaUtils.isObjectSchema(headersSchema)) {
|
|
94
|
-
throw new OpenAPIError(`When input structure is 'detailed', headers schema in input schema must be an object.`);
|
|
95
|
-
}
|
|
96
|
-
return { paramsSchema, querySchema, headersSchema, bodySchema };
|
|
97
|
-
}
|
|
98
|
-
parseCompactSchema(inputSchema, method, httpPath) {
|
|
99
|
-
const dynamic = httpPath ? this.pathParser.parseDynamicParams(httpPath) : [];
|
|
100
|
-
if (dynamic.length === 0) {
|
|
101
|
-
if (method === "GET") {
|
|
102
|
-
let querySchema = inputSchema;
|
|
103
|
-
if (querySchema !== void 0 && this.schemaUtils.isAnySchema(querySchema)) {
|
|
104
|
-
querySchema = void 0;
|
|
105
|
-
}
|
|
106
|
-
if (querySchema !== void 0 && !this.schemaUtils.isObjectSchema(querySchema)) {
|
|
107
|
-
throw new OpenAPIError(`When input structure is 'compact' and method is 'GET', input schema must be an object.`);
|
|
108
|
-
}
|
|
109
|
-
return {
|
|
110
|
-
paramsSchema: void 0,
|
|
111
|
-
querySchema,
|
|
112
|
-
headersSchema: void 0,
|
|
113
|
-
bodySchema: void 0
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
return {
|
|
117
|
-
paramsSchema: void 0,
|
|
118
|
-
querySchema: void 0,
|
|
119
|
-
headersSchema: void 0,
|
|
120
|
-
bodySchema: inputSchema
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
if (!this.schemaUtils.isObjectSchema(inputSchema)) {
|
|
124
|
-
throw new OpenAPIError(`When input structure is 'compact' and path has dynamic parameters, input schema must be an object.`);
|
|
125
|
-
}
|
|
126
|
-
const [params, rest] = this.schemaUtils.separateObjectSchema(inputSchema, dynamic.map((v) => v.name));
|
|
127
|
-
return {
|
|
128
|
-
paramsSchema: params,
|
|
129
|
-
querySchema: method === "GET" ? rest : void 0,
|
|
130
|
-
headersSchema: void 0,
|
|
131
|
-
bodySchema: method !== "GET" ? rest : void 0
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
// src/openapi-output-structure-parser.ts
|
|
137
|
-
var OpenAPIOutputStructureParser = class {
|
|
138
|
-
constructor(schemaConverter, schemaUtils) {
|
|
139
|
-
this.schemaConverter = schemaConverter;
|
|
140
|
-
this.schemaUtils = schemaUtils;
|
|
141
|
-
}
|
|
142
|
-
parse(contract, structure) {
|
|
143
|
-
const outputSchema = this.schemaConverter.convert(contract["~orpc"].OutputSchema, { strategy: "output" });
|
|
144
|
-
if (this.schemaUtils.isAnySchema(outputSchema)) {
|
|
145
|
-
return {
|
|
146
|
-
headersSchema: void 0,
|
|
147
|
-
bodySchema: void 0
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
if (structure === "detailed") {
|
|
151
|
-
return this.parseDetailedSchema(outputSchema);
|
|
152
|
-
} else {
|
|
153
|
-
return this.parseCompactSchema(outputSchema);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
parseDetailedSchema(outputSchema) {
|
|
157
|
-
if (!this.schemaUtils.isObjectSchema(outputSchema)) {
|
|
158
|
-
throw new OpenAPIError(`When output structure is 'detailed', output schema must be an object.`);
|
|
159
|
-
}
|
|
160
|
-
if (outputSchema.properties && Object.keys(outputSchema.properties).some((key) => !["headers", "body"].includes(key))) {
|
|
161
|
-
throw new OpenAPIError(`When output structure is 'detailed', output schema must be only can contain 'headers' and 'body' properties.`);
|
|
162
|
-
}
|
|
163
|
-
let headersSchema = outputSchema.properties?.headers;
|
|
164
|
-
const bodySchema = outputSchema.properties?.body;
|
|
165
|
-
if (headersSchema !== void 0 && this.schemaUtils.isAnySchema(headersSchema)) {
|
|
166
|
-
headersSchema = void 0;
|
|
167
|
-
}
|
|
168
|
-
if (headersSchema !== void 0 && !this.schemaUtils.isObjectSchema(headersSchema)) {
|
|
169
|
-
throw new OpenAPIError(`When output structure is 'detailed', headers schema in output schema must be an object.`);
|
|
170
|
-
}
|
|
171
|
-
return { headersSchema, bodySchema };
|
|
172
|
-
}
|
|
173
|
-
parseCompactSchema(outputSchema) {
|
|
174
|
-
return {
|
|
175
|
-
headersSchema: void 0,
|
|
176
|
-
bodySchema: outputSchema
|
|
177
|
-
};
|
|
178
|
-
}
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
// src/openapi-parameters-builder.ts
|
|
182
|
-
import { get, isPlainObject, omit } from "@orpc/shared";
|
|
183
|
-
var OpenAPIParametersBuilder = class {
|
|
184
|
-
build(paramIn, jsonSchema, options) {
|
|
185
|
-
const parameters = [];
|
|
186
|
-
for (const name in jsonSchema.properties) {
|
|
187
|
-
const schema = jsonSchema.properties[name];
|
|
188
|
-
const paramExamples = jsonSchema.examples?.filter((example) => {
|
|
189
|
-
return isPlainObject(example) && name in example;
|
|
190
|
-
}).map((example) => {
|
|
191
|
-
return example[name];
|
|
192
|
-
});
|
|
193
|
-
const paramSchema = {
|
|
194
|
-
examples: paramExamples?.length ? paramExamples : void 0,
|
|
195
|
-
...schema === true ? {} : schema === false ? { not: {} } : schema
|
|
196
|
-
};
|
|
197
|
-
const paramExample = get(options?.example, [name]);
|
|
198
|
-
parameters.push({
|
|
199
|
-
name,
|
|
200
|
-
in: paramIn,
|
|
201
|
-
required: typeof options?.required === "boolean" ? options.required : jsonSchema.required?.includes(name) ?? false,
|
|
202
|
-
schema: paramSchema,
|
|
203
|
-
example: paramExample,
|
|
204
|
-
style: options?.style
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
return parameters;
|
|
208
|
-
}
|
|
209
|
-
buildHeadersObject(jsonSchema, options) {
|
|
210
|
-
const parameters = this.build("header", jsonSchema, options);
|
|
211
|
-
const headersObject = {};
|
|
212
|
-
for (const param of parameters) {
|
|
213
|
-
headersObject[param.name] = omit(param, ["name", "in"]);
|
|
214
|
-
}
|
|
215
|
-
return headersObject;
|
|
216
|
-
}
|
|
217
|
-
};
|
|
218
|
-
|
|
219
|
-
// src/openapi-path-parser.ts
|
|
220
|
-
var OpenAPIPathParser = class {
|
|
221
|
-
parseDynamicParams(path) {
|
|
222
|
-
const raws = path.match(/\{([^}]+)\}/g) ?? [];
|
|
223
|
-
return raws.map((raw) => {
|
|
224
|
-
const name = raw.slice(1, -1).split(":")[0];
|
|
225
|
-
return { name, raw };
|
|
226
|
-
});
|
|
227
|
-
}
|
|
228
|
-
};
|
|
229
|
-
|
|
230
|
-
// src/schema-converter.ts
|
|
231
|
-
var CompositeSchemaConverter = class {
|
|
232
|
-
converters;
|
|
233
|
-
constructor(converters) {
|
|
234
|
-
this.converters = converters;
|
|
235
|
-
}
|
|
236
|
-
condition() {
|
|
237
|
-
return true;
|
|
238
|
-
}
|
|
239
|
-
convert(schema, options) {
|
|
240
|
-
for (const converter of this.converters) {
|
|
241
|
-
if (converter.condition(schema, options)) {
|
|
242
|
-
return converter.convert(schema, options);
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
return {};
|
|
246
|
-
}
|
|
247
|
-
};
|
|
248
|
-
|
|
249
|
-
// src/schema-utils.ts
|
|
250
|
-
import { isPlainObject as isPlainObject2 } from "@orpc/shared";
|
|
251
|
-
|
|
252
|
-
// src/schema.ts
|
|
253
|
-
import * as JSONSchema from "json-schema-typed/draft-2020-12";
|
|
254
|
-
import { Format } from "json-schema-typed/draft-2020-12";
|
|
255
|
-
var NON_LOGIC_KEYWORDS = [
|
|
256
|
-
// Core Documentation Keywords
|
|
257
|
-
"$anchor",
|
|
258
|
-
"$comment",
|
|
259
|
-
"$defs",
|
|
260
|
-
"$id",
|
|
261
|
-
"title",
|
|
262
|
-
"description",
|
|
263
|
-
// Value Keywords
|
|
264
|
-
"default",
|
|
265
|
-
"deprecated",
|
|
266
|
-
"examples",
|
|
267
|
-
// Metadata Keywords
|
|
268
|
-
"$schema",
|
|
269
|
-
"definitions",
|
|
270
|
-
// Legacy, but still used
|
|
271
|
-
"readOnly",
|
|
272
|
-
"writeOnly",
|
|
273
|
-
// Display and UI Hints
|
|
274
|
-
"contentMediaType",
|
|
275
|
-
"contentEncoding",
|
|
276
|
-
"format",
|
|
277
|
-
// Custom Extensions
|
|
278
|
-
"$vocabulary",
|
|
279
|
-
"$dynamicAnchor",
|
|
280
|
-
"$dynamicRef"
|
|
281
|
-
];
|
|
282
|
-
|
|
283
|
-
// src/schema-utils.ts
|
|
284
|
-
var SchemaUtils = class {
|
|
285
|
-
isFileSchema(schema) {
|
|
286
|
-
return typeof schema === "object" && schema.type === "string" && typeof schema.contentMediaType === "string";
|
|
287
|
-
}
|
|
288
|
-
isObjectSchema(schema) {
|
|
289
|
-
return typeof schema === "object" && schema.type === "object";
|
|
290
|
-
}
|
|
291
|
-
isAnySchema(schema) {
|
|
292
|
-
return schema === true || Object.keys(schema).length === 0;
|
|
293
|
-
}
|
|
294
|
-
isUndefinableSchema(schema) {
|
|
295
|
-
const [matches] = this.filterSchemaBranches(schema, (schema2) => {
|
|
296
|
-
if (typeof schema2 === "boolean") {
|
|
297
|
-
return schema2;
|
|
298
|
-
}
|
|
299
|
-
return Object.keys(schema2).length === 0;
|
|
300
|
-
});
|
|
301
|
-
return matches.length > 0;
|
|
302
|
-
}
|
|
303
|
-
separateObjectSchema(schema, separatedProperties) {
|
|
304
|
-
const matched = { ...schema };
|
|
305
|
-
const rest = { ...schema };
|
|
306
|
-
matched.properties = Object.entries(schema.properties ?? {}).filter(([key]) => separatedProperties.includes(key)).reduce((acc, [key, value]) => {
|
|
307
|
-
acc[key] = value;
|
|
308
|
-
return acc;
|
|
309
|
-
}, {});
|
|
310
|
-
matched.required = schema.required?.filter((key) => separatedProperties.includes(key));
|
|
311
|
-
matched.examples = schema.examples?.map((example) => {
|
|
312
|
-
if (!isPlainObject2(example)) {
|
|
313
|
-
return example;
|
|
314
|
-
}
|
|
315
|
-
return Object.entries(example).reduce((acc, [key, value]) => {
|
|
316
|
-
if (separatedProperties.includes(key)) {
|
|
317
|
-
acc[key] = value;
|
|
318
|
-
}
|
|
319
|
-
return acc;
|
|
320
|
-
}, {});
|
|
321
|
-
});
|
|
322
|
-
rest.properties = Object.entries(schema.properties ?? {}).filter(([key]) => !separatedProperties.includes(key)).reduce((acc, [key, value]) => {
|
|
323
|
-
acc[key] = value;
|
|
324
|
-
return acc;
|
|
325
|
-
}, {});
|
|
326
|
-
rest.required = schema.required?.filter((key) => !separatedProperties.includes(key));
|
|
327
|
-
rest.examples = schema.examples?.map((example) => {
|
|
328
|
-
if (!isPlainObject2(example)) {
|
|
329
|
-
return example;
|
|
330
|
-
}
|
|
331
|
-
return Object.entries(example).reduce((acc, [key, value]) => {
|
|
332
|
-
if (!separatedProperties.includes(key)) {
|
|
333
|
-
acc[key] = value;
|
|
334
|
-
}
|
|
335
|
-
return acc;
|
|
336
|
-
}, {});
|
|
337
|
-
});
|
|
338
|
-
return [matched, rest];
|
|
339
|
-
}
|
|
340
|
-
filterSchemaBranches(schema, check, matches = []) {
|
|
341
|
-
if (check(schema)) {
|
|
342
|
-
matches.push(schema);
|
|
343
|
-
return [matches, void 0];
|
|
344
|
-
}
|
|
345
|
-
if (typeof schema === "boolean") {
|
|
346
|
-
return [matches, schema];
|
|
347
|
-
}
|
|
348
|
-
if (schema.anyOf && Object.keys(schema).every(
|
|
349
|
-
(k) => k === "anyOf" || NON_LOGIC_KEYWORDS.includes(k)
|
|
350
|
-
)) {
|
|
351
|
-
const anyOf = schema.anyOf.map((s) => this.filterSchemaBranches(s, check, matches)[1]).filter((v) => !!v);
|
|
352
|
-
if (anyOf.length === 1 && typeof anyOf[0] === "object") {
|
|
353
|
-
return [matches, { ...schema, anyOf: void 0, ...anyOf[0] }];
|
|
354
|
-
}
|
|
355
|
-
return [matches, { ...schema, anyOf }];
|
|
356
|
-
}
|
|
357
|
-
if (schema.oneOf && Object.keys(schema).every(
|
|
358
|
-
(k) => k === "oneOf" || NON_LOGIC_KEYWORDS.includes(k)
|
|
359
|
-
)) {
|
|
360
|
-
const oneOf = schema.oneOf.map((s) => this.filterSchemaBranches(s, check, matches)[1]).filter((v) => !!v);
|
|
361
|
-
if (oneOf.length === 1 && typeof oneOf[0] === "object") {
|
|
362
|
-
return [matches, { ...schema, oneOf: void 0, ...oneOf[0] }];
|
|
363
|
-
}
|
|
364
|
-
return [matches, { ...schema, oneOf }];
|
|
365
|
-
}
|
|
366
|
-
return [matches, schema];
|
|
367
|
-
}
|
|
368
|
-
};
|
|
369
|
-
|
|
370
|
-
// src/openapi-generator.ts
|
|
371
|
-
var OpenAPIGenerator = class {
|
|
372
|
-
contentBuilder;
|
|
373
|
-
parametersBuilder;
|
|
374
|
-
schemaConverter;
|
|
375
|
-
schemaUtils;
|
|
376
|
-
jsonSerializer;
|
|
377
|
-
pathParser;
|
|
378
|
-
inputStructureParser;
|
|
379
|
-
outputStructureParser;
|
|
380
|
-
errorHandlerStrategy;
|
|
381
|
-
ignoreUndefinedPathProcedures;
|
|
382
|
-
considerMissingTagDefinitionAsError;
|
|
383
|
-
constructor(options) {
|
|
384
|
-
this.parametersBuilder = options?.parametersBuilder ?? new OpenAPIParametersBuilder();
|
|
385
|
-
this.schemaConverter = new CompositeSchemaConverter(options?.schemaConverters ?? []);
|
|
386
|
-
this.schemaUtils = options?.schemaUtils ?? new SchemaUtils();
|
|
387
|
-
this.jsonSerializer = options?.jsonSerializer ?? new JSONSerializer();
|
|
388
|
-
this.contentBuilder = options?.contentBuilder ?? new OpenAPIContentBuilder(this.schemaUtils);
|
|
389
|
-
this.pathParser = new OpenAPIPathParser();
|
|
390
|
-
this.inputStructureParser = options?.inputStructureParser ?? new OpenAPIInputStructureParser(this.schemaConverter, this.schemaUtils, this.pathParser);
|
|
391
|
-
this.outputStructureParser = options?.outputStructureParser ?? new OpenAPIOutputStructureParser(this.schemaConverter, this.schemaUtils);
|
|
392
|
-
this.errorHandlerStrategy = options?.errorHandlerStrategy ?? "throw";
|
|
393
|
-
this.ignoreUndefinedPathProcedures = options?.ignoreUndefinedPathProcedures ?? false;
|
|
394
|
-
this.considerMissingTagDefinitionAsError = options?.considerMissingTagDefinitionAsError ?? false;
|
|
395
|
-
}
|
|
396
|
-
async generate(router, doc) {
|
|
397
|
-
const builder = new OpenApiBuilder({
|
|
398
|
-
...doc,
|
|
399
|
-
openapi: "3.1.1"
|
|
400
|
-
});
|
|
401
|
-
const rootTags = doc.tags?.map((tag) => tag.name) ?? [];
|
|
402
|
-
await forEachAllContractProcedure(router, ({ contract, path }) => {
|
|
403
|
-
try {
|
|
404
|
-
const def = contract["~orpc"];
|
|
405
|
-
if (this.ignoreUndefinedPathProcedures && def.route?.path === void 0) {
|
|
406
|
-
return;
|
|
407
|
-
}
|
|
408
|
-
const method = def.route?.method ?? "POST";
|
|
409
|
-
const httpPath = def.route?.path ? standardizeHTTPPath(def.route?.path) : `/${path.map(encodeURIComponent).join("/")}`;
|
|
410
|
-
const { paramsSchema, querySchema, headersSchema, bodySchema } = this.inputStructureParser.parse(contract, def.route?.inputStructure ?? "compact");
|
|
411
|
-
const { headersSchema: resHeadersSchema, bodySchema: resBodySchema } = this.outputStructureParser.parse(contract, def.route?.outputStructure ?? "compact");
|
|
412
|
-
const params = paramsSchema ? this.parametersBuilder.build("path", paramsSchema, {
|
|
413
|
-
required: true
|
|
414
|
-
}) : [];
|
|
415
|
-
const query = querySchema ? this.parametersBuilder.build("query", querySchema) : [];
|
|
416
|
-
const headers = headersSchema ? this.parametersBuilder.build("header", headersSchema) : [];
|
|
417
|
-
const parameters = [...params, ...query, ...headers];
|
|
418
|
-
const requestBody = bodySchema !== void 0 ? {
|
|
419
|
-
required: this.schemaUtils.isUndefinableSchema(bodySchema),
|
|
420
|
-
content: this.contentBuilder.build(bodySchema)
|
|
421
|
-
} : void 0;
|
|
422
|
-
const successResponse = {
|
|
423
|
-
description: "OK",
|
|
424
|
-
content: resBodySchema !== void 0 ? this.contentBuilder.build(resBodySchema, {
|
|
425
|
-
example: def.outputExample
|
|
426
|
-
}) : void 0,
|
|
427
|
-
headers: resHeadersSchema !== void 0 ? this.parametersBuilder.buildHeadersObject(resHeadersSchema, {
|
|
428
|
-
example: def.outputExample
|
|
429
|
-
}) : void 0
|
|
430
|
-
};
|
|
431
|
-
if (this.considerMissingTagDefinitionAsError && def.route?.tags) {
|
|
432
|
-
const missingTag = def.route?.tags.find((tag) => !rootTags.includes(tag));
|
|
433
|
-
if (missingTag !== void 0) {
|
|
434
|
-
throw new OpenAPIError(
|
|
435
|
-
`Tag "${missingTag}" is missing definition. Please define it in OpenAPI root tags object`
|
|
436
|
-
);
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
const operation = {
|
|
440
|
-
summary: def.route?.summary,
|
|
441
|
-
description: def.route?.description,
|
|
442
|
-
deprecated: def.route?.deprecated,
|
|
443
|
-
tags: def.route?.tags ? [...def.route.tags] : void 0,
|
|
444
|
-
operationId: path.join("."),
|
|
445
|
-
parameters: parameters.length ? parameters : void 0,
|
|
446
|
-
requestBody,
|
|
447
|
-
responses: {
|
|
448
|
-
[def.route?.successStatus ?? 200]: successResponse
|
|
449
|
-
}
|
|
450
|
-
};
|
|
451
|
-
builder.addPath(httpPath, {
|
|
452
|
-
[method.toLocaleLowerCase()]: operation
|
|
453
|
-
});
|
|
454
|
-
} catch (e) {
|
|
455
|
-
if (e instanceof OpenAPIError) {
|
|
456
|
-
const error = new OpenAPIError(`
|
|
457
|
-
Generate OpenAPI Error: ${e.message}
|
|
458
|
-
Happened at path: ${path.join(".")}
|
|
459
|
-
`, { cause: e });
|
|
460
|
-
if (this.errorHandlerStrategy === "throw") {
|
|
461
|
-
throw error;
|
|
462
|
-
}
|
|
463
|
-
if (this.errorHandlerStrategy === "log") {
|
|
464
|
-
console.error(error);
|
|
465
|
-
}
|
|
466
|
-
} else {
|
|
467
|
-
throw e;
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
});
|
|
471
|
-
return this.jsonSerializer.serialize(builder.getSpec());
|
|
472
|
-
}
|
|
473
|
-
};
|
|
474
|
-
export {
|
|
475
|
-
CompositeSchemaConverter,
|
|
476
|
-
JSONSchema,
|
|
477
|
-
Format as JSONSchemaFormat,
|
|
478
|
-
JSONSerializer,
|
|
479
|
-
NON_LOGIC_KEYWORDS,
|
|
480
|
-
OpenAPIContentBuilder,
|
|
481
|
-
OpenAPIGenerator,
|
|
482
|
-
OpenAPIParametersBuilder,
|
|
483
|
-
OpenAPIPathParser,
|
|
484
|
-
OpenApiBuilder,
|
|
485
|
-
SchemaUtils,
|
|
486
|
-
forEachAllContractProcedure,
|
|
487
|
-
forEachContractProcedure,
|
|
488
|
-
standardizeHTTPPath
|
|
489
|
-
};
|
|
490
|
-
//# sourceMappingURL=index.js.map
|
package/dist/node.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
OpenAPIHandler
|
|
3
|
-
} from "./chunk-YXHH6XHB.js";
|
|
4
|
-
import "./chunk-KNYXLM77.js";
|
|
5
|
-
|
|
6
|
-
// src/adapters/node/openapi-handler.ts
|
|
7
|
-
import { createRequest, sendResponse } from "@mjackson/node-fetch-server";
|
|
8
|
-
import { ORPC_HANDLER_HEADER } from "@orpc/shared";
|
|
9
|
-
var OpenAPIHandler2 = class {
|
|
10
|
-
openapiFetchHandler;
|
|
11
|
-
constructor(hono, router, options) {
|
|
12
|
-
this.openapiFetchHandler = new OpenAPIHandler(hono, router, options);
|
|
13
|
-
}
|
|
14
|
-
condition(request) {
|
|
15
|
-
return request.headers[ORPC_HANDLER_HEADER] === void 0;
|
|
16
|
-
}
|
|
17
|
-
async handle(req, res, ...[options]) {
|
|
18
|
-
const request = createRequest(req, res, options);
|
|
19
|
-
const castedOptions = options ?? {};
|
|
20
|
-
const response = await this.openapiFetchHandler.fetch(request, castedOptions);
|
|
21
|
-
await options?.beforeSend?.(response, castedOptions.context);
|
|
22
|
-
return await sendResponse(res, response);
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
// src/adapters/node/openapi-handler-server.ts
|
|
27
|
-
import { TrieRouter } from "hono/router/trie-router";
|
|
28
|
-
var OpenAPIServerHandler = class extends OpenAPIHandler2 {
|
|
29
|
-
constructor(router, options) {
|
|
30
|
-
super(new TrieRouter(), router, options);
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
// src/adapters/node/openapi-handler-serverless.ts
|
|
35
|
-
import { LinearRouter } from "hono/router/linear-router";
|
|
36
|
-
var OpenAPIServerlessHandler = class extends OpenAPIHandler2 {
|
|
37
|
-
constructor(router, options) {
|
|
38
|
-
super(new LinearRouter(), router, options);
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
export {
|
|
42
|
-
OpenAPIHandler2 as OpenAPIHandler,
|
|
43
|
-
OpenAPIServerHandler,
|
|
44
|
-
OpenAPIServerlessHandler
|
|
45
|
-
};
|
|
46
|
-
//# sourceMappingURL=node.js.map
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Serialize an object or array into a list of [key, value] pairs.
|
|
3
|
-
* The key will express by using bracket-notation.
|
|
4
|
-
*
|
|
5
|
-
* Notice: This way cannot express the empty object or array.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```ts
|
|
9
|
-
* const payload = {
|
|
10
|
-
* name: 'John Doe',
|
|
11
|
-
* pets: ['dog', 'cat'],
|
|
12
|
-
* }
|
|
13
|
-
*
|
|
14
|
-
* const entities = serialize(payload)
|
|
15
|
-
*
|
|
16
|
-
* expect(entities).toEqual([
|
|
17
|
-
* ['name', 'John Doe'],
|
|
18
|
-
* ['name[pets][0]', 'dog'],
|
|
19
|
-
* ['name[pets][1]', 'cat'],
|
|
20
|
-
* ])
|
|
21
|
-
* ```
|
|
22
|
-
*/
|
|
23
|
-
export declare function serialize(payload: unknown, parentKey?: string): [string, unknown][];
|
|
24
|
-
/**
|
|
25
|
-
* Deserialize a list of [key, value] pairs into an object or array.
|
|
26
|
-
* The key is expressed by using bracket-notation.
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* ```ts
|
|
30
|
-
* const entities = [
|
|
31
|
-
* ['name', 'John Doe'],
|
|
32
|
-
* ['name[pets][0]', 'dog'],
|
|
33
|
-
* ['name[pets][1]', 'cat'],
|
|
34
|
-
* ['name[dogs][]', 'hello'],
|
|
35
|
-
* ['name[dogs][]', 'kitty'],
|
|
36
|
-
* ]
|
|
37
|
-
*
|
|
38
|
-
* const payload = deserialize(entities)
|
|
39
|
-
*
|
|
40
|
-
* expect(payload).toEqual({
|
|
41
|
-
* name: 'John Doe',
|
|
42
|
-
* pets: { 0: 'dog', 1: 'cat' },
|
|
43
|
-
* dogs: ['hello', 'kitty'],
|
|
44
|
-
* })
|
|
45
|
-
* ```
|
|
46
|
-
*/
|
|
47
|
-
export declare function deserialize(entities: readonly (readonly [string, unknown])[]): Record<string, unknown> | unknown[] | undefined;
|
|
48
|
-
/**
|
|
49
|
-
* Escape the `[`, `]`, and `\` chars in a path segment.
|
|
50
|
-
*
|
|
51
|
-
* @example
|
|
52
|
-
* ```ts
|
|
53
|
-
* expect(escapeSegment('name[pets')).toEqual('name\\[pets')
|
|
54
|
-
* ```
|
|
55
|
-
*/
|
|
56
|
-
export declare function escapeSegment(segment: string): string;
|
|
57
|
-
/**
|
|
58
|
-
* Convert an array of path segments into a path string using bracket-notation.
|
|
59
|
-
*
|
|
60
|
-
* For the special char `[`, `]`, and `\` will be escaped by adding `\` at start.
|
|
61
|
-
*
|
|
62
|
-
* @example
|
|
63
|
-
* ```ts
|
|
64
|
-
* expect(stringifyPath(['name', 'pets', '0'])).toEqual('name[pets][0]')
|
|
65
|
-
* ```
|
|
66
|
-
*/
|
|
67
|
-
export declare function stringifyPath(path: readonly [string, ...string[]]): string;
|
|
68
|
-
/**
|
|
69
|
-
* Convert a path string using bracket-notation into an array of path segments.
|
|
70
|
-
*
|
|
71
|
-
* For the special char `[`, `]`, and `\` you should escape by adding `\` at start.
|
|
72
|
-
* It only treats a pair `[${string}]` as a path segment.
|
|
73
|
-
* If missing or escape it will bypass and treat as normal string.
|
|
74
|
-
*
|
|
75
|
-
* @example
|
|
76
|
-
* ```ts
|
|
77
|
-
* expect(parsePath('name[pets][0]')).toEqual(['name', 'pets', '0'])
|
|
78
|
-
* expect(parsePath('name[pets][0')).toEqual(['name', 'pets', '[0'])
|
|
79
|
-
* expect(parsePath('name[pets[0]')).toEqual(['name', 'pets[0')
|
|
80
|
-
* expect(parsePath('name\\[pets][0]')).toEqual(['name[pets]', '0'])
|
|
81
|
-
* ```
|
|
82
|
-
*/
|
|
83
|
-
export declare function parsePath(path: string): [string, ...string[]];
|
|
84
|
-
//# sourceMappingURL=bracket-notation.d.ts.map
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export * from './bracket-notation';
|
|
2
|
-
export * from './input-structure-compact';
|
|
3
|
-
export * from './input-structure-detailed';
|
|
4
|
-
export * from './openapi-handler';
|
|
5
|
-
export * from './openapi-handler-server';
|
|
6
|
-
export * from './openapi-handler-serverless';
|
|
7
|
-
export * from './openapi-payload-codec';
|
|
8
|
-
export * from './openapi-procedure-matcher';
|
|
9
|
-
export * from './schema-coercer';
|
|
10
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { Params } from 'hono/router';
|
|
2
|
-
export declare class InputStructureCompact {
|
|
3
|
-
build(params: Params, payload: unknown): unknown;
|
|
4
|
-
}
|
|
5
|
-
export type PublicInputStructureCompact = Pick<InputStructureCompact, keyof InputStructureCompact>;
|
|
6
|
-
//# sourceMappingURL=input-structure-compact.d.ts.map
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { Params } from 'hono/router';
|
|
2
|
-
export declare class InputStructureDetailed {
|
|
3
|
-
build(params: Params, query: unknown, headers: unknown, body: unknown): {
|
|
4
|
-
params: Params;
|
|
5
|
-
query: unknown;
|
|
6
|
-
headers: unknown;
|
|
7
|
-
body: unknown;
|
|
8
|
-
};
|
|
9
|
-
}
|
|
10
|
-
export type PublicInputStructureDetailed = Pick<InputStructureDetailed, keyof InputStructureDetailed>;
|
|
11
|
-
//# sourceMappingURL=input-structure-detailed.d.ts.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { Context, Router } from '@orpc/server';
|
|
2
|
-
import type { OpenAPIHandlerOptions } from './openapi-handler';
|
|
3
|
-
import { OpenAPIHandler } from './openapi-handler';
|
|
4
|
-
export declare class OpenAPIServerHandler<T extends Context> extends OpenAPIHandler<T> {
|
|
5
|
-
constructor(router: Router<T, any>, options?: NoInfer<OpenAPIHandlerOptions<T>>);
|
|
6
|
-
}
|
|
7
|
-
//# sourceMappingURL=openapi-handler-server.d.ts.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { Context, Router } from '@orpc/server';
|
|
2
|
-
import type { OpenAPIHandlerOptions } from './openapi-handler';
|
|
3
|
-
import { OpenAPIHandler } from './openapi-handler';
|
|
4
|
-
export declare class OpenAPIServerlessHandler<T extends Context> extends OpenAPIHandler<T> {
|
|
5
|
-
constructor(router: Router<T, any>, options?: NoInfer<OpenAPIHandlerOptions<T>>);
|
|
6
|
-
}
|
|
7
|
-
//# sourceMappingURL=openapi-handler-serverless.d.ts.map
|