-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathOpenApi.ts
1210 lines (1098 loc) · 33 KB
/
OpenApi.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import { OpenApiV3 } from "./OpenApiV3";
import { OpenApiV3_1 } from "./OpenApiV3_1";
import { SwaggerV2 } from "./SwaggerV2";
import { OpenApiV3Downgrader } from "./converters/OpenApiV3Downgrader";
import { OpenApiV3Upgrader } from "./converters/OpenApiV3Upgrader";
import { OpenApiV3_1Emender } from "./converters/OpenApiV3_1Emender";
import { SwaggerV2Downgrader } from "./converters/SwaggerV2Downgrader";
import { SwaggerV2Upgrader } from "./converters/SwaggerV2Upgrader";
/**
* Emended OpenAPI v3.1 definition used by `typia` and `nestia`.
*
* `OpenApi` is a namespace containing functions and interfaces for emended
* OpenAPI v3.1 specification. The keyword "emended" means that `OpenApi` is
* not a direct OpenAPI v3.1 specification ({@link OpenApiV3_1}), but a little
* bit shrunk to remove ambiguous and duplicated expressions of OpenAPI v3.1
* for the convenience of `typia` and `nestia`.
*
* For example, when representing nullable type, OpenAPI v3.1 supports three ways.
* In that case, `OpenApi` remains only the third way, so that makes `typia` and
* `nestia` (especially `@nestia/editor`) to be simple and easy to implement.
*
* 1. `{ type: ["string", "null"] }`
* 2. `{ type: "string", nullable: true }`
* 3. `{ oneOf: [{ type: "string" }, { type: "null" }] }`
*
* Here is the entire list of differences between OpenAPI v3.1 and emended `OpenApi`.
*
* - Operation
* - Merge {@link OpenApiV3_1.IPath.parameters} to {@link OpenApi.IOperation.parameters}
* - Resolve {@link OpenApi.IJsonSchema.IReference references} of {@link OpenApiV3_1.IOperation} members
* - Escape references of {@link OpenApiV3_1.IComponents.examples}
* - JSON Schema
* - Decompose mixed type: {@link OpenApiV3_1.IJsonSchema.IMixed}
* - Resolve nullable property: {@link OpenApiV3_1.IJsonSchema.__ISignificant.nullable}
* - Array type utilizes only single {@link OpenApi.IJsonSchema.IArray.items}
* - Tuple type utilizes only {@link OpenApi.IJsonSchema.ITuple.prefixItems}
* - Merge {@link OpenApiV3_1.IJsonSchema.IAllOf} to {@link OpenApi.IJsonSchema.IObject}
* - Merge {@link OpenApiV3_1.IJsonSchema.IAnyOf} to {@link OpenApi.IJsonSchema.IOneOf}
* - Merge {@link OpenApiV3_1.IJsonSchema.IRecursiveReference} to {@link OpenApi.IJsonSchema.IReference}
*
* @author Jeongho Nam - https://github.com/samchon
*/
export namespace OpenApi {
/**
* Method of the operation.
*/
export type Method =
| "get"
| "post"
| "put"
| "delete"
| "options"
| "head"
| "patch"
| "trace";
/**
* Convert Swagger or OpenAPI document into emended OpenAPI v3.1 document.
*
* @param input Swagger or OpenAPI document to convert
* @returns Emended OpenAPI v3.1 document
*/
export function convert(
input:
| SwaggerV2.IDocument
| OpenApiV3.IDocument
| OpenApiV3_1.IDocument
| OpenApi.IDocument,
): IDocument {
if (OpenApiV3_1.is(input))
return OpenApiV3_1Emender.convert(input) as IDocument;
else if (OpenApiV3.is(input))
return OpenApiV3Upgrader.convert(input) as IDocument;
else if (SwaggerV2.is(input))
return SwaggerV2Upgrader.convert(input) as IDocument;
throw new TypeError("Unrecognized Swagger/OpenAPI version.");
}
/**
* Downgrade to Swagger v2.0 document.
*
* Downgrade the given document (emeneded OpenAPI v3.1) into Swagger v2.0.
*
* @param document Emended OpenAPI v3.1 document to downgrade
* @param version Version to downgrade
* @returns Swagger v2.0 document
*/
export function downgrade(
document: IDocument,
version: "2.0",
): SwaggerV2.IDocument;
/**
* Downgrade to OpenAPI v3.0 document.
*
* Downgrade the given document (emeneded OpenAPI v3.1) into OpenAPI v3.0.
*
* @param document Emended OpenAPI v3.1 document to downgrade
* @param version Version to downgrade
* @returns OpenAPI v3.0 document
*/
export function downgrade(
document: IDocument,
version: "3.0",
): OpenApiV3.IDocument;
/**
* @internal
*/
export function downgrade(
document: IDocument,
version: string,
): SwaggerV2.IDocument | OpenApiV3.IDocument {
if (version === "2.0") return SwaggerV2Downgrader.downgrade(document);
else if (version === "3.0") return OpenApiV3Downgrader.downgrade(document);
throw new TypeError("Unrecognized Swagger/OpenAPI version.");
}
/* -----------------------------------------------------------
PATH ITEMS
----------------------------------------------------------- */
/**
* OpenAPI document.
*
* `OpenApi.IDocument` represents an OpenAPI document of emended OpenAPI v3.1.
*
* In other words, `OpenApi.IDocument` is a structure of `swagger.json` file of
* OpenAPI v3.1 specification, but a little bit shrunk to remove ambiguous and
* duplicated expressions of OpenAPI v3.1 for the convenience and clarity.
*/
export interface IDocument {
/**
* OpenAPI version number.
*/
openapi: `3.1.${number}`;
/**
* List of servers that provide the API.
*/
servers?: IServer[];
/**
* Information about the API.
*/
info?: IDocument.IInfo;
/**
* An object to hold reusable data structures.
*
* It stores both DTO schemas and security schemes.
*
* For reference, `nestia` defines every object and alias types as reusable DTO
* schemas. The alias type means that defined by `type` keyword in TypeScript.
*/
components: IComponents;
/**
* The available paths and operations for the API.
*
* The 1st key is the path, and the 2nd key is the HTTP method.
*/
paths?: Record<string, IPath>;
/**
* An object to hold Webhooks.
*
* Its structure is same with {@link paths}, so that the 1st key is the path,
* and the 2nd key is the HTTP method.
*/
webhooks?: Record<string, IPath>;
/**
* A declaration of which security mechanisms can be used across the API.
*
* When this property be configured, it would be overwritten in every API routes.
*
* For reference, key means the name of security scheme and value means the `scopes`.
* The `scopes` can be used only when target security scheme is `oauth2` type,
* especially for {@link ISwaggerSecurityScheme.IOAuth2.IFlow.scopes} property.
*/
security?: Record<string, string[]>[];
/**
* List of tag names with description.
*
* It is possible to omit this property or skip some tag name even if
* the tag name is used in the API routes. In that case, the tag name
* would be displayed (in Swagger-UI) without description.
*/
tags?: IDocument.ITag[];
/**
* Flag for indicating this document is emended by `@samchon/openapi`.
*/
"x-samchon-emended": true;
}
export namespace IDocument {
/**
* Information about the API.
*/
export interface IInfo {
/**
* The title of the API.
*/
title: string;
/**
* A short summary of the API.
*/
summary?: string;
/**
* A full description of the API.
*/
description?: string;
/**
* A URL to the Terms of Service for the API.
*/
termsOfService?: string;
/**
* The contact information for the exposed API.
*/
contact?: IContact;
/**
* The license information for the exposed API.
*/
license?: ILicense;
/**
* Version of the API.
*/
version: string;
}
/**
* OpenAPI tag information.
*
* It is possible to skip composing this structure, even if some
* tag names are registered in the API routes ({@link OpenApi.IOperation.tags}).
* In that case, the tag name would be displayed in Swagger-UI without
* description.
*
* However, if you want to describe the tag name, you can compose this
* structure and describe the tag name in the {@link description} property.
*/
export interface ITag {
/**
* The name of the tag.
*/
name: string;
/**
* An optional string describing the tag.
*/
description?: string;
}
/**
* Contact information for the exposed API.
*/
export interface IContact {
/**
* The identifying name of the contact person/organization.
*/
name?: string;
/**
* The URL pointing to the contact information.
*/
url?: string;
/**
* The email address of the contact person/organization.
*
* @format email
*/
email?: string;
}
/**
* License information for the exposed API.
*/
export interface ILicense {
/**
* The license name used for the API.
*/
name: string;
/**
* Identifier for the license used for the API.
*
* example: MIT
*/
identifier?: string;
/**
* A URL to the license used for the API.
*/
url?: string;
}
}
/**
* The remote server that provides the API.
*/
export interface IServer {
/**
* A URL to the target host.
*/
url: string;
/**
* An optional string describing the target server.
*/
description?: string;
/**
* A map between a variable name and its value.
*
* When the server {@link url} is a type of template, this property
* would be utilized to fill the template with actual values.
*/
variables?: Record<string, IServer.IVariable>;
}
export namespace IServer {
/**
* A variable for the server URL template.
*/
export interface IVariable {
/**
* Default value to use for substitution.
*/
default: string;
/**
* List of available values for the variable.
*/
enum?: string[];
/**
* An optional description for the server variable.
*/
description?: string;
}
}
/* -----------------------------------------------------------
OPERATORS
----------------------------------------------------------- */
/**
* Path item.
*
* `OpenApi.IPath` represents a path item of emended OpenAPI v3.1,
* collecting multiple method operations in a single path.
*/
export interface IPath extends Partial<Record<Method, IOperation>> {
/**
* Servers that provide the path operations.
*/
servers?: IServer[];
/**
* Summary of the path.
*/
summary?: string;
/**
* Description of the path.
*/
description?: string;
}
/**
* Remote operation info.
*
* `OpenApi.IOperation` represents an Restful API operation provided by the
* remote server.
*/
export interface IOperation {
/**
* Unique string used to identify the operation.
*/
operationId?: string;
/**
* List of parameters that are applicable for this operation.
*/
parameters?: IOperation.IParameter[];
/**
* The request body applicable for this operation.
*/
requestBody?: IOperation.IRequestBody;
/**
* The list of possible responses as they are returned from executing this
* operation. Its key is the HTTP status code, and the value is the metadata of
* the response in the HTTP status code.
*/
responses?: Record<string, IOperation.IResponse>;
/**
* A list of servers providing this API operation.
*/
servers?: IServer[];
/**
* A short summary of what the operation does.
*/
summary?: string;
/**
* A verbose explanation of the operation behavior.
*/
description?: string;
/**
* List of securities and their scopes that are required for execution.
*
* When this property be configured, the Restful API operation requires
* the matched security value for execution. Its key means security key
* matched with {@link OpenApi.IDocument.security}.
*
* The value means scopes required for the security key when the security
* type is {@link OpenApi.ISecurityScheme.IOAuth2}. Otherwise the target
* security type is not {@link OpenApi.ISecurityScheme.IOAuth2}, the value
* would be empty array.
*/
security?: Record<string, string[]>[];
/**
* Tags for API documentation control.
*/
tags?: string[];
/**
* Flag for indicating this operation is deprecated.
*/
deprecated?: boolean;
/**
* Flag for indicating this operation is human-only.
*
* If this property value is `true`, {@link HttpLlm.application}
* function will not convert this operation schema into the LLM function
* calling schema that is represented by the {@link IHttpLlmFunction}
* interface.
*/
"x-samchon-human"?: boolean;
/**
* Accessor of the operation.
*
* If you configure this property, the assigned value would be used as
* {@link IHttpMigrateRoute.accessor}. Also, it also can be used as the
* {@link IHttpLlmFunction.name} by joininig with `.` character in the
* LLM function calling application.
*
* Note that, the `x-samchon-accessor` value must be unique in the entire
* OpenAPI document operations. If there're duplicated `x-samchon-accessor`
* values, {@link IHttpMigrateRoute.accessor} will ignore every duplicated
* `x-samchon-accessor` values and generate the
* {@link IHttpMigrateRoute.accessor} by itself.
*/
"x-samchon-accessor"?: string[];
/**
* Controller of the operation.
*
* If you configure this property, the assigned value would be utilized
* as the controller name in the OpenAPI generator library like
* [`@nestia/editor`](https://nestia.io/docs/editor/) and
* [`@nestia/migrate`](https://nestia.io/docs/migrate/).
*
* Also, if {@link x-samchon-accessor} has been configured, its last
* element would be used as the controller method (function) name.
* Of course, the OpenAPI document generator `@nestia/sdk` fills both of
* them.
*/
"x-samchon-controller"?: string;
}
export namespace IOperation {
/**
* Parameter of the operation.
*/
export interface IParameter {
/**
* Representative name of the parameter.
*
* In the most case, the `name` is equivalent to parameter variable name.
* Therefore, the `name` must be filled with the significant variable name
* of the parameter.
*
* By the way, only when the {@link in} property is `path`, the `name`
* can be omitted. In that case, the `name` is automatically deduced from
* the URL path's positional template argument analyzing.
*/
name?: string;
/**
* Location of the parameter.
*
* The `in` property is a string that determines the location of the parameter.
*
* - `path`: parameter is part of the path of the URL.
* - `query`: parameter is part of the query string.
* - `header`: parameter is part of the header.
* - `cookie`: parameter is part of the cookie.
*/
in: "path" | "query" | "header" | "cookie";
/**
* Type info of the parameter.
*/
schema: IJsonSchema;
/**
* Whether the parameter is required for execution or not.
*
* If the parameter is required, the value must be filled. Otherwise,
* it is possible to skip the parameter when executing the APi operation.
*
* For reference, the `required` property must be always `true` when the
* {@link in} property is `path`. Otherwise, the `required` property can
* be anything of them; `true`, `false` and `undefined`.
*/
required?: boolean;
/**
* Short title of the parameter.
*/
title?: string;
/**
* Verbose explanation of the parameter.
*/
description?: string;
/**
* Example value of the parameter.
*/
example?: any;
/**
* Collection of example values of the parameter with keys.
*/
examples?: Record<string, IExample>;
}
/**
* Request body of the operation.
*/
export interface IRequestBody {
content?: IContent;
description?: string;
required?: boolean;
"x-nestia-encrypted"?: boolean;
}
/**
* Response of the operation.
*/
export interface IResponse {
headers?: Record<string, IOperation.IParameter>;
content?: IContent;
description?: string;
"x-nestia-encrypted"?: boolean;
}
/**
* List of content types supported in request/response body.
*/
export interface IContent
extends Partial<Record<ContentType, IMediaType>> {}
/**
* Media type of a request/response body.
*/
export interface IMediaType {
schema?: IJsonSchema;
example?: any;
examples?: Record<string, IExample>;
}
/**
* List of supported content media types.
*/
export type ContentType =
| "text/plain"
| "application/json"
| "application/x-www-form-url-encoded"
| "multipart/form-data"
| "*/*"
| (string & {});
}
/**
* Example of the operation parameter or response.
*/
export interface IExample {
summary?: string;
description?: string;
value?: any;
externalValue?: string;
}
/* -----------------------------------------------------------
SCHEMA DEFINITIONS
----------------------------------------------------------- */
/**
* Reusable components in OpenAPI.
*
* A storage of reusable components in OpenAPI document.
*
* In other words, it is a storage of named DTO schemas and security schemes.
*/
export interface IComponents {
/**
* An object to hold reusable DTO schemas.
*
* In other words, a collection of named JSON schemas.
*/
schemas?: Record<string, IJsonSchema>;
/**
* An object to hold reusable security schemes.
*
* In other words, a collection of named security schemes.
*/
securitySchemes?: Record<string, ISecurityScheme>;
}
/**
* Type schema info.
*
* `OpenApi.IJsonSchema` is a type schema info of the OpenAPI.
*
* `OpenApi.IJsonSchema` basically follows the JSON schema definition of
* OpenAPI v3.1, but a little bit shrunk to remove ambiguous and duplicated
* expressions of OpenAPI v3.1 for the convenience and clarity.
*
* - Decompose mixed type: {@link OpenApiV3_1.IJsonSchema.IMixed}
* - Resolve nullable property: {@link OpenApiV3_1.IJsonSchema.__ISignificant.nullable}
* - Array type utilizes only single {@link OpenAPI.IJsonSchema.IArray.items}
* - Tuple type utilizes only {@link OpenApi.IJsonSchema.ITuple.prefixItems}
* - Merge {@link OpenApiV3_1.IJsonSchema.IAllOf} to {@link OpenApi.IJsonSchema.IObject}
* - Merge {@link OpenApiV3_1.IJsonSchema.IAnyOf} to {@link OpenApi.IJsonSchema.IOneOf}
* - Merge {@link OpenApiV3_1.IJsonSchema.IRecursiveReference} to {@link OpenApi.IJsonSchema.IReference}
*/
export type IJsonSchema =
| IJsonSchema.IConstant
| IJsonSchema.IBoolean
| IJsonSchema.IInteger
| IJsonSchema.INumber
| IJsonSchema.IString
| IJsonSchema.IArray
| IJsonSchema.ITuple
| IJsonSchema.IObject
| IJsonSchema.IReference
| IJsonSchema.IOneOf
| IJsonSchema.INull
| IJsonSchema.IUnknown;
export namespace IJsonSchema {
/**
* Constant value type.
*/
export interface IConstant extends __IAttribute {
/**
* The constant value.
*/
const: boolean | number | string;
}
/**
* Boolean type info.
*/
export interface IBoolean extends __ISignificant<"boolean"> {
/**
* The default value.
*/
default?: boolean;
}
/**
* Integer type info.
*/
export interface IInteger extends __ISignificant<"integer"> {
/**
* Default value.
*
* @type int64
*/
default?: number;
/**
* Minimum value restriction.
*
* @type int64
*/
minimum?: number;
/**
* Maximum value restriction.
*
* @type int64
*/
maximum?: number;
/**
* Exclusive minimum value restriction.
*
* For reference, even though your Swagger (or OpenAPI) document has
* defined the `exclusiveMinimum` value as `number`, {@link OpenApi}
* forcibly converts it to `boolean` type, and assign the numeric value to
* the {@link minimum} property.
*/
exclusiveMinimum?: boolean;
/**
* Exclusive maximum value restriction.
*
* For reference, even though your Swagger (or OpenAPI) document has
* defined the `exclusiveMaximum` value as `number`, {@link OpenApi}
* forcibly converts it to `boolean` type, and assign the numeric value to
* the {@link maximum} property.
*/
exclusiveMaximum?: boolean;
/**
* Multiple of value restriction.
*
* @type uint64
* @exclusiveMinimum 0
*/
multipleOf?: number;
}
/**
* Number (double) type info.
*/
export interface INumber extends __ISignificant<"number"> {
/**
* Default value.
*/
default?: number;
/**
* Minimum value restriction.
*/
minimum?: number;
/**
* Maximum value restriction.
*/
maximum?: number;
/**
* Exclusive minimum value restriction.
*
* For reference, even though your Swagger (or OpenAPI) document has
* defined the `exclusiveMinimum` value as `number`, {@link OpenAiComposer}
* forcibly converts it to `boolean` type, and assign the numeric value to
* the {@link minimum} property.
*/
exclusiveMinimum?: boolean;
/**
* Exclusive maximum value restriction.
*
* For reference, even though your Swagger (or OpenAPI) document has
* defined the `exclusiveMaximum` value as `number`, {@link OpenAiComposer}
* forcibly converts it to `boolean` type, and assign the numeric value to
* the {@link maximum} property.
*/
exclusiveMaximum?: boolean;
/**
* Multiple of value restriction.
*
* @exclusiveMinimum 0
*/
multipleOf?: number;
}
/**
* String type info.
*/
export interface IString extends __ISignificant<"string"> {
/**
* Default value.
*/
default?: string;
/**
* Format restriction.
*/
format?:
| "binary"
| "byte"
| "password"
| "regex"
| "uuid"
| "email"
| "hostname"
| "idn-email"
| "idn-hostname"
| "iri"
| "iri-reference"
| "ipv4"
| "ipv6"
| "uri"
| "uri-reference"
| "uri-template"
| "url"
| "date-time"
| "date"
| "time"
| "duration"
| "json-pointer"
| "relative-json-pointer"
| (string & {});
/**
* Pattern restriction.
*/
pattern?: string;
/**
* Content media type restriction.
*/
contentMediaType?: string;
/**
* Minimum length restriction.
*
* @type uint64
*/
minLength?: number;
/**
* Maximum length restriction.
*
* @type uint64
*/
maxLength?: number;
}
/**
* Array type info.
*/
export interface IArray extends __ISignificant<"array"> {
/**
* Items type info.
*
* The `items` means the type of the array elements. In other words, it is
* the type schema info of the `T` in the TypeScript array type `Array<T>`.
*/
items: IJsonSchema;
/**
* Unique items restriction.
*
* If this property value is `true`, target array must have unique items.
*/
uniqueItems?: boolean;
/**
* Minimum items restriction.
*
* Restriction of minimum number of items in the array.
*
* @type uint64
*/
minItems?: number;
/**
* Maximum items restriction.
*
* Restriction of maximum number of items in the array.
*
* @type uint64
*/
maxItems?: number;
}
/**
* Tuple type info.
*/
export interface ITuple extends __ISignificant<"array"> {
/**
* Prefix items.
*
* The `prefixItems` means the type schema info of the prefix items in the
* tuple type. In the TypeScript, it is expressed as `[T1, T2]`.
*
* If you want to express `[T1, T2, ...TO[]]` type, you can configure the
* `...TO[]` through the {@link additionalItems} property.
*/
prefixItems: IJsonSchema[];
/**
* Additional items.
*
* The `additionalItems` means the type schema info of the additional items
* after the {@link prefixItems}. In the TypeScript, if there's a type
* `[T1, T2, ...TO[]]`, the `...TO[]` is represented by the `additionalItems`.
*
* By the way, if you configure the `additionalItems` as `true`, it means
* the additional items are not restricted. They can be any type, so that
* it is equivalent to the TypeScript type `[T1, T2, ...any[]]`.
*
* Otherwise configure the `additionalItems` as the {@link IJsonSchema},
* it means the additional items must follow the type schema info.
* Therefore, it is equivalent to the TypeScript type `[T1, T2, ...TO[]]`.
*/
additionalItems?: boolean | IJsonSchema;
/**
* Unique items restriction.
*
* If this property value is `true`, target tuple must have unique items.
*/
uniqueItems?: boolean;
/**
* Minimum items restriction.
*
* Restriction of minimum number of items in the tuple.
*
* @type uint64
*/
minItems?: number;
/**
* Maximum items restriction.
*
* Restriction of maximum number of items in the tuple.
*
* @type uint64
*/
maxItems?: number;
}
/**
* Object type info.
*/
export interface IObject extends __ISignificant<"object"> {
/**
* Properties of the object.
*
* The `properties` means a list of key-value pairs of the object's
* regular properties. The key is the name of the regular property,
* and the value is the type schema info.
*
* If you need additional properties that is represented by dynamic key,
* you can use the {@link additionalProperties} instead.
*/
properties?: Record<string, IJsonSchema>;
/**
* Additional properties' info.
*
* The `additionalProperties` means the type schema info of the additional
* properties that are not listed in the {@link properties}.
*
* If the value is `true`, it means that the additional properties are not
* restricted. They can be any type. Otherwise, if the value is
* {@link IOpenAiSchema} type, it means that the additional properties must
* follow the type schema info.
*
* - `true`: `Record<string, any>`
* - `IOpenAiSchema`: `Record<string, T>`
*/
additionalProperties?: boolean | IJsonSchema;
/**
* List of key values of the required properties.
*
* The `required` means a list of the key values of the required
* {@link properties}. If some property key is not listed in the `required`
* list, it means that property is optional. Otherwise some property key
* exists in the `required` list, it means that the property must be filled.
*
* Below is an example of the {@link properties} and `required`.
*
* ```typescript
* interface SomeObject {
* id: string;
* email: string;
* name?: string;
* }
* ```
*
* As you can see, `id` and `email` {@link properties} are {@link required},
* so that they are listed in the `required` list.
*