@orpc/openapi 2.0.0-beta.46 → 2.0.0-beta.47
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 -3
- package/dist/adapters/aws-lambda/index.mjs +1 -1
- package/dist/adapters/fastify/index.mjs +1 -1
- package/dist/adapters/fetch/index.mjs +2 -2
- package/dist/adapters/node/index.mjs +1 -1
- package/dist/adapters/standard/index.d.mts +11 -3
- package/dist/adapters/standard/index.d.ts +11 -3
- package/dist/adapters/standard/index.mjs +2 -2
- package/dist/index.d.mts +10 -3
- package/dist/index.d.ts +10 -3
- package/dist/index.mjs +9 -7
- package/dist/shared/{openapi.BNe1y1cD.mjs → openapi.CQkXu1nY.mjs} +12 -6
- package/dist/shared/{openapi.BCrrWRbv.d.mts → openapi.DfmCR1pB.d.mts} +9 -2
- package/dist/shared/{openapi.BkjX_6hE.d.ts → openapi.Y4K_-I5W.d.ts} +9 -2
- package/dist/shared/{openapi.DXqJL3gB.mjs → openapi.g7ucL05o.mjs} +6 -4
- package/dist/shared/{openapi.B_SoJfYz.d.mts → openapi.zGZlCOwp.d.mts} +4 -3
- package/dist/shared/{openapi.B_SoJfYz.d.ts → openapi.zGZlCOwp.d.ts} +4 -3
- package/package.json +11 -11
package/README.md
CHANGED
|
@@ -156,10 +156,11 @@ Like what we build over at [middleapi](https://github.com/middleapi)? You can he
|
|
|
156
156
|
<td align="center"><a href="https://github.com/christ12938?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="christ12938"><img src="https://avatars.githubusercontent.com/u/25758598?v=4" width="167" alt="christ12938"/><br />christ12938</a></td>
|
|
157
157
|
<td align="center"><a href="https://github.com/Ryanjso?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Ryan Soderberg"><img src="https://avatars.githubusercontent.com/u/39172778?u=5ed913c31d57e7221b75784abcad48c7ebddde27&v=4" width="167" alt="Ryan Soderberg"/><br />Ryan Soderberg</a></td>
|
|
158
158
|
<td align="center"><a href="https://github.com/itigoore01?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="shota"><img src="https://avatars.githubusercontent.com/u/11831107?u=c976a6dc7e055eb026304c46c99100ed22b0c8e0&v=4" width="167" alt="shota"/><br />shota</a></td>
|
|
159
|
+
<td align="center"><a href="https://github.com/Nic13Gamer?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Nicholas"><img src="https://avatars.githubusercontent.com/u/54724556?u=56a7ab430ce7a80d648ab6eba051d454a818ed0b&v=4" width="167" alt="Nicholas"/><br />Nicholas</a></td>
|
|
159
160
|
<td align="center"><a href="https://github.com/ellis-driscoll?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Ellis Driscoll"><img src="https://avatars.githubusercontent.com/u/70685966?u=c5f95bc33b5991d9744abe00052542e4a2ed3cb9&v=4" width="167" alt="Ellis Driscoll"/><br />Ellis Driscoll</a></td>
|
|
160
|
-
<td align="center"><a href="https://github.com/hoangbn?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Hoang Nguyen"><img src="https://avatars.githubusercontent.com/u/38968280?u=c90084c6de65c56facabab7ba13a72a49ddbc3e4&v=4" width="167" alt="Hoang Nguyen"/><br />Hoang Nguyen</a></td>
|
|
161
161
|
</tr>
|
|
162
162
|
<tr>
|
|
163
|
+
<td align="center"><a href="https://github.com/hoangbn?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Hoang Nguyen"><img src="https://avatars.githubusercontent.com/u/38968280?u=c90084c6de65c56facabab7ba13a72a49ddbc3e4&v=4" width="167" alt="Hoang Nguyen"/><br />Hoang Nguyen</a></td>
|
|
163
164
|
<td align="center"><a href="https://opencollective.com/guest-ac41de3b?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Orestis Ioannou"><img src="https://images.opencollective.com/guest-ac41de3b/avatar/460.png" width="167" alt="Orestis Ioannou"/><br />Orestis Ioannou</a></td>
|
|
164
165
|
<td align="center"><a href="https://automatio.ai/?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Stefan Smiljkovic"><img src="https://avatars.githubusercontent.com/u/1984909?u=b7bf5bc40ed49df3c22f69d2da7b8d78709c49ed&v=4" width="167" alt="Stefan Smiljkovic"/><br />Stefan Smiljkovic</a></td>
|
|
165
166
|
</tr>
|
|
@@ -198,7 +199,7 @@ Like what we build over at [middleapi](https://github.com/middleapi)? You can he
|
|
|
198
199
|
</tr>
|
|
199
200
|
</table>
|
|
200
201
|
|
|
201
|
-
With thanks to [
|
|
202
|
+
With thanks to [39 past sponsors](https://orpc.dev/sponsors#past-sponsors) who helped get oRPC here.
|
|
202
203
|
|
|
203
204
|
## Open Source Programs
|
|
204
205
|
|
|
@@ -206,7 +207,9 @@ With thanks to [40 past sponsors](https://orpc.dev/sponsors#past-sponsors) who h
|
|
|
206
207
|
|
|
207
208
|
<table>
|
|
208
209
|
<tr>
|
|
209
|
-
<td align="center"><a href="https://claude.com/contact-sales/claude-for-oss" target="_blank" rel="noopener" title="Claude for Open Source"><img src="https://cdn.simpleicons.org/claude" width="64" alt="Claude"/><br />Claude
|
|
210
|
+
<td align="center"><a href="https://claude.com/contact-sales/claude-for-oss" target="_blank" rel="noopener" title="Claude for Open Source"><img src="https://cdn.simpleicons.org/claude" width="64" alt="Claude"/><br />Claude</a></td>
|
|
211
|
+
<td align="center"><a href="https://pullfrog.com/for-oss" target="_blank" rel="noopener" title="Pullfrog for OSS"><img src="https://avatars.githubusercontent.com/in/1768019?s=128&v=4" width="64" alt="Pullfrog"/><br />Pullfrog</a></td>
|
|
212
|
+
<td align="center"><a href="https://macroscope.com/open-source" target="_blank" rel="noopener" title="Macroscope for Open Source"><img src="https://avatars.githubusercontent.com/in/900172?s=128&v=4" width="64" alt="Macroscope"/><br />Macroscope</a></td>
|
|
210
213
|
</tr>
|
|
211
214
|
</table>
|
|
212
215
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AwsLambdaHandler } from '@orpc/server/aws-lambda';
|
|
2
2
|
import { StandardHandler } from '@orpc/server/standard';
|
|
3
|
-
import { O as OpenAPIHandlerCodec } from '../../shared/openapi.
|
|
3
|
+
import { O as OpenAPIHandlerCodec } from '../../shared/openapi.g7ucL05o.mjs';
|
|
4
4
|
import '@orpc/client';
|
|
5
5
|
import '@orpc/server';
|
|
6
6
|
import '@orpc/shared';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { FastifyHandler } from '@orpc/server/fastify';
|
|
2
2
|
import { StandardHandler } from '@orpc/server/standard';
|
|
3
|
-
import { O as OpenAPIHandlerCodec } from '../../shared/openapi.
|
|
3
|
+
import { O as OpenAPIHandlerCodec } from '../../shared/openapi.g7ucL05o.mjs';
|
|
4
4
|
import '@orpc/client';
|
|
5
5
|
import '@orpc/server';
|
|
6
6
|
import '@orpc/shared';
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { FetchHandler } from '@orpc/server/fetch';
|
|
2
2
|
import { StandardHandler } from '@orpc/server/standard';
|
|
3
|
-
import { O as OpenAPIHandlerCodec } from '../../shared/openapi.
|
|
3
|
+
import { O as OpenAPIHandlerCodec } from '../../shared/openapi.g7ucL05o.mjs';
|
|
4
4
|
import { FetchLinkTransport } from '@orpc/client/fetch';
|
|
5
5
|
import { StandardLink } from '@orpc/client/standard';
|
|
6
|
-
import { O as OpenAPILinkCodec } from '../../shared/openapi.
|
|
6
|
+
import { O as OpenAPILinkCodec } from '../../shared/openapi.CQkXu1nY.mjs';
|
|
7
7
|
import '@orpc/client';
|
|
8
8
|
import '@orpc/server';
|
|
9
9
|
import '@orpc/shared';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NodeHttpHandler } from '@orpc/server/node';
|
|
2
2
|
import { StandardHandler } from '@orpc/server/standard';
|
|
3
|
-
import { O as OpenAPIHandlerCodec } from '../../shared/openapi.
|
|
3
|
+
import { O as OpenAPIHandlerCodec } from '../../shared/openapi.g7ucL05o.mjs';
|
|
4
4
|
import '@orpc/client';
|
|
5
5
|
import '@orpc/server';
|
|
6
6
|
import '@orpc/shared';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { a as OpenAPIHandlerCodec, b as OpenAPIHandlerCodecCore, c as OpenAPIHandlerCodecCoreOptions, O as OpenAPIHandlerCodecOptions, d as OpenAPIMatcher, e as OpenAPIMatcherOptions } from '../../shared/openapi.
|
|
1
|
+
export { a as OpenAPIHandlerCodec, b as OpenAPIHandlerCodecCore, c as OpenAPIHandlerCodecCoreOptions, O as OpenAPIHandlerCodecOptions, d as OpenAPIMatcher, e as OpenAPIMatcherOptions } from '../../shared/openapi.DfmCR1pB.mjs';
|
|
2
2
|
import { ClientContext, ClientOptions, AnyORPCError } from '@orpc/client';
|
|
3
3
|
import { StandardLinkCodec, StandardLinkCodecDecodedResponse } from '@orpc/client/standard';
|
|
4
4
|
import { RouterContract } from '@orpc/contract';
|
|
@@ -28,14 +28,22 @@ interface OpenAPILinkCodecOptions<T extends ClientContext> {
|
|
|
28
28
|
* Customize how an error response body is converted into an ORPC error.
|
|
29
29
|
* Return `null` or `undefined` to fall back to the default decoding behavior.
|
|
30
30
|
*/
|
|
31
|
-
|
|
31
|
+
errorResponseBodyDecoder?: ((deserializedBody: unknown, response: StandardLazyResponse) => AnyORPCError | null | undefined) | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* Parse error responses with this `content-type` as JSON, ignoring case and parameters such as `charset`.
|
|
34
|
+
* Should match the handler's `errorResponseContentType`.
|
|
35
|
+
*
|
|
36
|
+
* @example 'application/problem+json'
|
|
37
|
+
*/
|
|
38
|
+
errorResponseContentType?: string | undefined;
|
|
32
39
|
}
|
|
33
40
|
declare class OpenAPILinkCodec<T extends ClientContext> implements StandardLinkCodec<T> {
|
|
34
41
|
private readonly router;
|
|
35
42
|
private readonly baseUrl;
|
|
36
43
|
private readonly headers;
|
|
37
44
|
private readonly serializer;
|
|
38
|
-
private readonly
|
|
45
|
+
private readonly errorResponseBodyDecoder;
|
|
46
|
+
private readonly errorResponseMediaType;
|
|
39
47
|
constructor(router: RouterContract, options?: OpenAPILinkCodecOptions<T>);
|
|
40
48
|
encodeInput(input: unknown, path: string[], options: ClientOptions<T>): Promise<StandardRequest>;
|
|
41
49
|
private encodePathParam;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { a as OpenAPIHandlerCodec, b as OpenAPIHandlerCodecCore, c as OpenAPIHandlerCodecCoreOptions, O as OpenAPIHandlerCodecOptions, d as OpenAPIMatcher, e as OpenAPIMatcherOptions } from '../../shared/openapi.
|
|
1
|
+
export { a as OpenAPIHandlerCodec, b as OpenAPIHandlerCodecCore, c as OpenAPIHandlerCodecCoreOptions, O as OpenAPIHandlerCodecOptions, d as OpenAPIMatcher, e as OpenAPIMatcherOptions } from '../../shared/openapi.Y4K_-I5W.js';
|
|
2
2
|
import { ClientContext, ClientOptions, AnyORPCError } from '@orpc/client';
|
|
3
3
|
import { StandardLinkCodec, StandardLinkCodecDecodedResponse } from '@orpc/client/standard';
|
|
4
4
|
import { RouterContract } from '@orpc/contract';
|
|
@@ -28,14 +28,22 @@ interface OpenAPILinkCodecOptions<T extends ClientContext> {
|
|
|
28
28
|
* Customize how an error response body is converted into an ORPC error.
|
|
29
29
|
* Return `null` or `undefined` to fall back to the default decoding behavior.
|
|
30
30
|
*/
|
|
31
|
-
|
|
31
|
+
errorResponseBodyDecoder?: ((deserializedBody: unknown, response: StandardLazyResponse) => AnyORPCError | null | undefined) | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* Parse error responses with this `content-type` as JSON, ignoring case and parameters such as `charset`.
|
|
34
|
+
* Should match the handler's `errorResponseContentType`.
|
|
35
|
+
*
|
|
36
|
+
* @example 'application/problem+json'
|
|
37
|
+
*/
|
|
38
|
+
errorResponseContentType?: string | undefined;
|
|
32
39
|
}
|
|
33
40
|
declare class OpenAPILinkCodec<T extends ClientContext> implements StandardLinkCodec<T> {
|
|
34
41
|
private readonly router;
|
|
35
42
|
private readonly baseUrl;
|
|
36
43
|
private readonly headers;
|
|
37
44
|
private readonly serializer;
|
|
38
|
-
private readonly
|
|
45
|
+
private readonly errorResponseBodyDecoder;
|
|
46
|
+
private readonly errorResponseMediaType;
|
|
39
47
|
constructor(router: RouterContract, options?: OpenAPILinkCodecOptions<T>);
|
|
40
48
|
encodeInput(input: unknown, path: string[], options: ClientOptions<T>): Promise<StandardRequest>;
|
|
41
49
|
private encodePathParam;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { O as OpenAPIHandlerCodec, a as OpenAPIHandlerCodecCore, b as OpenAPIMatcher } from '../../shared/openapi.
|
|
2
|
-
export { O as OpenAPILinkCodec } from '../../shared/openapi.
|
|
1
|
+
export { O as OpenAPIHandlerCodec, a as OpenAPIHandlerCodecCore, b as OpenAPIMatcher } from '../../shared/openapi.g7ucL05o.mjs';
|
|
2
|
+
export { O as OpenAPILinkCodec } from '../../shared/openapi.CQkXu1nY.mjs';
|
|
3
3
|
import '@orpc/client';
|
|
4
4
|
import '@orpc/server';
|
|
5
5
|
import '@orpc/shared';
|
package/dist/index.d.mts
CHANGED
|
@@ -5,7 +5,7 @@ export { COMMON_ERROR_STATUS_MAP } from '@orpc/client';
|
|
|
5
5
|
import { RouterContract, RouterContractClient, AnyProcedureContract, ProcedureContract } from '@orpc/contract';
|
|
6
6
|
import { J as JsonifiedClient, a as OpenAPIVersion, O as OpenAPIDocument } from './shared/openapi.Covi8zVE.mjs';
|
|
7
7
|
export { b as JsonifiedArray, c as JsonifiedClientError, d as JsonifiedValue } from './shared/openapi.Covi8zVE.mjs';
|
|
8
|
-
export { a as OpenAPIFunction, O as OpenAPIMeta, b as OpenAPIMetaPlugin, c as OpenAPIMethodMetaPlugin, d as OpenAPIPathMetaPlugin, e as OpenAPIPrefixMetaPlugin, f as OpenAPISpecMetaPlugin, g as getOpenAPIMeta, o as openapi } from './shared/openapi.
|
|
8
|
+
export { a as OpenAPIFunction, O as OpenAPIMeta, b as OpenAPIMetaPlugin, c as OpenAPIMethodMetaPlugin, d as OpenAPIPathMetaPlugin, e as OpenAPIPrefixMetaPlugin, f as OpenAPISpecMetaPlugin, g as getOpenAPIMeta, o as openapi } from './shared/openapi.zGZlCOwp.mjs';
|
|
9
9
|
import { JsonSchema, JsonSchemaConverter } from '@orpc/json-schema';
|
|
10
10
|
export { JsonSchema } from '@orpc/json-schema';
|
|
11
11
|
import { AnyRouter, AnyProcedure } from '@orpc/server';
|
|
@@ -93,7 +93,7 @@ interface OpenAPIGeneratorGenerateOptions<TVersion extends OpenAPIVersion> {
|
|
|
93
93
|
*
|
|
94
94
|
* @default defName => defName
|
|
95
95
|
*/
|
|
96
|
-
|
|
96
|
+
componentName?: ((defName: string, defSchema: JsonSchema) => string | undefined) | undefined;
|
|
97
97
|
/**
|
|
98
98
|
* Filter procedures. Return `false` to exclude a procedure from the OpenAPI specification.
|
|
99
99
|
*
|
|
@@ -109,10 +109,17 @@ interface OpenAPIGeneratorGenerateOptions<TVersion extends OpenAPIVersion> {
|
|
|
109
109
|
* - Return `null | undefined` to use the default error response body shaper.
|
|
110
110
|
* - The schema is an OpenAPI 3.2 Schema Object, it is downgraded with the rest of the document when an older `version` is requested.
|
|
111
111
|
*/
|
|
112
|
-
|
|
112
|
+
errorResponseBodySchema?: Value<JsonSchema | undefined | null, [
|
|
113
113
|
definedErrors: OpenAPIErrorBodyDefinition[],
|
|
114
114
|
status: number
|
|
115
115
|
]> | undefined;
|
|
116
|
+
/**
|
|
117
|
+
* Media type of error responses in the generated document, e.g. `application/problem+json`.
|
|
118
|
+
* Should match the handler's `errorResponseContentType`.
|
|
119
|
+
*
|
|
120
|
+
* @default 'application/json'
|
|
121
|
+
*/
|
|
122
|
+
errorResponseContentType?: string | undefined;
|
|
116
123
|
/**
|
|
117
124
|
* Mapping ORPCError Code -> HTTP Status Code
|
|
118
125
|
* Codes missing from the map fall back to `DEFAULT_ERROR_STATUS` (400).
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export { COMMON_ERROR_STATUS_MAP } from '@orpc/client';
|
|
|
5
5
|
import { RouterContract, RouterContractClient, AnyProcedureContract, ProcedureContract } from '@orpc/contract';
|
|
6
6
|
import { J as JsonifiedClient, a as OpenAPIVersion, O as OpenAPIDocument } from './shared/openapi.Covi8zVE.js';
|
|
7
7
|
export { b as JsonifiedArray, c as JsonifiedClientError, d as JsonifiedValue } from './shared/openapi.Covi8zVE.js';
|
|
8
|
-
export { a as OpenAPIFunction, O as OpenAPIMeta, b as OpenAPIMetaPlugin, c as OpenAPIMethodMetaPlugin, d as OpenAPIPathMetaPlugin, e as OpenAPIPrefixMetaPlugin, f as OpenAPISpecMetaPlugin, g as getOpenAPIMeta, o as openapi } from './shared/openapi.
|
|
8
|
+
export { a as OpenAPIFunction, O as OpenAPIMeta, b as OpenAPIMetaPlugin, c as OpenAPIMethodMetaPlugin, d as OpenAPIPathMetaPlugin, e as OpenAPIPrefixMetaPlugin, f as OpenAPISpecMetaPlugin, g as getOpenAPIMeta, o as openapi } from './shared/openapi.zGZlCOwp.js';
|
|
9
9
|
import { JsonSchema, JsonSchemaConverter } from '@orpc/json-schema';
|
|
10
10
|
export { JsonSchema } from '@orpc/json-schema';
|
|
11
11
|
import { AnyRouter, AnyProcedure } from '@orpc/server';
|
|
@@ -93,7 +93,7 @@ interface OpenAPIGeneratorGenerateOptions<TVersion extends OpenAPIVersion> {
|
|
|
93
93
|
*
|
|
94
94
|
* @default defName => defName
|
|
95
95
|
*/
|
|
96
|
-
|
|
96
|
+
componentName?: ((defName: string, defSchema: JsonSchema) => string | undefined) | undefined;
|
|
97
97
|
/**
|
|
98
98
|
* Filter procedures. Return `false` to exclude a procedure from the OpenAPI specification.
|
|
99
99
|
*
|
|
@@ -109,10 +109,17 @@ interface OpenAPIGeneratorGenerateOptions<TVersion extends OpenAPIVersion> {
|
|
|
109
109
|
* - Return `null | undefined` to use the default error response body shaper.
|
|
110
110
|
* - The schema is an OpenAPI 3.2 Schema Object, it is downgraded with the rest of the document when an older `version` is requested.
|
|
111
111
|
*/
|
|
112
|
-
|
|
112
|
+
errorResponseBodySchema?: Value<JsonSchema | undefined | null, [
|
|
113
113
|
definedErrors: OpenAPIErrorBodyDefinition[],
|
|
114
114
|
status: number
|
|
115
115
|
]> | undefined;
|
|
116
|
+
/**
|
|
117
|
+
* Media type of error responses in the generated document, e.g. `application/problem+json`.
|
|
118
|
+
* Should match the handler's `errorResponseContentType`.
|
|
119
|
+
*
|
|
120
|
+
* @default 'application/json'
|
|
121
|
+
*/
|
|
122
|
+
errorResponseContentType?: string | undefined;
|
|
116
123
|
/**
|
|
117
124
|
* Mapping ORPCError Code -> HTTP Status Code
|
|
118
125
|
* Codes missing from the map fall back to `DEFAULT_ERROR_STATUS` (400).
|
package/dist/index.mjs
CHANGED
|
@@ -18,9 +18,9 @@ function createContractJsonifiedClientFactory(link, options = {}) {
|
|
|
18
18
|
const DEFS_REF_PREFIX = "#/$defs/";
|
|
19
19
|
const COMPONENTS_REF_PREFIX = "#/components/schemas/";
|
|
20
20
|
class OpenAPIComponentRegistry {
|
|
21
|
-
constructor(doc,
|
|
21
|
+
constructor(doc, componentName) {
|
|
22
22
|
this.doc = doc;
|
|
23
|
-
this.
|
|
23
|
+
this.componentName = componentName;
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
26
26
|
* Registers `schema` as a component under `preferredName` (or an equivalent/postfixed name)
|
|
@@ -68,7 +68,7 @@ class OpenAPIComponentRegistry {
|
|
|
68
68
|
componentsSchemas,
|
|
69
69
|
new Set(renameMap.values()),
|
|
70
70
|
defName,
|
|
71
|
-
this.
|
|
71
|
+
this.componentName?.(defName, cleanSchema) ?? defName,
|
|
72
72
|
defs,
|
|
73
73
|
direction
|
|
74
74
|
);
|
|
@@ -366,6 +366,7 @@ function renderQueryParameters(ctx, operation, queryEntries, queryStyles) {
|
|
|
366
366
|
"application/json": { schema: parameter.schema }
|
|
367
367
|
};
|
|
368
368
|
delete parameter.schema;
|
|
369
|
+
delete parameter.allowReserved;
|
|
369
370
|
} else if (style === void 0) {
|
|
370
371
|
if (flattenJsonUnionSchema(schema).some((s) => !isJsonPrimitiveSchema(s))) {
|
|
371
372
|
const arrayable = matchArrayableJsonSchema(schema);
|
|
@@ -537,7 +538,7 @@ function buildErrorResponse(ctx, operation, def) {
|
|
|
537
538
|
for (const [status, definitions] of definitionsByStatus.entries()) {
|
|
538
539
|
const descriptions = definitions.map(({ defaultMessage }) => defaultMessage).filter((m) => m !== void 0);
|
|
539
540
|
const customBodySchema = value(
|
|
540
|
-
ctx.
|
|
541
|
+
ctx.errorResponseBodySchema,
|
|
541
542
|
definitions.map((def2) => ({ ...def2, dataJsonSchema: ctx.registry.hoistDefs(def2.dataJsonSchema, "output") })),
|
|
542
543
|
status
|
|
543
544
|
);
|
|
@@ -560,7 +561,7 @@ function buildErrorResponse(ctx, operation, def) {
|
|
|
560
561
|
operation.responses[toResponseStatusKey(status)] = {
|
|
561
562
|
description: descriptions.length ? descriptions.join(", ") : status.toString(),
|
|
562
563
|
content: {
|
|
563
|
-
|
|
564
|
+
[ctx.errorResponseContentType]: {
|
|
564
565
|
schema: ctx.registry.toOpenAPISchema(responseSchema, "output")
|
|
565
566
|
}
|
|
566
567
|
}
|
|
@@ -657,10 +658,11 @@ class OpenAPIGenerator {
|
|
|
657
658
|
info: options.base?.info ?? { title: "API Reference", version: "0.0.0" }
|
|
658
659
|
};
|
|
659
660
|
const ctx = {
|
|
660
|
-
registry: new OpenAPIComponentRegistry(doc, options.
|
|
661
|
+
registry: new OpenAPIComponentRegistry(doc, options.componentName),
|
|
661
662
|
convertSchemas: (schemas, direction) => this.convertSchemas(schemas, direction),
|
|
662
663
|
errorStatusMap: options.errorStatusMap ?? COMMON_ERROR_STATUS_MAP,
|
|
663
|
-
|
|
664
|
+
errorResponseBodySchema: options.errorResponseBodySchema,
|
|
665
|
+
errorResponseContentType: options.errorResponseContentType ?? "application/json"
|
|
664
666
|
};
|
|
665
667
|
const errors = [];
|
|
666
668
|
await walkProcedureContractsAsync(router, (contract, path) => {
|
|
@@ -2,11 +2,11 @@ import { MalformedResponseError, isORPCErrorJson, createORPCErrorFromJson, Respo
|
|
|
2
2
|
import { getRouterContract, ProcedureContract } from '@orpc/contract';
|
|
3
3
|
import { unlazy } from '@orpc/server';
|
|
4
4
|
import { value, pathToHttpPath, mergeHttpPath, isTypescriptObject, stringifyJSON, safeEncodeURIComponent } from '@orpc/shared';
|
|
5
|
-
import { mergeStandardHeaders, parseStandardUrl } from '@standard-server/core';
|
|
5
|
+
import { mergeStandardHeaders, parseStandardUrl, flattenStandardHeader } from '@standard-server/core';
|
|
6
6
|
import { toStandardHeaders } from '@standard-server/fetch';
|
|
7
7
|
import { O as OpenAPISerializer, D as DEFAULT_OPENAPI_METHOD, a as DEFAULT_OPENAPI_INPUT_STRUCTURE, g as getDynamicPathParams, i as isBodylessMethod, b as DEFAULT_OPENAPI_OUTPUT_STRUCTURE } from './openapi.E3ZBiweM.mjs';
|
|
8
8
|
import { g as getOpenAPIMeta } from './openapi.B9PQzqBn.mjs';
|
|
9
|
-
import { s as serializeHeaders } from './openapi.
|
|
9
|
+
import { s as serializeHeaders } from './openapi.g7ucL05o.mjs';
|
|
10
10
|
|
|
11
11
|
const END_SLASH_REGEX = /\/$/;
|
|
12
12
|
const DOT_SEGMENT_REGEX = /(?:^|\/)\.{1,2}(?:\/|$)/;
|
|
@@ -16,12 +16,14 @@ class OpenAPILinkCodec {
|
|
|
16
16
|
this.baseUrl = options.url ?? "/";
|
|
17
17
|
this.headers = options.headers ?? {};
|
|
18
18
|
this.serializer = options.serializer ?? new OpenAPISerializer();
|
|
19
|
-
this.
|
|
19
|
+
this.errorResponseBodyDecoder = options.errorResponseBodyDecoder;
|
|
20
|
+
this.errorResponseMediaType = toMediaType(options.errorResponseContentType);
|
|
20
21
|
}
|
|
21
22
|
baseUrl;
|
|
22
23
|
headers;
|
|
23
24
|
serializer;
|
|
24
|
-
|
|
25
|
+
errorResponseBodyDecoder;
|
|
26
|
+
errorResponseMediaType;
|
|
25
27
|
async encodeInput(input, path, options) {
|
|
26
28
|
let headers = toResolvedStandardHeaders(await value(this.headers, options, path, input));
|
|
27
29
|
if (options.lastEventId !== void 0) {
|
|
@@ -252,7 +254,8 @@ class OpenAPILinkCodec {
|
|
|
252
254
|
const isOk = response.status < 400;
|
|
253
255
|
const procedure = await this.resolveProcedure(path);
|
|
254
256
|
const meta = getOpenAPIMeta(procedure);
|
|
255
|
-
const
|
|
257
|
+
const errorBodyHint = !isOk && this.errorResponseMediaType !== void 0 && toMediaType(flattenStandardHeader(response.headers["content-type"])) === this.errorResponseMediaType ? "json" : void 0;
|
|
258
|
+
const body = await response.resolveBody(isOk ? meta?.responseBodyHint : errorBodyHint);
|
|
256
259
|
const deserialized = await (async () => {
|
|
257
260
|
try {
|
|
258
261
|
return this.serializer.deserialize(body);
|
|
@@ -265,7 +268,7 @@ class OpenAPILinkCodec {
|
|
|
265
268
|
}
|
|
266
269
|
})();
|
|
267
270
|
if (!isOk) {
|
|
268
|
-
const customError = this.
|
|
271
|
+
const customError = this.errorResponseBodyDecoder?.(deserialized, response);
|
|
269
272
|
if (customError !== void 0 && customError !== null) {
|
|
270
273
|
return { kind: "error", error: customError };
|
|
271
274
|
}
|
|
@@ -309,6 +312,9 @@ function combineSearch(baseSearch, additionalSearch) {
|
|
|
309
312
|
}
|
|
310
313
|
return `${baseSearch}&${additionalSearch}`;
|
|
311
314
|
}
|
|
315
|
+
function toMediaType(contentType) {
|
|
316
|
+
return contentType?.split(";")[0]?.trim().toLowerCase();
|
|
317
|
+
}
|
|
312
318
|
function toResolvedStandardHeaders(headers) {
|
|
313
319
|
if (typeof headers.forEach === "function") {
|
|
314
320
|
return toStandardHeaders(headers);
|
|
@@ -56,12 +56,19 @@ interface OpenAPIHandlerCodecCoreOptions<_T extends Context> {
|
|
|
56
56
|
*
|
|
57
57
|
* @default ((e) => e.toJSON())
|
|
58
58
|
*/
|
|
59
|
-
|
|
59
|
+
errorResponseBodyEncoder?: ((error: AnyORPCError) => unknown) | undefined;
|
|
60
|
+
/**
|
|
61
|
+
* The `content-type` of error responses, e.g. `application/problem+json` for RFC 9457 Problem Details.
|
|
62
|
+
*
|
|
63
|
+
* @default 'application/json'
|
|
64
|
+
*/
|
|
65
|
+
errorResponseContentType?: string | undefined;
|
|
60
66
|
}
|
|
61
67
|
declare class OpenAPIHandlerCodecCore<T extends Context> {
|
|
62
68
|
private readonly serializer;
|
|
63
69
|
private readonly errorStatusMap;
|
|
64
|
-
private readonly
|
|
70
|
+
private readonly errorResponseBodyEncoder;
|
|
71
|
+
private readonly errorResponseContentType;
|
|
65
72
|
constructor(options?: OpenAPIHandlerCodecCoreOptions<T>);
|
|
66
73
|
decodeInput(matched: {
|
|
67
74
|
procedure: AnyProcedure;
|
|
@@ -56,12 +56,19 @@ interface OpenAPIHandlerCodecCoreOptions<_T extends Context> {
|
|
|
56
56
|
*
|
|
57
57
|
* @default ((e) => e.toJSON())
|
|
58
58
|
*/
|
|
59
|
-
|
|
59
|
+
errorResponseBodyEncoder?: ((error: AnyORPCError) => unknown) | undefined;
|
|
60
|
+
/**
|
|
61
|
+
* The `content-type` of error responses, e.g. `application/problem+json` for RFC 9457 Problem Details.
|
|
62
|
+
*
|
|
63
|
+
* @default 'application/json'
|
|
64
|
+
*/
|
|
65
|
+
errorResponseContentType?: string | undefined;
|
|
60
66
|
}
|
|
61
67
|
declare class OpenAPIHandlerCodecCore<T extends Context> {
|
|
62
68
|
private readonly serializer;
|
|
63
69
|
private readonly errorStatusMap;
|
|
64
|
-
private readonly
|
|
70
|
+
private readonly errorResponseBodyEncoder;
|
|
71
|
+
private readonly errorResponseContentType;
|
|
65
72
|
constructor(options?: OpenAPIHandlerCodecCoreOptions<T>);
|
|
66
73
|
decodeInput(matched: {
|
|
67
74
|
procedure: AnyProcedure;
|
|
@@ -218,11 +218,13 @@ function serializeHeaderValue(value, serializer) {
|
|
|
218
218
|
class OpenAPIHandlerCodecCore {
|
|
219
219
|
serializer;
|
|
220
220
|
errorStatusMap;
|
|
221
|
-
|
|
221
|
+
errorResponseBodyEncoder;
|
|
222
|
+
errorResponseContentType;
|
|
222
223
|
constructor(options = {}) {
|
|
223
224
|
this.serializer = options.serializer ?? new OpenAPISerializer();
|
|
224
225
|
this.errorStatusMap = options.errorStatusMap ?? COMMON_ERROR_STATUS_MAP;
|
|
225
|
-
this.
|
|
226
|
+
this.errorResponseBodyEncoder = options.errorResponseBodyEncoder;
|
|
227
|
+
this.errorResponseContentType = options.errorResponseContentType;
|
|
226
228
|
}
|
|
227
229
|
async decodeInput(matched, request) {
|
|
228
230
|
const meta = getOpenAPIMeta(matched.procedure);
|
|
@@ -288,8 +290,8 @@ class OpenAPIHandlerCodecCore {
|
|
|
288
290
|
const status = getOwn(this.errorStatusMap, error.code) ?? DEFAULT_ERROR_STATUS;
|
|
289
291
|
return {
|
|
290
292
|
status,
|
|
291
|
-
headers: {},
|
|
292
|
-
body: this.serializer.serialize(this.
|
|
293
|
+
headers: this.errorResponseContentType !== void 0 ? { "content-type": this.errorResponseContentType } : {},
|
|
294
|
+
body: this.serializer.serialize(this.errorResponseBodyEncoder?.(error) ?? error.toJSON())
|
|
293
295
|
};
|
|
294
296
|
}
|
|
295
297
|
deserializeQuery(url, styles) {
|
|
@@ -159,7 +159,7 @@ interface OpenAPIMeta {
|
|
|
159
159
|
/**
|
|
160
160
|
* Hint for how to parse the incoming request body.
|
|
161
161
|
*
|
|
162
|
-
* Note:
|
|
162
|
+
* Note: This option takes priority over the `standard-server` and `Content-Type` headers.
|
|
163
163
|
* `form-data` and `url-search-params` are decoded using bracket notation,
|
|
164
164
|
* so the resulting value will be an object or array.
|
|
165
165
|
*
|
|
@@ -167,9 +167,10 @@ interface OpenAPIMeta {
|
|
|
167
167
|
*/
|
|
168
168
|
requestBodyHint?: StandardBodyHint | undefined;
|
|
169
169
|
/**
|
|
170
|
-
* Hint for how to parse
|
|
170
|
+
* Hint for how to parse a successful response body (status below 400).
|
|
171
|
+
* Error response bodies are always parsed from their headers.
|
|
171
172
|
*
|
|
172
|
-
* Note:
|
|
173
|
+
* Note: This option takes priority over the `standard-server` and `Content-Type` headers.
|
|
173
174
|
* `form-data` and `url-search-params` are decoded using bracket notation,
|
|
174
175
|
* so the resulting value will be an object or array.
|
|
175
176
|
*
|
|
@@ -159,7 +159,7 @@ interface OpenAPIMeta {
|
|
|
159
159
|
/**
|
|
160
160
|
* Hint for how to parse the incoming request body.
|
|
161
161
|
*
|
|
162
|
-
* Note:
|
|
162
|
+
* Note: This option takes priority over the `standard-server` and `Content-Type` headers.
|
|
163
163
|
* `form-data` and `url-search-params` are decoded using bracket notation,
|
|
164
164
|
* so the resulting value will be an object or array.
|
|
165
165
|
*
|
|
@@ -167,9 +167,10 @@ interface OpenAPIMeta {
|
|
|
167
167
|
*/
|
|
168
168
|
requestBodyHint?: StandardBodyHint | undefined;
|
|
169
169
|
/**
|
|
170
|
-
* Hint for how to parse
|
|
170
|
+
* Hint for how to parse a successful response body (status below 400).
|
|
171
|
+
* Error response bodies are always parsed from their headers.
|
|
171
172
|
*
|
|
172
|
-
* Note:
|
|
173
|
+
* Note: This option takes priority over the `standard-server` and `Content-Type` headers.
|
|
173
174
|
* `form-data` and `url-search-params` are decoded using bracket notation,
|
|
174
175
|
* so the resulting value will be an object or array.
|
|
175
176
|
*
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/openapi",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.0.0-beta.
|
|
4
|
+
"version": "2.0.0-beta.47",
|
|
5
5
|
"description": "Generate OpenAPI specs from oRPC routers and serve OpenAPI-compliant APIs with end-to-end type safety",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"funding": [
|
|
@@ -97,20 +97,20 @@
|
|
|
97
97
|
}
|
|
98
98
|
},
|
|
99
99
|
"dependencies": {
|
|
100
|
-
"@openapi-spec/downgrader": "~0.
|
|
101
|
-
"@openapi-spec/types": "~0.
|
|
102
|
-
"@orpc/client": "2.0.0-beta.
|
|
103
|
-
"@orpc/contract": "2.0.0-beta.
|
|
104
|
-
"@orpc/json-schema": "2.0.0-beta.
|
|
105
|
-
"@orpc/server": "2.0.0-beta.
|
|
106
|
-
"@orpc/shared": "2.0.0-beta.
|
|
107
|
-
"@standard-server/core": "~0.
|
|
108
|
-
"@standard-server/fetch": "~0.
|
|
100
|
+
"@openapi-spec/downgrader": "~0.4.0",
|
|
101
|
+
"@openapi-spec/types": "~0.4.0",
|
|
102
|
+
"@orpc/client": "2.0.0-beta.47",
|
|
103
|
+
"@orpc/contract": "2.0.0-beta.47",
|
|
104
|
+
"@orpc/json-schema": "2.0.0-beta.47",
|
|
105
|
+
"@orpc/server": "2.0.0-beta.47",
|
|
106
|
+
"@orpc/shared": "2.0.0-beta.47",
|
|
107
|
+
"@standard-server/core": "~0.13.0",
|
|
108
|
+
"@standard-server/fetch": "~0.13.0",
|
|
109
109
|
"rou3": "^1.0.0"
|
|
110
110
|
},
|
|
111
111
|
"devDependencies": {
|
|
112
112
|
"@scalar/api-reference": "^1.74.0",
|
|
113
|
-
"@standard-server/aws-lambda": "~0.
|
|
113
|
+
"@standard-server/aws-lambda": "~0.13.0",
|
|
114
114
|
"@types/swagger-ui": "^5.32.0",
|
|
115
115
|
"fastify": "^5.12.7",
|
|
116
116
|
"swagger-ui": "^5.33.2",
|