@orpc/openapi 0.36.1 → 0.37.0
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/dist/{chunk-BHJYKXQL.js → chunk-HC5PVG4R.js} +3 -3
- package/dist/{chunk-WBGO55OM.js → chunk-ICLAXOVR.js} +2 -2
- package/dist/{chunk-44Q55FOB.js → chunk-PWOV66X6.js} +9 -9
- package/dist/fetch.js +3 -3
- package/dist/hono.js +3 -3
- package/dist/index.js +63 -7
- package/dist/next.js +3 -3
- package/dist/node.js +2 -2
- package/dist/src/index.d.ts +5 -0
- package/dist/src/openapi-operation-extender.d.ts +7 -0
- package/dist/standard.js +2 -2
- package/package.json +4 -4
@@ -5,7 +5,7 @@ var __export = (target, all) => {
|
|
5
5
|
};
|
6
6
|
|
7
7
|
// src/json-serializer.ts
|
8
|
-
import {
|
8
|
+
import { isObject } from "@orpc/shared";
|
9
9
|
var JSONSerializer = class {
|
10
10
|
serialize(payload) {
|
11
11
|
if (payload instanceof Set)
|
@@ -26,7 +26,7 @@ var JSONSerializer = class {
|
|
26
26
|
return payload.toString();
|
27
27
|
if (payload instanceof URL)
|
28
28
|
return payload.toString();
|
29
|
-
if (!
|
29
|
+
if (!isObject(payload))
|
30
30
|
return payload;
|
31
31
|
return Object.keys(payload).reduce(
|
32
32
|
(carry, key) => {
|
@@ -49,4 +49,4 @@ export {
|
|
49
49
|
JSONSerializer,
|
50
50
|
standardizeHTTPPath
|
51
51
|
};
|
52
|
-
//# sourceMappingURL=chunk-
|
52
|
+
//# sourceMappingURL=chunk-HC5PVG4R.js.map
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import {
|
2
2
|
OpenAPICodec,
|
3
3
|
OpenAPIMatcher
|
4
|
-
} from "./chunk-
|
4
|
+
} from "./chunk-PWOV66X6.js";
|
5
5
|
|
6
6
|
// src/adapters/fetch/openapi-handler.ts
|
7
7
|
import { fetchRequestToStandardRequest, standardResponseToFetchResponse } from "@orpc/server/fetch";
|
@@ -29,4 +29,4 @@ var OpenAPIHandler = class {
|
|
29
29
|
export {
|
30
30
|
OpenAPIHandler
|
31
31
|
};
|
32
|
-
//# sourceMappingURL=chunk-
|
32
|
+
//# sourceMappingURL=chunk-ICLAXOVR.js.map
|
@@ -2,7 +2,7 @@ import {
|
|
2
2
|
JSONSerializer,
|
3
3
|
__export,
|
4
4
|
standardizeHTTPPath
|
5
|
-
} from "./chunk-
|
5
|
+
} from "./chunk-HC5PVG4R.js";
|
6
6
|
|
7
7
|
// src/adapters/standard/bracket-notation.ts
|
8
8
|
var bracket_notation_exports = {};
|
@@ -13,9 +13,9 @@ __export(bracket_notation_exports, {
|
|
13
13
|
serialize: () => serialize,
|
14
14
|
stringifyPath: () => stringifyPath
|
15
15
|
});
|
16
|
-
import {
|
16
|
+
import { isObject } from "@orpc/shared";
|
17
17
|
function serialize(payload, parentKey = "") {
|
18
|
-
if (!Array.isArray(payload) && !
|
18
|
+
if (!Array.isArray(payload) && !isObject(payload))
|
19
19
|
return [["", payload]];
|
20
20
|
const result = [];
|
21
21
|
function helper(value, path) {
|
@@ -23,7 +23,7 @@ function serialize(payload, parentKey = "") {
|
|
23
23
|
value.forEach((item, index) => {
|
24
24
|
helper(item, [...path, String(index)]);
|
25
25
|
});
|
26
|
-
} else if (
|
26
|
+
} else if (isObject(value)) {
|
27
27
|
for (const [key, val] of Object.entries(value)) {
|
28
28
|
helper(val, [...path, key]);
|
29
29
|
}
|
@@ -223,7 +223,7 @@ function parsePath(path) {
|
|
223
223
|
|
224
224
|
// src/adapters/standard/openapi-codec.ts
|
225
225
|
import { fallbackContractConfig } from "@orpc/contract";
|
226
|
-
import {
|
226
|
+
import { isObject as isObject2 } from "@orpc/shared";
|
227
227
|
|
228
228
|
// src/adapters/standard/openapi-serializer.ts
|
229
229
|
import { findDeepMatches } from "@orpc/shared";
|
@@ -274,7 +274,7 @@ var OpenAPICodec = class {
|
|
274
274
|
if (data === void 0) {
|
275
275
|
return params;
|
276
276
|
}
|
277
|
-
if (
|
277
|
+
if (isObject2(data)) {
|
278
278
|
return {
|
279
279
|
...params,
|
280
280
|
...data
|
@@ -309,7 +309,7 @@ var OpenAPICodec = class {
|
|
309
309
|
body: this.serializer.serialize(output)
|
310
310
|
};
|
311
311
|
}
|
312
|
-
if (!
|
312
|
+
if (!isObject2(output)) {
|
313
313
|
throw new Error(
|
314
314
|
'Invalid output structure for "detailed" output. Expected format: { body: any, headers?: Record<string, string | string[] | undefined> }'
|
315
315
|
);
|
@@ -404,7 +404,7 @@ var OpenAPIMatcher = class {
|
|
404
404
|
path: match.data.path,
|
405
405
|
procedure: match.data.procedure,
|
406
406
|
params: match.params ? { ...match.params } : void 0
|
407
|
-
// normalize params
|
407
|
+
// normalize params
|
408
408
|
};
|
409
409
|
}
|
410
410
|
};
|
@@ -418,4 +418,4 @@ export {
|
|
418
418
|
OpenAPICodec,
|
419
419
|
OpenAPIMatcher
|
420
420
|
};
|
421
|
-
//# sourceMappingURL=chunk-
|
421
|
+
//# sourceMappingURL=chunk-PWOV66X6.js.map
|
package/dist/fetch.js
CHANGED
package/dist/hono.js
CHANGED
package/dist/index.js
CHANGED
@@ -1,7 +1,53 @@
|
|
1
1
|
import {
|
2
2
|
JSONSerializer,
|
3
3
|
standardizeHTTPPath
|
4
|
-
} from "./chunk-
|
4
|
+
} from "./chunk-HC5PVG4R.js";
|
5
|
+
|
6
|
+
// src/openapi-operation-extender.ts
|
7
|
+
import { isProcedure } from "@orpc/server";
|
8
|
+
var OPERATION_EXTENDER_SYMBOL = Symbol("ORPC_OPERATION_EXTENDER");
|
9
|
+
function setOperationExtender(o, extend) {
|
10
|
+
return new Proxy(o, {
|
11
|
+
get(target, prop, receiver) {
|
12
|
+
if (prop === OPERATION_EXTENDER_SYMBOL) {
|
13
|
+
return extend;
|
14
|
+
}
|
15
|
+
return Reflect.get(target, prop, receiver);
|
16
|
+
}
|
17
|
+
});
|
18
|
+
}
|
19
|
+
function getOperationExtender(o) {
|
20
|
+
return o[OPERATION_EXTENDER_SYMBOL];
|
21
|
+
}
|
22
|
+
function extendOperation(operation, procedure) {
|
23
|
+
const operationExtenders = [];
|
24
|
+
for (const errorItem of Object.values(procedure["~orpc"].errorMap)) {
|
25
|
+
const maybeExtender = getOperationExtender(errorItem);
|
26
|
+
if (maybeExtender) {
|
27
|
+
operationExtenders.push(maybeExtender);
|
28
|
+
}
|
29
|
+
}
|
30
|
+
if (isProcedure(procedure)) {
|
31
|
+
for (const middleware of procedure["~orpc"].middlewares) {
|
32
|
+
const maybeExtender = getOperationExtender(middleware);
|
33
|
+
if (maybeExtender) {
|
34
|
+
operationExtenders.push(maybeExtender);
|
35
|
+
}
|
36
|
+
}
|
37
|
+
}
|
38
|
+
let currentOperation = operation;
|
39
|
+
for (const extender of operationExtenders) {
|
40
|
+
if (typeof extender === "function") {
|
41
|
+
currentOperation = extender(currentOperation, procedure);
|
42
|
+
} else {
|
43
|
+
currentOperation = {
|
44
|
+
...currentOperation,
|
45
|
+
...extender
|
46
|
+
};
|
47
|
+
}
|
48
|
+
}
|
49
|
+
return currentOperation;
|
50
|
+
}
|
5
51
|
|
6
52
|
// src/openapi.ts
|
7
53
|
import { OpenApiBuilder } from "openapi3-ts/oas31";
|
@@ -183,14 +229,14 @@ var OpenAPIOutputStructureParser = class {
|
|
183
229
|
};
|
184
230
|
|
185
231
|
// src/openapi-parameters-builder.ts
|
186
|
-
import { get,
|
232
|
+
import { get, isObject, omit } from "@orpc/shared";
|
187
233
|
var OpenAPIParametersBuilder = class {
|
188
234
|
build(paramIn, jsonSchema, options) {
|
189
235
|
const parameters = [];
|
190
236
|
for (const name in jsonSchema.properties) {
|
191
237
|
const schema = jsonSchema.properties[name];
|
192
238
|
const paramExamples = jsonSchema.examples?.filter((example) => {
|
193
|
-
return
|
239
|
+
return isObject(example) && name in example;
|
194
240
|
}).map((example) => {
|
195
241
|
return example[name];
|
196
242
|
});
|
@@ -251,7 +297,7 @@ var CompositeSchemaConverter = class {
|
|
251
297
|
};
|
252
298
|
|
253
299
|
// src/schema-utils.ts
|
254
|
-
import {
|
300
|
+
import { isObject as isObject2 } from "@orpc/shared";
|
255
301
|
|
256
302
|
// src/schema.ts
|
257
303
|
import * as JSONSchema from "json-schema-typed/draft-2020-12";
|
@@ -313,7 +359,7 @@ var SchemaUtils = class {
|
|
313
359
|
}, {});
|
314
360
|
matched.required = schema.required?.filter((key) => separatedProperties.includes(key));
|
315
361
|
matched.examples = schema.examples?.map((example) => {
|
316
|
-
if (!
|
362
|
+
if (!isObject2(example)) {
|
317
363
|
return example;
|
318
364
|
}
|
319
365
|
return Object.entries(example).reduce((acc, [key, value]) => {
|
@@ -329,7 +375,7 @@ var SchemaUtils = class {
|
|
329
375
|
}, {});
|
330
376
|
rest.required = schema.required?.filter((key) => !separatedProperties.includes(key));
|
331
377
|
rest.examples = schema.examples?.map((example) => {
|
332
|
-
if (!
|
378
|
+
if (!isObject2(example)) {
|
333
379
|
return example;
|
334
380
|
}
|
335
381
|
return Object.entries(example).reduce((acc, [key, value]) => {
|
@@ -506,8 +552,9 @@ var OpenAPIGenerator = class {
|
|
506
552
|
requestBody,
|
507
553
|
responses
|
508
554
|
};
|
555
|
+
const extendedOperation = extendOperation(operation, contract);
|
509
556
|
builder.addPath(httpPath, {
|
510
|
-
[method.toLocaleLowerCase()]:
|
557
|
+
[method.toLocaleLowerCase()]: extendedOperation
|
511
558
|
});
|
512
559
|
} catch (e) {
|
513
560
|
if (e instanceof OpenAPIError) {
|
@@ -529,6 +576,11 @@ var OpenAPIGenerator = class {
|
|
529
576
|
return this.jsonSerializer.serialize(builder.getSpec());
|
530
577
|
}
|
531
578
|
};
|
579
|
+
|
580
|
+
// src/index.ts
|
581
|
+
var oo = {
|
582
|
+
spec: setOperationExtender
|
583
|
+
};
|
532
584
|
export {
|
533
585
|
CompositeSchemaConverter,
|
534
586
|
JSONSchema,
|
@@ -541,6 +593,10 @@ export {
|
|
541
593
|
OpenAPIPathParser,
|
542
594
|
OpenApiBuilder,
|
543
595
|
SchemaUtils,
|
596
|
+
extendOperation,
|
597
|
+
getOperationExtender,
|
598
|
+
oo,
|
599
|
+
setOperationExtender,
|
544
600
|
standardizeHTTPPath
|
545
601
|
};
|
546
602
|
//# sourceMappingURL=index.js.map
|
package/dist/next.js
CHANGED
package/dist/node.js
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
import {
|
2
2
|
OpenAPICodec,
|
3
3
|
OpenAPIMatcher
|
4
|
-
} from "./chunk-
|
5
|
-
import "./chunk-
|
4
|
+
} from "./chunk-PWOV66X6.js";
|
5
|
+
import "./chunk-HC5PVG4R.js";
|
6
6
|
|
7
7
|
// src/adapters/node/openapi-handler.ts
|
8
8
|
import { nodeHttpResponseSendStandardResponse, nodeHttpToStandardRequest } from "@orpc/server/node";
|
package/dist/src/index.d.ts
CHANGED
@@ -1,12 +1,17 @@
|
|
1
1
|
/** unnoq */
|
2
|
+
import { setOperationExtender } from './openapi-operation-extender';
|
2
3
|
export * from './json-serializer';
|
3
4
|
export * from './openapi';
|
4
5
|
export * from './openapi-content-builder';
|
5
6
|
export * from './openapi-generator';
|
7
|
+
export * from './openapi-operation-extender';
|
6
8
|
export * from './openapi-parameters-builder';
|
7
9
|
export * from './openapi-path-parser';
|
8
10
|
export * from './schema';
|
9
11
|
export * from './schema-converter';
|
10
12
|
export * from './schema-utils';
|
11
13
|
export * from './utils';
|
14
|
+
export declare const oo: {
|
15
|
+
spec: typeof setOperationExtender;
|
16
|
+
};
|
12
17
|
//# sourceMappingURL=index.d.ts.map
|
@@ -0,0 +1,7 @@
|
|
1
|
+
import type { AnyContractProcedure } from '@orpc/contract';
|
2
|
+
import type { OpenAPI } from './openapi';
|
3
|
+
export type OverrideOperationValue = OpenAPI.OperationObject | ((current: OpenAPI.OperationObject, procedure: AnyContractProcedure) => OpenAPI.OperationObject);
|
4
|
+
export declare function setOperationExtender<T extends object>(o: T, extend: OverrideOperationValue): T;
|
5
|
+
export declare function getOperationExtender(o: object): OverrideOperationValue | undefined;
|
6
|
+
export declare function extendOperation(operation: OpenAPI.OperationObject, procedure: AnyContractProcedure): OpenAPI.OperationObject;
|
7
|
+
//# sourceMappingURL=openapi-operation-extender.d.ts.map
|
package/dist/standard.js
CHANGED
@@ -3,8 +3,8 @@ import {
|
|
3
3
|
OpenAPIMatcher,
|
4
4
|
OpenAPISerializer,
|
5
5
|
bracket_notation_exports
|
6
|
-
} from "./chunk-
|
7
|
-
import "./chunk-
|
6
|
+
} from "./chunk-PWOV66X6.js";
|
7
|
+
import "./chunk-HC5PVG4R.js";
|
8
8
|
export {
|
9
9
|
bracket_notation_exports as BracketNotation,
|
10
10
|
OpenAPICodec,
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@orpc/openapi",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.
|
4
|
+
"version": "0.37.0",
|
5
5
|
"license": "MIT",
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
7
7
|
"repository": {
|
@@ -60,9 +60,9 @@
|
|
60
60
|
"openapi3-ts": "^4.4.0",
|
61
61
|
"rou3": "^0.5.1",
|
62
62
|
"wildcard-match": "^5.1.3",
|
63
|
-
"@orpc/contract": "0.
|
64
|
-
"@orpc/
|
65
|
-
"@orpc/
|
63
|
+
"@orpc/contract": "0.37.0",
|
64
|
+
"@orpc/server": "0.37.0",
|
65
|
+
"@orpc/shared": "0.37.0"
|
66
66
|
},
|
67
67
|
"devDependencies": {
|
68
68
|
"@readme/openapi-parser": "^2.6.0",
|