|
| 1 | +/** |
| 2 | + * Utility functions around the OpenAPI Specification 3. |
| 3 | + */ |
| 4 | +import { Oas2 } from './types/oas2'; |
| 5 | +import { Operation } from './types/operation'; |
| 6 | +import { Oas3, ServerObject, ParameterObject, SchemaObject, OperationObject, ReferenceObject, LinkObject, SecuritySchemeObject } from './types/oas3.js'; |
| 7 | +import { PreprocessingData } from './types/preprocessing_data'; |
| 8 | +import { InternalOptions } from './types/options'; |
| 9 | +export declare type SchemaNames = { |
| 10 | + fromPath?: string; |
| 11 | + fromSchema?: string; |
| 12 | + fromRef?: string; |
| 13 | +}; |
| 14 | +export declare type RequestSchemaAndNames = { |
| 15 | + payloadContentType?: string; |
| 16 | + payloadSchema?: SchemaObject | ReferenceObject; |
| 17 | + payloadSchemaNames?: SchemaNames; |
| 18 | + payloadRequired: boolean; |
| 19 | +}; |
| 20 | +export declare type ResponseSchemaAndNames = { |
| 21 | + responseContentType?: string; |
| 22 | + responseSchema?: SchemaObject | ReferenceObject; |
| 23 | + responseSchemaNames?: SchemaNames; |
| 24 | + statusCode?: string; |
| 25 | +}; |
| 26 | +export declare const OAS_OPERATIONS: string[]; |
| 27 | +export declare const SUCCESS_STATUS_RX: RegExp; |
| 28 | +/** |
| 29 | + * Resolves on a validated OAS 3 for the given spec (OAS 2 or OAS 3), or rejects |
| 30 | + * if errors occur. |
| 31 | + */ |
| 32 | +export declare function getValidOAS3(spec: Oas2 | Oas3): Promise<Oas3>; |
| 33 | +/** |
| 34 | + * Counts the number of operations in an OAS. |
| 35 | + */ |
| 36 | +export declare function countOperations(oas: Oas3): number; |
| 37 | +/** |
| 38 | + * Counts the number of operations that translate to queries in an OAS. |
| 39 | + */ |
| 40 | +export declare function countOperationsQuery(oas: Oas3): number; |
| 41 | +/** |
| 42 | + * Counts the number of operations that translate to mutations in an OAS. |
| 43 | + */ |
| 44 | +export declare function countOperationsMutation(oas: Oas3): number; |
| 45 | +/** |
| 46 | + * Counts the number of operations with a payload definition in an OAS. |
| 47 | + */ |
| 48 | +export declare function countOperationsWithPayload(oas: Oas3): number; |
| 49 | +/** |
| 50 | + * Resolves the given reference in the given object. |
| 51 | + */ |
| 52 | +export declare function resolveRef(ref: string, obj: Object, parts?: string[]): any; |
| 53 | +/** |
| 54 | + * From the given OAS, returns the base URL to use for the given operation. |
| 55 | + */ |
| 56 | +export declare function getBaseUrl(oas: Oas3, operation: Operation): string; |
| 57 | +/** |
| 58 | + * Returns object | array where all object keys are sanitized. Keys passed in |
| 59 | + * exceptions are not sanitized. |
| 60 | + */ |
| 61 | +export declare function sanitizeObjKeys(obj: Object | Array<any>, exceptions?: string[]): Object | Array<any>; |
| 62 | +/** |
| 63 | + * Desanitizes keys in given object by replacing them with the keys stored in |
| 64 | + * the given mapping. |
| 65 | + */ |
| 66 | +export declare function desanitizeObjKeys(obj: Object | Array<any>, mapping?: Object): Object | Array<any>; |
| 67 | +/** |
| 68 | + * Replaces the path parameter in the given path with values in the given args. |
| 69 | + * Furthermore adds the query parameters for a request. |
| 70 | + */ |
| 71 | +export declare function instantiatePathAndGetQuery(path: string, parameters: ParameterObject[], args: Object): { |
| 72 | + path: string; |
| 73 | + query: { |
| 74 | + [key: string]: string; |
| 75 | + }; |
| 76 | + headers: { |
| 77 | + [key: string]: string; |
| 78 | + }; |
| 79 | +}; |
| 80 | +/** |
| 81 | + * Returns the "type" of the given JSON schema. Makes best guesses if the type |
| 82 | + * is not explicitly defined. |
| 83 | + */ |
| 84 | +export declare function getSchemaType(schema: SchemaObject): string | null; |
| 85 | +/** |
| 86 | + * Determines an approximate name for the resource at the given path. |
| 87 | + */ |
| 88 | +export declare function inferResourceNameFromPath(path: string): string; |
| 89 | +/** |
| 90 | + * Returns JSON-compatible schema required by the given endpoint - or null if it |
| 91 | + * does not exist. |
| 92 | + */ |
| 93 | +export declare function getRequestSchema(endpoint: OperationObject, oas: Oas3): { |
| 94 | + payloadContentType: string; |
| 95 | + payloadSchema: SchemaObject; |
| 96 | +} | null; |
| 97 | +/** |
| 98 | + * Returns the request schema (if any) for endpoint at given path and method, a |
| 99 | + * dictionary of names from different sources (if available), and whether the |
| 100 | + * request schema is required for the endpoint. |
| 101 | + */ |
| 102 | +export declare function getRequestSchemaAndNames(path: string, method: string, oas: Oas3): RequestSchemaAndNames; |
| 103 | +/** |
| 104 | + * Returns JSON-compatible schema produced by the given endpoint - or null if it |
| 105 | + * does not exist. |
| 106 | + */ |
| 107 | +export declare function getResponseSchema(endpoint: OperationObject, statusCode: string, oas: Oas3): { |
| 108 | + responseContentType: string; |
| 109 | + responseSchema: SchemaObject; |
| 110 | +} | null; |
| 111 | +/** |
| 112 | + * Returns the response schema for endpoint at given path and method and with |
| 113 | + * the given status code, and a dictionary of names from different sources (if |
| 114 | + * available). |
| 115 | + */ |
| 116 | +export declare function getResponseSchemaAndNames(path: string, method: string, oas: Oas3, data: PreprocessingData, options: InternalOptions): ResponseSchemaAndNames; |
| 117 | +/** |
| 118 | + * Returns the success status code for the operation at the given path and |
| 119 | + * method (or null). |
| 120 | + */ |
| 121 | +export declare function getResponseStatusCode(path: string, method: string, oas: Oas3, data: PreprocessingData): string | void; |
| 122 | +/** |
| 123 | + * Returns an hash containing the links defined in the given endpoint. |
| 124 | + */ |
| 125 | +export declare function getEndpointLinks(path: string, method: string, oas: Oas3, data: PreprocessingData): { |
| 126 | + [key: string]: LinkObject; |
| 127 | +}; |
| 128 | +/** |
| 129 | + * Returns the list of parameters for the endpoint at the given method and path. |
| 130 | + * Resolves possible references. |
| 131 | + */ |
| 132 | +export declare function getParameters(path: string, method: string, oas: Oas3): ParameterObject[]; |
| 133 | +/** |
| 134 | + * Returns an array of server objects for the opeartion at the given path and |
| 135 | + * method. Considers in the following order: global server definitions, |
| 136 | + * definitions at the path item, definitions at the operation, or the OAS |
| 137 | + * default. |
| 138 | + */ |
| 139 | +export declare function getServers(path: string, method: string, oas: Oas3): ServerObject[]; |
| 140 | +/** |
| 141 | + * Returns a map of Security Scheme definitions, identified by keys. Resolves |
| 142 | + * possible references. |
| 143 | + */ |
| 144 | +export declare function getSecuritySchemes(oas: Oas3): { |
| 145 | + [key: string]: SecuritySchemeObject; |
| 146 | +}; |
| 147 | +/** |
| 148 | + * Returns the list of BEAUTIFIED keys of NON-OAUTH 2 security schemes |
| 149 | + * required by the operation at the given path and method. |
| 150 | + */ |
| 151 | +export declare function getSecurityRequirements(path: string, method: string, securitySchemes: { |
| 152 | + [key: string]: SecuritySchemeObject; |
| 153 | +}, oas: Oas3): string[]; |
| 154 | +/** |
| 155 | + * Beautifies the given string and stores the sanitized-to-original mapping in |
| 156 | + * the given mapping. |
| 157 | + */ |
| 158 | +export declare function beautifyAndStore(str: string, mapping: { |
| 159 | + [key: string]: string; |
| 160 | +}): string; |
| 161 | +/** |
| 162 | + * First sanitizes given string and then also camel-cases it. |
| 163 | + */ |
| 164 | +export declare function beautify(str: string, lowercaseFirstChar?: boolean): string; |
| 165 | +/** |
| 166 | + * Stringifies and possibly trims the given string to the provided length. |
| 167 | + */ |
| 168 | +export declare function trim(str: string, length: number): string; |
| 169 | +/** |
| 170 | + * Determines if the given "method" is indeed an operation. Alternatively, the |
| 171 | + * method could point to other types of information (e.g., parameters, servers). |
| 172 | + */ |
| 173 | +export declare function isOperation(method: string): boolean; |
| 174 | +/** |
| 175 | + * Capitalizes a given string |
| 176 | + */ |
| 177 | +export declare function capitalize(str: string): string; |
| 178 | +/** |
| 179 | + * Uncapitalizes a given string |
| 180 | + */ |
| 181 | +export declare function uncapitalize(str: string): string; |
0 commit comments