-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.ts
More file actions
111 lines (103 loc) · 3.21 KB
/
types.ts
File metadata and controls
111 lines (103 loc) · 3.21 KB
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
import { OpenAPIV3 } from 'openapi-types';
import { ModelTypes, TypeGenTypes, methods, schemaTypeHints, validators } from './lib';
export type ValueOf<T> = T[keyof T];
export type SchemaComponent = ValueOf<ValueOf<OpenAPIV3.ComponentsObject>>;
export type NonRefSchema =
| OpenAPIV3.SchemaObject
| OpenAPIV3.ResponseObject
| OpenAPIV3.ParameterObject
| OpenAPIV3.ExampleObject
| OpenAPIV3.RequestBodyObject
| OpenAPIV3.HeaderObject
| OpenAPIV3.SecuritySchemeObject
| OpenAPIV3.LinkObject
| OpenAPIV3.CallbackObject;
export type TypeGenType = (typeof TypeGenTypes)[keyof typeof TypeGenTypes];
export type ModelType = (typeof ModelTypes)[keyof typeof ModelTypes];
export type TypeGenRef = { tType: typeof TypeGenTypes.remoteRef | typeof TypeGenTypes.ref; name: string };
export type Validations = Partial<Record<keyof typeof validators, any>>;
export type Method = keyof typeof methods;
export type SchemaTypeHint = (typeof schemaTypeHints)[keyof typeof schemaTypeHints];
export type TypeGenTypeDep = TypeGenModel<SchemaComponent> | TypeGenRef;
export type TypeGenSchemaRefString = string;
export interface TypeGenModel<T = SchemaComponent> {
name: string;
tType: TypeGenType;
schema: T;
location: string;
type?: ModelType | string;
enum?: string[];
description?: string;
validations?: Validations;
dependencies?: TypeGenTypeDep[];
fields?: TypeGenTypeField[];
array?: boolean;
extras?: Record<string, any>;
anyOf?: (TypeGenModel | TypeGenRef)[];
allOf?: (TypeGenModel | TypeGenRef)[];
oneOf?: (TypeGenModel | TypeGenRef)[];
}
export interface TypeGenTypeField {
name: string;
tType: TypeGenType;
type: ModelType | TypeGenSchemaRefString;
validations: Validations;
schema?: unknown;
location?: string;
description?: string;
subtype?: string;
enum?: string[];
array?: boolean;
extras?: Record<string, any>;
default?: any;
}
export interface TypeGenPathItem {
name: string;
tType: typeof TypeGenTypes.path;
schema: OpenAPIV3.PathItemObject;
description?: string;
methods?: (Omit<TypeGenMethod, 'path'> & { path: string })[];
}
export interface TypeGenMethod {
name: string;
method: Method;
tType: typeof TypeGenTypes.method;
schema: OpenAPIV3.OperationObject;
path: TypeGenPathItem;
pathParams: TypeGenRef[];
headerParams: TypeGenRef[];
queryParams: TypeGenRef[];
responses: TypeGenResponse[];
pathObject?: TypeGenRef;
headerObject?: TypeGenRef;
queryObject?: TypeGenRef;
requestBodies?: TypeGenBody[];
description?: string;
tags?: string[];
security?: TypeGenModel[];
}
export interface TypeGenResponse {
name: string;
status: number;
payload: TypeGenRef;
headers?: Record<string, TypeGenRef>;
type: TypeGenSchemaRefString;
tType?: typeof TypeGenTypes.response | typeof TypeGenTypes.remoteRef;
array?: boolean;
description?: string;
contentType?: string;
}
export interface TypeGenBody {
name: string;
tType: typeof TypeGenTypes.requestBody;
payload: TypeGenRef;
type: TypeGenSchemaRefString;
description?: string;
contentType?: string;
validators?: { required: true };
}
export type SchemaTypeData<T extends Record<string, unknown> = {}> = {
name?: string;
deps?: TypeGenTypeDep[];
required?: Record<string, boolean>;
} & T;