@tahminator/sapling 2.0.5 → 2.1.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/README.md +161 -12
- package/dist/index.cjs +591 -262
- package/dist/index.d.cts +589 -88
- package/dist/index.d.mts +589 -88
- package/dist/index.mjs +563 -262
- package/package.json +8 -2
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import e, { ErrorRequestHandler, NextFunction, Request, Response, Router } from "express";
|
|
1
|
+
import e, { ErrorRequestHandler, NextFunction, Request, RequestHandler, Response as Response$1, Router } from "express";
|
|
2
2
|
|
|
3
3
|
//#region src/html/404.d.ts
|
|
4
4
|
/**
|
|
@@ -26,7 +26,7 @@ type RouteDefinition = {
|
|
|
26
26
|
};
|
|
27
27
|
type Class<T> = new (...args: any[]) => T;
|
|
28
28
|
type HttpHeaders = Record<string, string>;
|
|
29
|
-
type ExpressMiddlewareFn = ($1: Request, $2: Response, $3: NextFunction) => void;
|
|
29
|
+
type ExpressMiddlewareFn = ($1: Request, $2: Response$1, $3: NextFunction) => void;
|
|
30
30
|
//#endregion
|
|
31
31
|
//#region src/annotation/controller.d.ts
|
|
32
32
|
declare const _ControllerRegistry: WeakMap<Function, Router | ErrorRequestHandler>;
|
|
@@ -230,6 +230,45 @@ declare namespace StandardSchemaV1 {
|
|
|
230
230
|
type InferOutput<Schema extends StandardTypedV1> = StandardTypedV1.InferOutput<Schema>;
|
|
231
231
|
}
|
|
232
232
|
/** The Standard JSON Schema interface. */
|
|
233
|
+
interface StandardJSONSchemaV1<Input = unknown, Output = Input> {
|
|
234
|
+
/** The Standard JSON Schema properties. */
|
|
235
|
+
readonly "~standard": StandardJSONSchemaV1.Props<Input, Output>;
|
|
236
|
+
}
|
|
237
|
+
declare namespace StandardJSONSchemaV1 {
|
|
238
|
+
/** The Standard JSON Schema properties interface. */
|
|
239
|
+
interface Props<Input = unknown, Output = Input> extends StandardTypedV1.Props<Input, Output> {
|
|
240
|
+
/** Methods for generating the input/output JSON Schema. */
|
|
241
|
+
readonly jsonSchema: StandardJSONSchemaV1.Converter;
|
|
242
|
+
}
|
|
243
|
+
/** The Standard JSON Schema converter interface. */
|
|
244
|
+
interface Converter {
|
|
245
|
+
/** Converts the input type to JSON Schema. May throw if conversion is not supported. */
|
|
246
|
+
readonly input: (options: StandardJSONSchemaV1.Options) => Record<string, unknown>;
|
|
247
|
+
/** Converts the output type to JSON Schema. May throw if conversion is not supported. */
|
|
248
|
+
readonly output: (options: StandardJSONSchemaV1.Options) => Record<string, unknown>;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* The target version of the generated JSON Schema.
|
|
252
|
+
*
|
|
253
|
+
* It is *strongly recommended* that implementers support `"draft-2020-12"` and `"draft-07"`, as they are both in wide use. All other targets can be implemented on a best-effort basis. Libraries should throw if they don't support a specified target.
|
|
254
|
+
*
|
|
255
|
+
* The `"openapi-3.0"` target is intended as a standardized specifier for OpenAPI 3.0 which is a superset of JSON Schema `"draft-04"`.
|
|
256
|
+
*/
|
|
257
|
+
type Target = "draft-2020-12" | "draft-07" | "openapi-3.0" | ({} & string);
|
|
258
|
+
/** The options for the input/output methods. */
|
|
259
|
+
interface Options {
|
|
260
|
+
/** Specifies the target version of the generated JSON Schema. Support for all versions is on a best-effort basis. If a given version is not supported, the library should throw. */
|
|
261
|
+
readonly target: Target;
|
|
262
|
+
/** Explicit support for additional vendor-specific parameters, if needed. */
|
|
263
|
+
readonly libraryOptions?: Record<string, unknown> | undefined;
|
|
264
|
+
}
|
|
265
|
+
/** The Standard types interface. */
|
|
266
|
+
interface Types<Input = unknown, Output = Input> extends StandardTypedV1.Types<Input, Output> {}
|
|
267
|
+
/** Infers the input type of a Standard. */
|
|
268
|
+
type InferInput<Schema extends StandardTypedV1> = StandardTypedV1.InferInput<Schema>;
|
|
269
|
+
/** Infers the output type of a Standard. */
|
|
270
|
+
type InferOutput<Schema extends StandardTypedV1> = StandardTypedV1.InferOutput<Schema>;
|
|
271
|
+
}
|
|
233
272
|
//#endregion
|
|
234
273
|
//#region src/helper/redirect.d.ts
|
|
235
274
|
/**
|
|
@@ -398,16 +437,370 @@ declare class ResponseStatusError extends Error {
|
|
|
398
437
|
}
|
|
399
438
|
//#endregion
|
|
400
439
|
//#region src/helper/error/parse.d.ts
|
|
401
|
-
type ParserErrorLocation = "reqbody" | "reqparams" | "reqquery";
|
|
440
|
+
type ParserErrorLocation = "reqbody" | "reqparams" | "reqquery" | "resbody";
|
|
402
441
|
/**
|
|
403
|
-
* This error should be thrown when some data cannot be parsed by a given schema.
|
|
442
|
+
* This error should be thrown when some data cannot be parsed by a given Standard Schema compatible schema.
|
|
404
443
|
*/
|
|
405
444
|
declare class ParserError extends ResponseStatusError {
|
|
406
|
-
constructor(location: ParserErrorLocation, issues: readonly StandardSchemaV1.Issue[], vendor: string);
|
|
445
|
+
constructor(location: ParserErrorLocation, issues: readonly StandardSchemaV1.Issue[], vendor: string, functionName: string);
|
|
407
446
|
private static formatMessage;
|
|
447
|
+
static getPrettyLocationString(location: ParserErrorLocation): "request body" | "request params" | "request query" | "response body";
|
|
408
448
|
}
|
|
409
449
|
//#endregion
|
|
450
|
+
//#region node_modules/.pnpm/openapi-types@12.1.3/node_modules/openapi-types/dist/index.d.ts
|
|
451
|
+
declare namespace OpenAPIV3 {
|
|
452
|
+
interface Document<T extends {} = {}> {
|
|
453
|
+
openapi: string;
|
|
454
|
+
info: InfoObject;
|
|
455
|
+
servers?: ServerObject[];
|
|
456
|
+
paths: PathsObject<T>;
|
|
457
|
+
components?: ComponentsObject;
|
|
458
|
+
security?: SecurityRequirementObject[];
|
|
459
|
+
tags?: TagObject[];
|
|
460
|
+
externalDocs?: ExternalDocumentationObject;
|
|
461
|
+
'x-express-openapi-additional-middleware'?: (((request: any, response: any, next: any) => Promise<void>) | ((request: any, response: any, next: any) => void))[];
|
|
462
|
+
'x-express-openapi-validation-strict'?: boolean;
|
|
463
|
+
}
|
|
464
|
+
interface InfoObject {
|
|
465
|
+
title: string;
|
|
466
|
+
description?: string;
|
|
467
|
+
termsOfService?: string;
|
|
468
|
+
contact?: ContactObject;
|
|
469
|
+
license?: LicenseObject;
|
|
470
|
+
version: string;
|
|
471
|
+
}
|
|
472
|
+
interface ContactObject {
|
|
473
|
+
name?: string;
|
|
474
|
+
url?: string;
|
|
475
|
+
email?: string;
|
|
476
|
+
}
|
|
477
|
+
interface LicenseObject {
|
|
478
|
+
name: string;
|
|
479
|
+
url?: string;
|
|
480
|
+
}
|
|
481
|
+
interface ServerObject {
|
|
482
|
+
url: string;
|
|
483
|
+
description?: string;
|
|
484
|
+
variables?: {
|
|
485
|
+
[variable: string]: ServerVariableObject;
|
|
486
|
+
};
|
|
487
|
+
}
|
|
488
|
+
interface ServerVariableObject {
|
|
489
|
+
enum?: string[];
|
|
490
|
+
default: string;
|
|
491
|
+
description?: string;
|
|
492
|
+
}
|
|
493
|
+
interface PathsObject<T extends {} = {}, P extends {} = {}> {
|
|
494
|
+
[pattern: string]: (PathItemObject<T> & P) | undefined;
|
|
495
|
+
}
|
|
496
|
+
enum HttpMethods {
|
|
497
|
+
GET = "get",
|
|
498
|
+
PUT = "put",
|
|
499
|
+
POST = "post",
|
|
500
|
+
DELETE = "delete",
|
|
501
|
+
OPTIONS = "options",
|
|
502
|
+
HEAD = "head",
|
|
503
|
+
PATCH = "patch",
|
|
504
|
+
TRACE = "trace"
|
|
505
|
+
}
|
|
506
|
+
type PathItemObject<T extends {} = {}> = {
|
|
507
|
+
$ref?: string;
|
|
508
|
+
summary?: string;
|
|
509
|
+
description?: string;
|
|
510
|
+
servers?: ServerObject[];
|
|
511
|
+
parameters?: (ReferenceObject | ParameterObject)[];
|
|
512
|
+
} & { [method in HttpMethods]?: OperationObject<T> };
|
|
513
|
+
type OperationObject<T extends {} = {}> = {
|
|
514
|
+
tags?: string[];
|
|
515
|
+
summary?: string;
|
|
516
|
+
description?: string;
|
|
517
|
+
externalDocs?: ExternalDocumentationObject;
|
|
518
|
+
operationId?: string;
|
|
519
|
+
parameters?: (ReferenceObject | ParameterObject)[];
|
|
520
|
+
requestBody?: ReferenceObject | RequestBodyObject;
|
|
521
|
+
responses: ResponsesObject;
|
|
522
|
+
callbacks?: {
|
|
523
|
+
[callback: string]: ReferenceObject | CallbackObject;
|
|
524
|
+
};
|
|
525
|
+
deprecated?: boolean;
|
|
526
|
+
security?: SecurityRequirementObject[];
|
|
527
|
+
servers?: ServerObject[];
|
|
528
|
+
} & T;
|
|
529
|
+
interface ExternalDocumentationObject {
|
|
530
|
+
description?: string;
|
|
531
|
+
url: string;
|
|
532
|
+
}
|
|
533
|
+
interface ParameterObject extends ParameterBaseObject {
|
|
534
|
+
name: string;
|
|
535
|
+
in: string;
|
|
536
|
+
}
|
|
537
|
+
interface HeaderObject extends ParameterBaseObject {}
|
|
538
|
+
interface ParameterBaseObject {
|
|
539
|
+
description?: string;
|
|
540
|
+
required?: boolean;
|
|
541
|
+
deprecated?: boolean;
|
|
542
|
+
allowEmptyValue?: boolean;
|
|
543
|
+
style?: string;
|
|
544
|
+
explode?: boolean;
|
|
545
|
+
allowReserved?: boolean;
|
|
546
|
+
schema?: ReferenceObject | SchemaObject;
|
|
547
|
+
example?: any;
|
|
548
|
+
examples?: {
|
|
549
|
+
[media: string]: ReferenceObject | ExampleObject;
|
|
550
|
+
};
|
|
551
|
+
content?: {
|
|
552
|
+
[media: string]: MediaTypeObject;
|
|
553
|
+
};
|
|
554
|
+
}
|
|
555
|
+
type NonArraySchemaObjectType = 'boolean' | 'object' | 'number' | 'string' | 'integer';
|
|
556
|
+
type ArraySchemaObjectType = 'array';
|
|
557
|
+
type SchemaObject = ArraySchemaObject | NonArraySchemaObject;
|
|
558
|
+
interface ArraySchemaObject extends BaseSchemaObject {
|
|
559
|
+
type: ArraySchemaObjectType;
|
|
560
|
+
items: ReferenceObject | SchemaObject;
|
|
561
|
+
}
|
|
562
|
+
interface NonArraySchemaObject extends BaseSchemaObject {
|
|
563
|
+
type?: NonArraySchemaObjectType;
|
|
564
|
+
}
|
|
565
|
+
interface BaseSchemaObject {
|
|
566
|
+
title?: string;
|
|
567
|
+
description?: string;
|
|
568
|
+
format?: string;
|
|
569
|
+
default?: any;
|
|
570
|
+
multipleOf?: number;
|
|
571
|
+
maximum?: number;
|
|
572
|
+
exclusiveMaximum?: boolean;
|
|
573
|
+
minimum?: number;
|
|
574
|
+
exclusiveMinimum?: boolean;
|
|
575
|
+
maxLength?: number;
|
|
576
|
+
minLength?: number;
|
|
577
|
+
pattern?: string;
|
|
578
|
+
additionalProperties?: boolean | ReferenceObject | SchemaObject;
|
|
579
|
+
maxItems?: number;
|
|
580
|
+
minItems?: number;
|
|
581
|
+
uniqueItems?: boolean;
|
|
582
|
+
maxProperties?: number;
|
|
583
|
+
minProperties?: number;
|
|
584
|
+
required?: string[];
|
|
585
|
+
enum?: any[];
|
|
586
|
+
properties?: {
|
|
587
|
+
[name: string]: ReferenceObject | SchemaObject;
|
|
588
|
+
};
|
|
589
|
+
allOf?: (ReferenceObject | SchemaObject)[];
|
|
590
|
+
oneOf?: (ReferenceObject | SchemaObject)[];
|
|
591
|
+
anyOf?: (ReferenceObject | SchemaObject)[];
|
|
592
|
+
not?: ReferenceObject | SchemaObject;
|
|
593
|
+
nullable?: boolean;
|
|
594
|
+
discriminator?: DiscriminatorObject;
|
|
595
|
+
readOnly?: boolean;
|
|
596
|
+
writeOnly?: boolean;
|
|
597
|
+
xml?: XMLObject;
|
|
598
|
+
externalDocs?: ExternalDocumentationObject;
|
|
599
|
+
example?: any;
|
|
600
|
+
deprecated?: boolean;
|
|
601
|
+
}
|
|
602
|
+
interface DiscriminatorObject {
|
|
603
|
+
propertyName: string;
|
|
604
|
+
mapping?: {
|
|
605
|
+
[value: string]: string;
|
|
606
|
+
};
|
|
607
|
+
}
|
|
608
|
+
interface XMLObject {
|
|
609
|
+
name?: string;
|
|
610
|
+
namespace?: string;
|
|
611
|
+
prefix?: string;
|
|
612
|
+
attribute?: boolean;
|
|
613
|
+
wrapped?: boolean;
|
|
614
|
+
}
|
|
615
|
+
interface ReferenceObject {
|
|
616
|
+
$ref: string;
|
|
617
|
+
}
|
|
618
|
+
interface ExampleObject {
|
|
619
|
+
summary?: string;
|
|
620
|
+
description?: string;
|
|
621
|
+
value?: any;
|
|
622
|
+
externalValue?: string;
|
|
623
|
+
}
|
|
624
|
+
interface MediaTypeObject {
|
|
625
|
+
schema?: ReferenceObject | SchemaObject;
|
|
626
|
+
example?: any;
|
|
627
|
+
examples?: {
|
|
628
|
+
[media: string]: ReferenceObject | ExampleObject;
|
|
629
|
+
};
|
|
630
|
+
encoding?: {
|
|
631
|
+
[media: string]: EncodingObject;
|
|
632
|
+
};
|
|
633
|
+
}
|
|
634
|
+
interface EncodingObject {
|
|
635
|
+
contentType?: string;
|
|
636
|
+
headers?: {
|
|
637
|
+
[header: string]: ReferenceObject | HeaderObject;
|
|
638
|
+
};
|
|
639
|
+
style?: string;
|
|
640
|
+
explode?: boolean;
|
|
641
|
+
allowReserved?: boolean;
|
|
642
|
+
}
|
|
643
|
+
interface RequestBodyObject {
|
|
644
|
+
description?: string;
|
|
645
|
+
content: {
|
|
646
|
+
[media: string]: MediaTypeObject;
|
|
647
|
+
};
|
|
648
|
+
required?: boolean;
|
|
649
|
+
}
|
|
650
|
+
interface ResponsesObject {
|
|
651
|
+
[code: string]: ReferenceObject | ResponseObject;
|
|
652
|
+
}
|
|
653
|
+
interface ResponseObject {
|
|
654
|
+
description: string;
|
|
655
|
+
headers?: {
|
|
656
|
+
[header: string]: ReferenceObject | HeaderObject;
|
|
657
|
+
};
|
|
658
|
+
content?: {
|
|
659
|
+
[media: string]: MediaTypeObject;
|
|
660
|
+
};
|
|
661
|
+
links?: {
|
|
662
|
+
[link: string]: ReferenceObject | LinkObject;
|
|
663
|
+
};
|
|
664
|
+
}
|
|
665
|
+
interface LinkObject {
|
|
666
|
+
operationRef?: string;
|
|
667
|
+
operationId?: string;
|
|
668
|
+
parameters?: {
|
|
669
|
+
[parameter: string]: any;
|
|
670
|
+
};
|
|
671
|
+
requestBody?: any;
|
|
672
|
+
description?: string;
|
|
673
|
+
server?: ServerObject;
|
|
674
|
+
}
|
|
675
|
+
interface CallbackObject {
|
|
676
|
+
[url: string]: PathItemObject;
|
|
677
|
+
}
|
|
678
|
+
interface SecurityRequirementObject {
|
|
679
|
+
[name: string]: string[];
|
|
680
|
+
}
|
|
681
|
+
interface ComponentsObject {
|
|
682
|
+
schemas?: {
|
|
683
|
+
[key: string]: ReferenceObject | SchemaObject;
|
|
684
|
+
};
|
|
685
|
+
responses?: {
|
|
686
|
+
[key: string]: ReferenceObject | ResponseObject;
|
|
687
|
+
};
|
|
688
|
+
parameters?: {
|
|
689
|
+
[key: string]: ReferenceObject | ParameterObject;
|
|
690
|
+
};
|
|
691
|
+
examples?: {
|
|
692
|
+
[key: string]: ReferenceObject | ExampleObject;
|
|
693
|
+
};
|
|
694
|
+
requestBodies?: {
|
|
695
|
+
[key: string]: ReferenceObject | RequestBodyObject;
|
|
696
|
+
};
|
|
697
|
+
headers?: {
|
|
698
|
+
[key: string]: ReferenceObject | HeaderObject;
|
|
699
|
+
};
|
|
700
|
+
securitySchemes?: {
|
|
701
|
+
[key: string]: ReferenceObject | SecuritySchemeObject;
|
|
702
|
+
};
|
|
703
|
+
links?: {
|
|
704
|
+
[key: string]: ReferenceObject | LinkObject;
|
|
705
|
+
};
|
|
706
|
+
callbacks?: {
|
|
707
|
+
[key: string]: ReferenceObject | CallbackObject;
|
|
708
|
+
};
|
|
709
|
+
}
|
|
710
|
+
type SecuritySchemeObject = HttpSecurityScheme | ApiKeySecurityScheme | OAuth2SecurityScheme | OpenIdSecurityScheme;
|
|
711
|
+
interface HttpSecurityScheme {
|
|
712
|
+
type: 'http';
|
|
713
|
+
description?: string;
|
|
714
|
+
scheme: string;
|
|
715
|
+
bearerFormat?: string;
|
|
716
|
+
}
|
|
717
|
+
interface ApiKeySecurityScheme {
|
|
718
|
+
type: 'apiKey';
|
|
719
|
+
description?: string;
|
|
720
|
+
name: string;
|
|
721
|
+
in: string;
|
|
722
|
+
}
|
|
723
|
+
interface OAuth2SecurityScheme {
|
|
724
|
+
type: 'oauth2';
|
|
725
|
+
description?: string;
|
|
726
|
+
flows: {
|
|
727
|
+
implicit?: {
|
|
728
|
+
authorizationUrl: string;
|
|
729
|
+
refreshUrl?: string;
|
|
730
|
+
scopes: {
|
|
731
|
+
[scope: string]: string;
|
|
732
|
+
};
|
|
733
|
+
};
|
|
734
|
+
password?: {
|
|
735
|
+
tokenUrl: string;
|
|
736
|
+
refreshUrl?: string;
|
|
737
|
+
scopes: {
|
|
738
|
+
[scope: string]: string;
|
|
739
|
+
};
|
|
740
|
+
};
|
|
741
|
+
clientCredentials?: {
|
|
742
|
+
tokenUrl: string;
|
|
743
|
+
refreshUrl?: string;
|
|
744
|
+
scopes: {
|
|
745
|
+
[scope: string]: string;
|
|
746
|
+
};
|
|
747
|
+
};
|
|
748
|
+
authorizationCode?: {
|
|
749
|
+
authorizationUrl: string;
|
|
750
|
+
tokenUrl: string;
|
|
751
|
+
refreshUrl?: string;
|
|
752
|
+
scopes: {
|
|
753
|
+
[scope: string]: string;
|
|
754
|
+
};
|
|
755
|
+
};
|
|
756
|
+
};
|
|
757
|
+
}
|
|
758
|
+
interface OpenIdSecurityScheme {
|
|
759
|
+
type: 'openIdConnect';
|
|
760
|
+
description?: string;
|
|
761
|
+
openIdConnectUrl: string;
|
|
762
|
+
}
|
|
763
|
+
interface TagObject {
|
|
764
|
+
name: string;
|
|
765
|
+
description?: string;
|
|
766
|
+
externalDocs?: ExternalDocumentationObject;
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
//#endregion
|
|
770
|
+
//#region src/helper/openapi.d.ts
|
|
771
|
+
type OpenAPIMetadata = {
|
|
772
|
+
title: string;
|
|
773
|
+
version: string;
|
|
774
|
+
description?: string;
|
|
775
|
+
};
|
|
776
|
+
declare class OpenAPIGenerator {
|
|
777
|
+
private OPENAPI_VERSION;
|
|
778
|
+
private controllers;
|
|
779
|
+
registerController(controllerClass: Function, prefix: string): void;
|
|
780
|
+
/**
|
|
781
|
+
* visible for testing
|
|
782
|
+
*/
|
|
783
|
+
_clearControllers(): void;
|
|
784
|
+
private get metadata();
|
|
785
|
+
generateSpec(): OpenAPIV3.Document;
|
|
786
|
+
private toJsonSchema;
|
|
787
|
+
}
|
|
788
|
+
declare const openApiGenerator: OpenAPIGenerator;
|
|
789
|
+
declare function _registerController(controllerClass: Function, prefix: string): void;
|
|
790
|
+
declare function generateOpenApiSpec(): OpenAPIV3.Document;
|
|
791
|
+
declare function _clearOpenApiRegistry(): void;
|
|
792
|
+
//#endregion
|
|
410
793
|
//#region src/helper/sapling.d.ts
|
|
794
|
+
type Settings = {
|
|
795
|
+
serialize: (value: any) => string;
|
|
796
|
+
deserialize: (value: string) => any;
|
|
797
|
+
doc: {
|
|
798
|
+
openApiPath: string;
|
|
799
|
+
swaggerPath: string;
|
|
800
|
+
metadata: OpenAPIMetadata;
|
|
801
|
+
};
|
|
802
|
+
};
|
|
803
|
+
declare const _settings: Settings;
|
|
411
804
|
/**
|
|
412
805
|
* Collection of utility functions which are essential for Sapling to function.
|
|
413
806
|
*/
|
|
@@ -481,111 +874,219 @@ declare class Sapling {
|
|
|
481
874
|
* Replace the function used for `deserialize`
|
|
482
875
|
*/
|
|
483
876
|
static setDeserializeFn(this: void, fn: (value: string) => any): void;
|
|
877
|
+
/**
|
|
878
|
+
* Modify extra settings
|
|
879
|
+
*/
|
|
880
|
+
static Extras: {
|
|
881
|
+
/**
|
|
882
|
+
* Modify default settings applied to OpenAPI & Swagger
|
|
883
|
+
*/
|
|
884
|
+
swaggerAndOpenApi: {
|
|
885
|
+
/**
|
|
886
|
+
* Set base OpenAPI metadata values.
|
|
887
|
+
*
|
|
888
|
+
* @default { title: "API", version: "1.0.0" }
|
|
889
|
+
*/
|
|
890
|
+
setMetadata(metadata: OpenAPIMetadata): void;
|
|
891
|
+
/**
|
|
892
|
+
* change default endpoint that will serve OpenAPI spec.
|
|
893
|
+
* Swagger will also load this endpoint on load.
|
|
894
|
+
*
|
|
895
|
+
* @default `/openapi.json`
|
|
896
|
+
*/
|
|
897
|
+
setOpenApiPath(this: void, path: string): void;
|
|
898
|
+
/**
|
|
899
|
+
* change Swagger endpoint.
|
|
900
|
+
*
|
|
901
|
+
* @default `/swagger.html`
|
|
902
|
+
*/
|
|
903
|
+
setSwaggerPath(this: void, path: string): void;
|
|
904
|
+
};
|
|
905
|
+
};
|
|
906
|
+
/**
|
|
907
|
+
* This method can be used in a `@MiddlewareClass` to register any libraries
|
|
908
|
+
* that expect you to register multiple registers at once. An example is `swagger-ui-express`
|
|
909
|
+
*
|
|
910
|
+
* @example
|
|
911
|
+
* ```ts
|
|
912
|
+
* ⠀@MiddlewareClass()
|
|
913
|
+
* class Serve {
|
|
914
|
+
* // `swagger.serve` returns multiple Express handlers for all the assets and routes
|
|
915
|
+
* // that will be served
|
|
916
|
+
* private readonly handlers: RequestHandler[] = swagger.serve;
|
|
917
|
+
*
|
|
918
|
+
* ⠀@Middleware(_settings.doc.swaggerPath)
|
|
919
|
+
* handle(request: Request, response: Response, next: NextFunction) {
|
|
920
|
+
* return Sapling.chainHandlers(this.handlers, request, response, next);
|
|
921
|
+
* }
|
|
922
|
+
* }
|
|
923
|
+
* ```
|
|
924
|
+
*/
|
|
925
|
+
static chainHandlers(this: void, handlers: RequestHandler[], request: Request, response: Response$1, next: NextFunction, index?: number): void;
|
|
484
926
|
}
|
|
485
927
|
//#endregion
|
|
486
|
-
//#region src/annotation/
|
|
487
|
-
type
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
928
|
+
//#region src/annotation/validator.d.ts
|
|
929
|
+
type ValidatorSchema = {
|
|
930
|
+
requestBody?: StandardSchemaV1 & StandardJSONSchemaV1;
|
|
931
|
+
requestParam?: StandardSchemaV1 & StandardJSONSchemaV1;
|
|
932
|
+
requestQuery?: StandardSchemaV1 & StandardJSONSchemaV1;
|
|
933
|
+
responseBody?: StandardSchemaV1 & StandardJSONSchemaV1;
|
|
934
|
+
};
|
|
935
|
+
declare function ResponseBody(schema: StandardSchemaV1 & StandardJSONSchemaV1): MethodDecorator;
|
|
936
|
+
declare function RequestBody(schema: StandardSchemaV1 & StandardJSONSchemaV1): MethodDecorator;
|
|
937
|
+
declare function RequestParam(schema: StandardSchemaV1 & StandardJSONSchemaV1): MethodDecorator;
|
|
938
|
+
declare function RequestQuery(schema: StandardSchemaV1 & StandardJSONSchemaV1): MethodDecorator;
|
|
939
|
+
declare function _getOrCreateSchemaDefinition(ctor: Function, fnName: string): ValidatorSchema;
|
|
940
|
+
declare function _parseOrThrow<TSchema extends StandardSchemaV1>(schema: TSchema, input: unknown, location: ParserErrorLocation, fnName: string): Promise<StandardSchemaV1.InferOutput<TSchema>>;
|
|
941
|
+
declare function _saveValidatorSchema(def: ValidatorSchema, key: keyof ValidatorSchema, schema: StandardSchemaV1 & StandardJSONSchemaV1, fnName: string): void;
|
|
942
|
+
declare function _getValidatorSchema(ctor: Function, fnName: string): ValidatorSchema | undefined;
|
|
943
|
+
//#endregion
|
|
944
|
+
//#region src/annotation/schema.d.ts
|
|
945
|
+
type ResponseSchema = {
|
|
946
|
+
statusCode: HttpStatus;
|
|
947
|
+
description?: string;
|
|
948
|
+
schema?: StandardSchemaV1 & StandardJSONSchemaV1;
|
|
949
|
+
};
|
|
950
|
+
type RouteSchemaDefinition = {
|
|
951
|
+
summary?: string;
|
|
952
|
+
description?: string;
|
|
953
|
+
responses?: ResponseSchema[];
|
|
491
954
|
};
|
|
955
|
+
type ControllerSchemaDefinition = {
|
|
956
|
+
title?: string;
|
|
957
|
+
description?: string;
|
|
958
|
+
};
|
|
959
|
+
declare function ControllerSchema(options: {
|
|
960
|
+
title?: string;
|
|
961
|
+
description?: string;
|
|
962
|
+
}): ClassDecorator;
|
|
963
|
+
declare function RouteSchema(options: {
|
|
964
|
+
summary?: string;
|
|
965
|
+
description?: string;
|
|
966
|
+
responses?: ResponseSchema[];
|
|
967
|
+
}): MethodDecorator;
|
|
968
|
+
declare function _setRouteSchema(ctor: Function, fnName: string, options: RouteSchemaDefinition): void;
|
|
969
|
+
declare function _setControllerSchema(ctor: Function, options: ControllerSchemaDefinition): void;
|
|
970
|
+
declare function _getRouteSchema(ctor: Function, fnName: string): RouteSchemaDefinition | undefined;
|
|
971
|
+
declare function _getControllerSchema(ctor: Function): ControllerSchemaDefinition | undefined;
|
|
972
|
+
//#endregion
|
|
973
|
+
//#region src/middleware/default/error/base.d.ts
|
|
492
974
|
/**
|
|
493
|
-
*
|
|
975
|
+
* This should be registered last in the middleware chain.
|
|
494
976
|
*
|
|
495
|
-
*
|
|
496
|
-
*
|
|
977
|
+
* All exception messages are hidden from the request by default.
|
|
978
|
+
* If the default is not suitable, you may also easily write your own.
|
|
979
|
+
*/
|
|
980
|
+
declare class DefaultBaseErrorMiddleware {
|
|
981
|
+
handle(err: unknown, _request: Request, _response: Response$1, _next: NextFunction): ResponseEntity<{
|
|
982
|
+
message: string;
|
|
983
|
+
}>;
|
|
984
|
+
}
|
|
985
|
+
//#endregion
|
|
986
|
+
//#region src/middleware/default/error/parse.d.ts
|
|
987
|
+
/**
|
|
988
|
+
* Default error middleware that handles `ParserError`.
|
|
989
|
+
* If the default is not suitable, you may also easily write your own.
|
|
990
|
+
*/
|
|
991
|
+
declare class DefaultParserErrorMiddleware {
|
|
992
|
+
handle(err: unknown, _request: Request, _response: Response$1, next: NextFunction): ResponseEntity<{
|
|
993
|
+
message: string;
|
|
994
|
+
}> | undefined;
|
|
995
|
+
}
|
|
996
|
+
//#endregion
|
|
997
|
+
//#region src/middleware/default/error/responsestatus.d.ts
|
|
998
|
+
/**
|
|
999
|
+
* Default error middleware that handles `ResponseStatusError`.
|
|
1000
|
+
* If the default is not suitable, you may also easily write your own.
|
|
1001
|
+
*/
|
|
1002
|
+
declare class DefaultResponseStatusErrorMiddleware {
|
|
1003
|
+
handle(err: unknown, _request: Request, _response: Response$1, next: NextFunction): ResponseEntity<{
|
|
1004
|
+
message: string;
|
|
1005
|
+
}> | undefined;
|
|
1006
|
+
}
|
|
1007
|
+
//#endregion
|
|
1008
|
+
//#region src/middleware/default/openapi/index.d.ts
|
|
1009
|
+
/**
|
|
1010
|
+
* Enable the serving of the OpenAPI spec autogenerated by Sapling.
|
|
497
1011
|
*
|
|
498
|
-
*
|
|
499
|
-
*
|
|
500
|
-
*
|
|
501
|
-
* name: z.string(),
|
|
502
|
-
* description: z.string().optional(),
|
|
503
|
-
* });
|
|
1012
|
+
* Configure any middleware-specific settings with `Sapling.Extras.swaggerAndOpenApi`
|
|
1013
|
+
*
|
|
1014
|
+
* You must register `DefaultSwaggerMiddleware.Serve` & `DefaultSwaggerMiddleware.Setup` after `DefaultOpenApiMiddleware`
|
|
504
1015
|
*
|
|
505
|
-
*
|
|
506
|
-
*
|
|
507
|
-
*
|
|
508
|
-
*
|
|
509
|
-
*
|
|
510
|
-
*
|
|
511
|
-
*
|
|
512
|
-
* >;
|
|
513
|
-
* }
|
|
514
|
-
* }
|
|
1016
|
+
* ```ts
|
|
1017
|
+
* const middlewares = [
|
|
1018
|
+
* DefaultOpenApiMiddleware,
|
|
1019
|
+
* DefaultSwaggerMiddleware.Serve,
|
|
1020
|
+
* DefaultSwaggerMiddleware.Setup,
|
|
1021
|
+
* ];
|
|
1022
|
+
* middlewares.map(Sapling.resolve).forEach((r) => app.use(r));
|
|
515
1023
|
* ```
|
|
516
1024
|
*/
|
|
517
|
-
declare
|
|
1025
|
+
declare class DefaultOpenApiMiddleware {
|
|
1026
|
+
handle(_request: Request, _response: Response$1, _next: NextFunction): ResponseEntity<OpenAPIV3.Document<{}>>;
|
|
1027
|
+
}
|
|
1028
|
+
//#endregion
|
|
1029
|
+
//#region src/middleware/default/swagger/index.d.ts
|
|
518
1030
|
/**
|
|
519
|
-
*
|
|
1031
|
+
* Enable the serving of the Swagger endpoint used to serve the OpenAPI spec generated by Sapling.
|
|
520
1032
|
*
|
|
521
|
-
*
|
|
522
|
-
* You can then just simply cast `request.param` for your use
|
|
1033
|
+
* Configure any middleware-specific settings with `Sapling.Extras.swaggerAndOpenApi`
|
|
523
1034
|
*
|
|
524
|
-
*
|
|
525
|
-
* ```ts
|
|
526
|
-
* const GET_BOOK_REQUEST_PARAM_SCHEMA = z.object({
|
|
527
|
-
* bookId: z.string(),
|
|
528
|
-
* });
|
|
1035
|
+
* You must register `DefaultSwaggerMiddleware.Serve` & `DefaultSwaggerMiddleware.Setup` after `DefaultOpenApiMiddleware`
|
|
529
1036
|
*
|
|
530
|
-
*
|
|
531
|
-
*
|
|
532
|
-
*
|
|
533
|
-
*
|
|
534
|
-
*
|
|
535
|
-
*
|
|
536
|
-
*
|
|
537
|
-
* >;
|
|
538
|
-
* }
|
|
539
|
-
* }
|
|
1037
|
+
* ```ts
|
|
1038
|
+
* const middlewares = [
|
|
1039
|
+
* DefaultOpenApiMiddleware,
|
|
1040
|
+
* DefaultSwaggerMiddleware.Serve,
|
|
1041
|
+
* DefaultSwaggerMiddleware.Setup,
|
|
1042
|
+
* ];
|
|
1043
|
+
* middlewares.map(Sapling.resolve).forEach((r) => app.use(r));
|
|
540
1044
|
* ```
|
|
541
1045
|
*/
|
|
542
|
-
declare
|
|
1046
|
+
declare class Serve {
|
|
1047
|
+
private readonly handlers;
|
|
1048
|
+
handle(request: Request, response: Response$1, next: NextFunction): void;
|
|
1049
|
+
}
|
|
543
1050
|
/**
|
|
544
|
-
*
|
|
1051
|
+
* Enable the serving of the Swagger endpoint used to serve the OpenAPI spec generated by Sapling.
|
|
545
1052
|
*
|
|
546
|
-
*
|
|
547
|
-
* You can then just simply cast `request.query` for your use
|
|
1053
|
+
* Configure any middleware-specific settings with `Sapling.Extras.swaggerAndOpenApi`
|
|
548
1054
|
*
|
|
549
|
-
*
|
|
550
|
-
* ```ts
|
|
551
|
-
* const LIST_BOOKS_REQUEST_QUERY_SCHEMA = z.object({
|
|
552
|
-
* sort: z.enum(["name", "createdAt"]).optional(),
|
|
553
|
-
* q: z.string().optional(),
|
|
554
|
-
* });
|
|
1055
|
+
* You must register `DefaultSwaggerMiddleware.Serve` & `DefaultSwaggerMiddleware.Setup` after `DefaultOpenApiMiddleware`
|
|
555
1056
|
*
|
|
556
|
-
*
|
|
557
|
-
*
|
|
558
|
-
*
|
|
559
|
-
*
|
|
560
|
-
*
|
|
561
|
-
*
|
|
562
|
-
*
|
|
563
|
-
* >;
|
|
564
|
-
* }
|
|
565
|
-
* }
|
|
1057
|
+
* ```ts
|
|
1058
|
+
* const middlewares = [
|
|
1059
|
+
* DefaultOpenApiMiddleware,
|
|
1060
|
+
* DefaultSwaggerMiddleware.Serve,
|
|
1061
|
+
* DefaultSwaggerMiddleware.Setup,
|
|
1062
|
+
* ];
|
|
1063
|
+
* middlewares.map(Sapling.resolve).forEach((r) => app.use(r));
|
|
566
1064
|
* ```
|
|
567
1065
|
*/
|
|
568
|
-
declare
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
1066
|
+
declare class Setup {
|
|
1067
|
+
private readonly handler;
|
|
1068
|
+
constructor();
|
|
1069
|
+
handle(request: Request, response: Response$1, next: NextFunction): unknown;
|
|
1070
|
+
}
|
|
573
1071
|
/**
|
|
574
|
-
*
|
|
1072
|
+
* Enable the serving of the Swagger endpoint used to serve the OpenAPI spec generated by Sapling.
|
|
575
1073
|
*
|
|
576
|
-
*
|
|
1074
|
+
* Configure any middleware-specific settings with `Sapling.Extras.swaggerAndOpenApi`
|
|
1075
|
+
*
|
|
1076
|
+
* You must register `DefaultSwaggerMiddleware.Serve` & `DefaultSwaggerMiddleware.Setup` after `DefaultOpenApiMiddleware`
|
|
1077
|
+
*
|
|
1078
|
+
* ```ts
|
|
1079
|
+
* const middlewares = [
|
|
1080
|
+
* DefaultOpenApiMiddleware,
|
|
1081
|
+
* DefaultSwaggerMiddleware.Serve,
|
|
1082
|
+
* DefaultSwaggerMiddleware.Setup,
|
|
1083
|
+
* ];
|
|
1084
|
+
* middlewares.map(Sapling.resolve).forEach((r) => app.use(r));
|
|
1085
|
+
* ```
|
|
577
1086
|
*/
|
|
578
|
-
declare
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
}
|
|
583
|
-
//#endregion
|
|
584
|
-
//#region src/middleware/default/responsestatus.d.ts
|
|
585
|
-
declare class DefaultResponseStatusErrorMiddleware {
|
|
586
|
-
handle(err: unknown, _request: Request, _response: Response, next: NextFunction): ResponseEntity<{
|
|
587
|
-
message: string;
|
|
588
|
-
}> | undefined;
|
|
589
|
-
}
|
|
1087
|
+
declare const DefaultSwaggerMiddleware: {
|
|
1088
|
+
Serve: typeof Serve;
|
|
1089
|
+
Setup: typeof Setup;
|
|
1090
|
+
};
|
|
590
1091
|
//#endregion
|
|
591
|
-
export { Class, Controller, DELETE, DefaultBaseErrorMiddleware, DefaultResponseStatusErrorMiddleware, ExpressMiddlewareFn, ExpressRouterMethodKey, ExpressRouterMethods, GET, HEAD, Html404ErrorPage, HttpHeaders, HttpStatus, Injectable, Middleware, MiddlewareClass, OPTIONS, PATCH, POST, PUT, ParserError, ParserErrorLocation, RedirectView, RequestBody, RequestParam, RequestQuery, ResponseEntity, ResponseEntityBuilder, ResponseStatusError, RouteDefinition, Sapling, _ControllerRegistry, _InjectableDeps, _InjectableRegistry, _Route,
|
|
1092
|
+
export { Class, Controller, ControllerSchema, ControllerSchemaDefinition, DELETE, DefaultBaseErrorMiddleware, DefaultOpenApiMiddleware, DefaultParserErrorMiddleware, DefaultResponseStatusErrorMiddleware, DefaultSwaggerMiddleware, ExpressMiddlewareFn, ExpressRouterMethodKey, ExpressRouterMethods, GET, HEAD, Html404ErrorPage, HttpHeaders, HttpStatus, Injectable, Middleware, MiddlewareClass, OPTIONS, OpenAPIMetadata, PATCH, POST, PUT, ParserError, ParserErrorLocation, RedirectView, RequestBody, RequestParam, RequestQuery, ResponseBody, ResponseEntity, ResponseEntityBuilder, ResponseSchema, ResponseStatusError, RouteDefinition, RouteSchema, RouteSchemaDefinition, Sapling, ValidatorSchema, _ControllerRegistry, _InjectableDeps, _InjectableRegistry, _Route, _clearOpenApiRegistry, _getControllerSchema, _getOrCreateSchemaDefinition, _getRouteSchema, _getRoutes, _getValidatorSchema, _parseOrThrow, _registerController, _resolve, _saveValidatorSchema, _setControllerSchema, _setRouteSchema, _settings, generateOpenApiSpec, methodResolve, openApiGenerator };
|