/** * Utility functions around the OpenAPI Specification 3. */ import { Oas2 } from './types/oas2'; import { TargetGraphQLType, Operation } from './types/operation'; import { Oas3, ServerObject, ParameterObject, SchemaObject, OperationObject, PathItemObject, ReferenceObject, LinkObject, SecuritySchemeObject } from './types/oas3'; import { PreprocessingData, ProcessedSecurityScheme } from './types/preprocessing_data'; import { InternalOptions } from './types/options'; export type SchemaNames = { fromExtension?: string; fromRef?: string; fromSchema?: string; fromPath?: string; /** * Used when the preferred name is known, i.e. a new data def does not need to * be created */ preferred?: string; }; export type RequestSchemaAndNames = { payloadContentType?: string; payloadSchema?: SchemaObject; payloadSchemaNames?: SchemaNames; payloadRequired: boolean; }; export type ResponseSchemaAndNames = { responseContentType?: string; responseSchema?: SchemaObject; responseSchemaNames?: SchemaNames; statusCode?: string; }; export declare enum HTTP_METHODS { 'get' = "get", 'put' = "put", 'post' = "post", 'patch' = "patch", 'delete' = "delete", 'options' = "options", 'head' = "head" } export declare const SUCCESS_STATUS_RX: RegExp; export declare enum OAS_GRAPHQL_EXTENSIONS { TypeName = "x-graphql-type-name", FieldName = "x-graphql-field-name", EnumMapping = "x-graphql-enum-mapping" } /** * Given an HTTP method, convert it to the HTTP_METHODS enum */ export declare function methodToHttpMethod(method: string): HTTP_METHODS; export declare function isOas2(spec: any): spec is Oas2; export declare function isOas3(spec: any): spec is Oas3; /** * 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, oasValidatorOptions: object, swagger2OpenAPIOptions: object): Promise; /** * 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 that translate to subscriptions in an OAS. */ export declare function countOperationsSubscription(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, oas: Oas3): T; /** * Recursively traverse a schema and resolve allOf by appending the data to the * parent schema */ export declare function resolveAllOf(schema: SchemaObject | ReferenceObject, references: { [reference: string]: SchemaObject; }, data: PreprocessingData, oas: Oas3): SchemaObject; /** * Returns the base URL to use for the given operation. */ export declare function getBaseUrl(operation: Operation): string; /** * Returns object/array/scalar where all object keys (if applicable) are * sanitized. */ export declare function sanitizeObjectKeys(obj: any, // obj does not necessarily need to be an object caseStyle?: CaseStyle): any; /** * Desanitizes keys in given object by replacing them with the keys stored in * the given mapping. */ export declare function desanitizeObjectKeys(obj: object | Array, mapping?: object): object | Array; /** * Returns the GraphQL type that the provided schema should be made into */ export declare function getSchemaTargetGraphQLType(schemaOrRef: SchemaObject | ReferenceObject, data: PreprocessingData, oas: Oas3): TargetGraphQLType | null; /** * Infers a resource name from the given URL path. * * For example, turns "/users/{userId}/car" into "userCar". */ export declare function inferResourceNameFromPath(path: string): string; /** * Returns the request schema (if any) for the given operation, * a dictionary of names from different sources (if available), and whether the * request schema is required for the operation. */ export declare function getRequestSchemaAndNames(path: string, method: HTTP_METHODS, operation: OperationObject, oas: Oas3): RequestSchemaAndNames; /** * Returns the response schema for the given operation, * a successful status code, and a dictionary of names from different sources * (if available). */ export declare function getResponseSchemaAndNames(path: string, method: HTTP_METHODS, operation: OperationObject, oas: Oas3, data: PreprocessingData, options: InternalOptions): ResponseSchemaAndNames; /** * Returns a success status code for the given operation */ export declare function getResponseStatusCode(path: string, method: string, operation: OperationObject, oas: Oas3, data: PreprocessingData): string; /** * Returns a hash containing the links in the given operation. */ export declare function getLinks(path: string, method: HTTP_METHODS, operation: OperationObject, oas: Oas3, data: PreprocessingData): { [key: string]: LinkObject; }; /** * Returns the list of parameters in the given operation. */ export declare function getParameters(path: string, method: HTTP_METHODS, operation: OperationObject, pathItem: PathItemObject, oas: Oas3): ParameterObject[]; /** * Returns an array of server objects for the operation 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(operation: OperationObject, pathItem: PathItemObject, oas: Oas3): ServerObject[]; /** * Returns a map of security scheme definitions, identified by keys. Resolves * possible references. */ export declare function getSecuritySchemes(oas: Oas3): { [schemeKey: 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(operation: OperationObject, securitySchemes: { [key: string]: ProcessedSecurityScheme; }, oas: Oas3): string[]; export declare enum CaseStyle { simple = 0, PascalCase = 1, camelCase = 2, ALL_CAPS = 3 } /** * Checks to see if the provided string is GraphQL-safe */ export declare function isSanitized(str: string): boolean; /** * First sanitizes given string and then also camelCases it. */ export declare function sanitize(str: string, caseStyle: CaseStyle): string; /** * Sanitizes the given string and stores the sanitized-to-original mapping in * the given mapping. */ export declare function storeSaneName(saneStr: string, str: string, mapping: { [key: string]: string; }): string; /** * 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 isHttpMethod(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: HTTP_METHODS, path: string): string;