/
oas_3_tools.d.ts
202 lines (202 loc) · 7.52 KB
/
oas_3_tools.d.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
/**
* Utility functions around the OpenAPI Specification 3.
*/
import { Oas2 } from './types/oas2';
import { Operation } from './types/operation';
import { Oas3, ServerObject, ParameterObject, SchemaObject, OperationObject, ReferenceObject, LinkObject, SecuritySchemeObject } from './types/oas3.js';
import { PreprocessingData, ProcessedSecurityScheme } from './types/preprocessing_data';
import { InternalOptions } from './types/options';
export declare type SchemaNames = {
fromPath?: string;
fromSchema?: string;
fromRef?: string;
/**
* Used when the preferred name is known, i.e. a new data def does not need to
* be created
*/
preferred?: string;
};
export declare type RequestSchemaAndNames = {
payloadContentType?: string;
payloadSchema?: SchemaObject | ReferenceObject;
payloadSchemaNames?: SchemaNames;
payloadRequired: boolean;
};
export declare type ResponseSchemaAndNames = {
responseContentType?: string;
responseSchema?: SchemaObject | ReferenceObject;
responseSchemaNames?: SchemaNames;
statusCode?: string;
};
export declare const OAS_OPERATIONS: string[];
export declare const SUCCESS_STATUS_RX: RegExp;
/**
* Resolves on a validated OAS 3 for the given spec (OAS 2 or OAS 3), or rejects
* if errors occur.
*/
export declare function getValidOAS3(spec: Oas2 | Oas3): Promise<Oas3>;
/**
* Counts the number of operations in an OAS.
*/
export declare function countOperations(oas: Oas3): number;
/**
* Counts the number of operations that translate to queries in an OAS.
*/
export declare function countOperationsQuery(oas: Oas3): number;
/**
* Counts the number of operations that translate to mutations in an OAS.
*/
export declare function countOperationsMutation(oas: Oas3): number;
/**
* Counts the number of operations with a payload definition in an OAS.
*/
export declare function countOperationsWithPayload(oas: Oas3): number;
/**
* Resolves the given reference in the given object.
*/
export declare function resolveRef(ref: string, obj: object, parts?: string[]): any;
/**
* Returns the base URL to use for the given operation.
*/
export declare function getBaseUrl(operation: Operation): string;
/**
* Returns object | array where all object keys are sanitized. Keys passed in
* exceptions are not sanitized.
*/
export declare function sanitizeObjKeys(obj: object | Array<any>, exceptions?: string[]): object | Array<any>;
/**
* Desanitizes keys in given object by replacing them with the keys stored in
* the given mapping.
*/
export declare function desanitizeObjKeys(obj: object | Array<any>, mapping?: object): object | Array<any>;
/**
* Replaces the path parameter in the given path with values in the given args.
* Furthermore adds the query parameters for a request.
*/
export declare function instantiatePathAndGetQuery(path: string, parameters: ParameterObject[], args: object): {
path: string;
query: {
[key: string]: string;
};
headers: {
[key: string]: string;
};
};
/**
* Returns the "type" of the given JSON schema. Makes best guesses if the type
* is not explicitly defined.
*/
export declare function getSchemaType(schema: SchemaObject): string | null;
/**
* Determines an approximate name for the resource at the given path.
*/
export declare function inferResourceNameFromPath(path: string): string;
/**
* Returns JSON-compatible schema required by the given endpoint - or null if it
* does not exist.
*/
export declare function getRequestSchema(endpoint: OperationObject, oas: Oas3): {
payloadContentType: string;
payloadSchema: SchemaObject;
} | null;
/**
* Returns the request schema (if any) for an endpoint at given path and method,
* a dictionary of names from different sources (if available), and whether the
* request schema is required for the endpoint.
*/
export declare function getRequestSchemaAndNames(path: string, method: string, oas: Oas3): RequestSchemaAndNames;
/**
* Returns JSON-compatible schema produced by the given endpoint - or null if it
* does not exist.
*/
export declare function getResponseSchema(endpoint: OperationObject, statusCode: string, oas: Oas3): {
responseContentType: string;
responseSchema: SchemaObject;
} | null;
/**
* Returns the response schema for endpoint at given path and method and with
* the given status code, and a dictionary of names from different sources (if
* available).
*/
export declare function getResponseSchemaAndNames(path: string, method: string, oas: Oas3, data: PreprocessingData, options: InternalOptions): ResponseSchemaAndNames;
/**
* Returns the success status code for the operation at the given path and
* method (or null).
*/
export declare function getResponseStatusCode(path: string, method: string, oas: Oas3, data: PreprocessingData): string | void;
/**
* Returns an hash containing the links defined in the given endpoint.
*/
export declare function getEndpointLinks(path: string, method: string, oas: Oas3, data: PreprocessingData): {
[key: string]: LinkObject;
};
/**
* Returns the list of parameters for the endpoint at the given method and path.
* Resolves possible references.
*/
export declare function getParameters(path: string, method: string, oas: Oas3): ParameterObject[];
/**
* Returns an array of server objects for the opeartion at the given path and
* method. Considers in the following order: global server definitions,
* definitions at the path item, definitions at the operation, or the OAS
* default.
*/
export declare function getServers(path: string, method: string, oas: Oas3): ServerObject[];
/**
* Returns a map of Security Scheme definitions, identified by keys. Resolves
* possible references.
*/
export declare function getSecuritySchemes(oas: Oas3): {
[key: string]: SecuritySchemeObject;
};
/**
* Returns the list of sanitized keys of non-OAuth2 security schemes
* required by the operation at the given path and method.
*/
export declare function getSecurityRequirements(path: string, method: string, securitySchemes: {
[key: string]: ProcessedSecurityScheme;
}, oas: Oas3): string[];
/**
* First sanitizes given string and then also camel-cases it.
*/
export declare function sanitize(str: string, lowercaseFirstChar?: boolean): string;
/**
* Sanitizes the given string and stores the sanitized-to-original mapping in
* the given mapping.
*/
export declare function sanitizeAndStore(str: string, mapping: {
[key: string]: string;
}): string;
/**
* Return an object similar to the input object except the keys are all
* sanitized
*/
export declare function sanitizeObjectKeys(obj: object): object;
/**
* Stringifies and possibly trims the given string to the provided length.
*/
export declare function trim(str: string, length: number): string;
/**
* Determines if the given "method" is indeed an operation. Alternatively, the
* method could point to other types of information (e.g., parameters, servers).
*/
export declare function isOperation(method: string): boolean;
/**
* Formats a string that describes an operation in the form:
* {name of OAS} {HTTP method in ALL_CAPS} {operation path}
*
* Also used in preprocessing.ts where Operation objects are being constructed
*/
export declare function formatOperationString(method: string, path: string, title?: string): string;
/**
* Capitalizes a given string
*/
export declare function capitalize(str: string): string;
/**
* Uncapitalizes a given string
*/
export declare function uncapitalize(str: string): string;
/**
* For operations that do not have an operationId, generate one
*/
export declare function generateOperationId(method: string, path: string): string;