@orpc/openapi 0.0.0-next.3b1cf14 → 0.0.0-next.3f6c426
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.
|
@@ -351,46 +351,58 @@ var OpenAPIPayloadCodec = class {
|
|
|
351
351
|
};
|
|
352
352
|
}
|
|
353
353
|
async decode(re) {
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
const contentType = re.headers.get("content-type");
|
|
358
|
-
const contentDisposition = re.headers.get("content-disposition");
|
|
359
|
-
const fileName = contentDisposition ? cd.parse(contentDisposition).parameters.filename : void 0;
|
|
360
|
-
if (fileName) {
|
|
361
|
-
const blob2 = await re.blob();
|
|
362
|
-
const file = new File([blob2], fileName, {
|
|
363
|
-
type: blob2.type
|
|
364
|
-
});
|
|
365
|
-
return file;
|
|
366
|
-
}
|
|
367
|
-
if (!contentType || contentType.startsWith("application/json")) {
|
|
368
|
-
if (!re.body) {
|
|
369
|
-
return void 0;
|
|
354
|
+
try {
|
|
355
|
+
if (re instanceof Headers || re instanceof URLSearchParams || re instanceof FormData) {
|
|
356
|
+
return deserialize([...re.entries()]);
|
|
370
357
|
}
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
358
|
+
const contentType = re.headers.get("content-type");
|
|
359
|
+
const contentDisposition = re.headers.get("content-disposition");
|
|
360
|
+
const fileName = contentDisposition ? cd.parse(contentDisposition).parameters.filename : void 0;
|
|
361
|
+
if (fileName) {
|
|
362
|
+
const blob2 = await re.blob();
|
|
363
|
+
const file = new File([blob2], fileName, {
|
|
364
|
+
type: blob2.type
|
|
365
|
+
});
|
|
366
|
+
return file;
|
|
367
|
+
}
|
|
368
|
+
if (!contentType || contentType.startsWith("application/json")) {
|
|
369
|
+
if (!re.body) {
|
|
370
|
+
return void 0;
|
|
371
|
+
}
|
|
372
|
+
const text = await re.text();
|
|
373
|
+
if (!text) {
|
|
374
|
+
return void 0;
|
|
375
|
+
}
|
|
376
|
+
return JSON.parse(text);
|
|
377
|
+
}
|
|
378
|
+
if (contentType.startsWith("application/x-www-form-urlencoded")) {
|
|
379
|
+
const params = new URLSearchParams(await re.text());
|
|
380
|
+
return this.decode(params);
|
|
381
|
+
}
|
|
382
|
+
if (contentType.startsWith("text/")) {
|
|
383
|
+
const text = await re.text();
|
|
384
|
+
return text;
|
|
385
|
+
}
|
|
386
|
+
if (contentType.startsWith("multipart/form-data")) {
|
|
387
|
+
const form = await re.formData();
|
|
388
|
+
return this.decode(form);
|
|
389
|
+
}
|
|
390
|
+
const blob = await re.blob();
|
|
391
|
+
return new File([blob], "blob", {
|
|
392
|
+
type: blob.type
|
|
393
|
+
});
|
|
394
|
+
} catch (e) {
|
|
395
|
+
throw new ORPCError({
|
|
396
|
+
code: "BAD_REQUEST",
|
|
397
|
+
message: "Cannot parse request/response. Please check the request/response body and Content-Type header.",
|
|
398
|
+
cause: e
|
|
399
|
+
});
|
|
384
400
|
}
|
|
385
|
-
const blob = await re.blob();
|
|
386
|
-
return new File([blob], "blob", {
|
|
387
|
-
type: blob.type
|
|
388
|
-
});
|
|
389
401
|
}
|
|
390
402
|
};
|
|
391
403
|
|
|
392
404
|
// src/adapters/fetch/openapi-procedure-matcher.ts
|
|
393
|
-
import { getLazyRouterPrefix, getRouterChild, isProcedure, unlazy } from "@orpc/server";
|
|
405
|
+
import { fallbackToGlobalConfig, getLazyRouterPrefix, getRouterChild, isProcedure, unlazy } from "@orpc/server";
|
|
394
406
|
import { mapValues } from "@orpc/shared";
|
|
395
407
|
var OpenAPIProcedureMatcher = class {
|
|
396
408
|
constructor(hono, router) {
|
|
@@ -434,7 +446,7 @@ var OpenAPIProcedureMatcher = class {
|
|
|
434
446
|
}
|
|
435
447
|
add(path, router) {
|
|
436
448
|
const lazies = forEachContractProcedure({ path, router }, ({ path: path2, contract }) => {
|
|
437
|
-
const method = contract["~orpc"].route?.method
|
|
449
|
+
const method = fallbackToGlobalConfig("defaultMethod", contract["~orpc"].route?.method);
|
|
438
450
|
const httpPath = contract["~orpc"].route?.path ? this.convertOpenAPIPathToRouterPath(contract["~orpc"].route?.path) : `/${path2.map(encodeURIComponent).join("/")}`;
|
|
439
451
|
this.hono.add(method, httpPath, [httpPath, path2]);
|
|
440
452
|
});
|
|
@@ -473,7 +485,7 @@ var CompositeSchemaCoercer = class {
|
|
|
473
485
|
};
|
|
474
486
|
|
|
475
487
|
// src/adapters/fetch/openapi-handler.ts
|
|
476
|
-
import { createProcedureClient, ORPCError as ORPCError2 } from "@orpc/server";
|
|
488
|
+
import { createProcedureClient, fallbackToGlobalConfig as fallbackToGlobalConfig2, ORPCError as ORPCError2 } from "@orpc/server";
|
|
477
489
|
import { executeWithHooks, isPlainObject as isPlainObject3, ORPC_HANDLER_HEADER, trim } from "@orpc/shared";
|
|
478
490
|
var OpenAPIHandler = class {
|
|
479
491
|
constructor(hono, router, options) {
|
|
@@ -519,7 +531,7 @@ var OpenAPIHandler = class {
|
|
|
519
531
|
const { body, headers: resHeaders } = this.encodeOutput(matched.procedure, output, accept);
|
|
520
532
|
return new Response(body, {
|
|
521
533
|
headers: resHeaders,
|
|
522
|
-
status: contractDef.route?.successStatus
|
|
534
|
+
status: fallbackToGlobalConfig2("defaultSuccessStatus", contractDef.route?.successStatus)
|
|
523
535
|
});
|
|
524
536
|
};
|
|
525
537
|
try {
|
|
@@ -551,28 +563,26 @@ var OpenAPIHandler = class {
|
|
|
551
563
|
}
|
|
552
564
|
}
|
|
553
565
|
async decodeInput(procedure, params, request) {
|
|
554
|
-
const inputStructure = procedure["~orpc"].contract["~orpc"].route?.inputStructure;
|
|
566
|
+
const inputStructure = fallbackToGlobalConfig2("defaultInputStructure", procedure["~orpc"].contract["~orpc"].route?.inputStructure);
|
|
555
567
|
const url = new URL(request.url);
|
|
556
568
|
const query = url.searchParams;
|
|
557
569
|
const headers = request.headers;
|
|
558
|
-
if (
|
|
570
|
+
if (inputStructure === "compact") {
|
|
559
571
|
return this.inputStructureCompact.build(
|
|
560
572
|
params,
|
|
561
573
|
request.method === "GET" ? await this.payloadCodec.decode(query) : await this.payloadCodec.decode(request)
|
|
562
574
|
);
|
|
563
575
|
}
|
|
564
|
-
const _expect = inputStructure;
|
|
565
576
|
const decodedQuery = await this.payloadCodec.decode(query);
|
|
566
577
|
const decodedHeaders = await this.payloadCodec.decode(headers);
|
|
567
578
|
const decodedBody = await this.payloadCodec.decode(request);
|
|
568
579
|
return this.inputStructureDetailed.build(params, decodedQuery, decodedHeaders, decodedBody);
|
|
569
580
|
}
|
|
570
581
|
encodeOutput(procedure, output, accept) {
|
|
571
|
-
const outputStructure = procedure["~orpc"].contract["~orpc"].route?.outputStructure;
|
|
572
|
-
if (
|
|
582
|
+
const outputStructure = fallbackToGlobalConfig2("defaultOutputStructure", procedure["~orpc"].contract["~orpc"].route?.outputStructure);
|
|
583
|
+
if (outputStructure === "compact") {
|
|
573
584
|
return this.payloadCodec.encode(output, accept);
|
|
574
585
|
}
|
|
575
|
-
const _expect = outputStructure;
|
|
576
586
|
this.assertDetailedOutput(output);
|
|
577
587
|
const headers = new Headers();
|
|
578
588
|
if (output.headers) {
|
|
@@ -639,4 +649,4 @@ export {
|
|
|
639
649
|
CompositeSchemaCoercer,
|
|
640
650
|
OpenAPIHandler
|
|
641
651
|
};
|
|
642
|
-
//# sourceMappingURL=chunk-
|
|
652
|
+
//# sourceMappingURL=chunk-WNX6GP4X.js.map
|
package/dist/fetch.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -35,11 +35,15 @@ var OpenAPIContentBuilder = class {
|
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
37
|
|
|
38
|
+
// src/openapi-generator.ts
|
|
39
|
+
import { fallbackToGlobalConfig as fallbackToGlobalConfig2 } from "@orpc/contract";
|
|
40
|
+
|
|
38
41
|
// src/openapi-error.ts
|
|
39
42
|
var OpenAPIError = class extends Error {
|
|
40
43
|
};
|
|
41
44
|
|
|
42
45
|
// src/openapi-input-structure-parser.ts
|
|
46
|
+
import { fallbackToGlobalConfig } from "@orpc/contract";
|
|
43
47
|
var OpenAPIInputStructureParser = class {
|
|
44
48
|
constructor(schemaConverter, schemaUtils, pathParser) {
|
|
45
49
|
this.schemaConverter = schemaConverter;
|
|
@@ -48,7 +52,7 @@ var OpenAPIInputStructureParser = class {
|
|
|
48
52
|
}
|
|
49
53
|
parse(contract, structure) {
|
|
50
54
|
const inputSchema = this.schemaConverter.convert(contract["~orpc"].InputSchema, { strategy: "input" });
|
|
51
|
-
const method = contract["~orpc"].route?.method
|
|
55
|
+
const method = fallbackToGlobalConfig("defaultMethod", contract["~orpc"].route?.method);
|
|
52
56
|
const httpPath = contract["~orpc"].route?.path;
|
|
53
57
|
if (this.schemaUtils.isAnySchema(inputSchema)) {
|
|
54
58
|
return {
|
|
@@ -405,10 +409,12 @@ var OpenAPIGenerator = class {
|
|
|
405
409
|
if (this.ignoreUndefinedPathProcedures && def.route?.path === void 0) {
|
|
406
410
|
return;
|
|
407
411
|
}
|
|
408
|
-
const method = def.route?.method
|
|
412
|
+
const method = fallbackToGlobalConfig2("defaultMethod", def.route?.method);
|
|
409
413
|
const httpPath = def.route?.path ? standardizeHTTPPath(def.route?.path) : `/${path.map(encodeURIComponent).join("/")}`;
|
|
410
|
-
const
|
|
411
|
-
const
|
|
414
|
+
const inputStructure = fallbackToGlobalConfig2("defaultInputStructure", def.route?.inputStructure);
|
|
415
|
+
const outputStructure = fallbackToGlobalConfig2("defaultOutputStructure", def.route?.outputStructure);
|
|
416
|
+
const { paramsSchema, querySchema, headersSchema, bodySchema } = this.inputStructureParser.parse(contract, inputStructure);
|
|
417
|
+
const { headersSchema: resHeadersSchema, bodySchema: resBodySchema } = this.outputStructureParser.parse(contract, outputStructure);
|
|
412
418
|
const params = paramsSchema ? this.parametersBuilder.build("path", paramsSchema, {
|
|
413
419
|
required: true
|
|
414
420
|
}) : [];
|
|
@@ -445,7 +451,7 @@ var OpenAPIGenerator = class {
|
|
|
445
451
|
parameters: parameters.length ? parameters : void 0,
|
|
446
452
|
requestBody,
|
|
447
453
|
responses: {
|
|
448
|
-
[def.route?.successStatus
|
|
454
|
+
[fallbackToGlobalConfig2("defaultSuccessStatus", def.route?.successStatus)]: successResponse
|
|
449
455
|
}
|
|
450
456
|
};
|
|
451
457
|
builder.addPath(httpPath, {
|
package/dist/node.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { ContractRouter } from '@orpc/contract';
|
|
2
1
|
import type { ANY_ROUTER } from '@orpc/server';
|
|
3
2
|
import type { PublicOpenAPIInputStructureParser } from './openapi-input-structure-parser';
|
|
4
3
|
import type { PublicOpenAPIOutputStructureParser } from './openapi-output-structure-parser';
|
|
5
4
|
import type { PublicOpenAPIPathParser } from './openapi-path-parser';
|
|
6
5
|
import type { SchemaConverter } from './schema-converter';
|
|
6
|
+
import { type ContractRouter } from '@orpc/contract';
|
|
7
7
|
import { type PublicJSONSerializer } from './json-serializer';
|
|
8
8
|
import { type OpenAPI } from './openapi';
|
|
9
9
|
import { type PublicOpenAPIContentBuilder } from './openapi-content-builder';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { ANY_CONTRACT_PROCEDURE } from '@orpc/contract';
|
|
2
1
|
import type { PublicOpenAPIPathParser } from './openapi-path-parser';
|
|
3
2
|
import type { JSONSchema, ObjectSchema } from './schema';
|
|
4
3
|
import type { SchemaConverter } from './schema-converter';
|
|
5
4
|
import type { PublicSchemaUtils } from './schema-utils';
|
|
5
|
+
import { type ANY_CONTRACT_PROCEDURE } from '@orpc/contract';
|
|
6
6
|
export interface OpenAPIInputStructureParseResult {
|
|
7
7
|
paramsSchema: ObjectSchema | undefined;
|
|
8
8
|
querySchema: ObjectSchema | undefined;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/openapi",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.0-next.
|
|
4
|
+
"version": "0.0.0-next.3f6c426",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -49,9 +49,9 @@
|
|
|
49
49
|
"json-schema-typed": "^8.0.1",
|
|
50
50
|
"openapi3-ts": "^4.4.0",
|
|
51
51
|
"wildcard-match": "^5.1.3",
|
|
52
|
-
"@orpc/contract": "0.0.0-next.
|
|
53
|
-
"@orpc/server": "0.0.0-next.
|
|
54
|
-
"@orpc/shared": "0.0.0-next.
|
|
52
|
+
"@orpc/contract": "0.0.0-next.3f6c426",
|
|
53
|
+
"@orpc/server": "0.0.0-next.3f6c426",
|
|
54
|
+
"@orpc/shared": "0.0.0-next.3f6c426"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
57
|
"@readme/openapi-parser": "^2.6.0",
|