zzapi
Version:
zzAPI is a REST API testing and documentation tool set. It is an open-source Postman alternative.
151 lines (139 loc) • 4.45 kB
text/typescript
import { Method, CancelableRequest, Response } from 'got';
interface Param {
name: string;
value?: any;
}
interface Options {
follow: boolean;
verifySSL: boolean;
keepRawJSON: boolean;
showHeaders: boolean;
rawParams: boolean;
stopOnFailure: boolean;
}
type Assertion = number | boolean | string | null | {
[op: string]: any;
};
interface Tests {
json: {
[key: string]: Assertion;
};
headers: {
[key: string]: Assertion;
};
body?: Assertion;
status?: Assertion;
}
interface SetVar {
varName: string;
type: "json" | "header" | "status" | "body";
spec: string;
}
interface RequestSpec {
name: string;
httpRequest: {
baseUrl?: string;
url: string;
method: Method;
params: Param[];
headers: {
[key: string]: string;
};
body?: any;
formValues?: Param[];
};
expectJson: boolean;
options: Options;
tests: Tests;
setvars: SetVar[];
}
interface ResponseData {
executionTime: number | string;
status?: number;
body: string;
rawHeaders: string;
headers: {
[key: string]: string;
};
json: any;
}
interface RequestPosition {
name?: string;
start: {
line: number;
col: number;
};
end: {
line: number;
col: number;
};
}
interface TestResult {
pass: boolean;
op: string;
expected: any;
received: any;
message?: string;
}
interface SpecResult {
spec: string | null;
skipped?: boolean;
results: TestResult[];
subResults: SpecResult[];
}
type GotRequest = CancelableRequest<Response<string>>;
/**
* @param document the yaml document to parse to form the requests
* @returns An array of RequestPosition objects
*/
declare function getRequestPositions(document: string): RequestPosition[];
/**
* @param document the yaml document to parse to form the requests
* @returns An object of type { [name: string]: RequestSpec } where each value is the data
* of a request of the name key
*/
declare function getAllRequestSpecs(document: string): {
[name: string]: RequestSpec;
};
/**
* @param document the yaml document to parse to form the requests
* @returns An object of type RequestSpec
*/
declare function getRequestSpec(document: string, name: string): RequestSpec;
type Variables = {
[key: string]: any;
};
declare class VarStore {
loadedVariables: Variables;
capturedVariables: Variables;
getLoadedVariables(): Variables;
setLoadedVariables(vars: Variables): void;
resetLoadedVariables(vars: Variables): void;
mergeLoadedVariables(vars: Variables): void;
getCapturedVariables(): Variables;
setCapturedVariables(vars: Variables): void;
resetCapturedVariables(): void;
mergeCapturedVariables(vars: Variables): void;
getAllVariables(): Variables;
}
declare function getEnvironments(bundleContent: string | undefined, varFileContents: string[]): string[];
declare function loadVariables(envName: string | undefined, bundleContent: string | undefined, varFileContents: string[]): Variables;
declare function replaceVariablesInRequest(request: RequestSpec, variables: Variables): string[];
declare function constructGotRequest(allData: RequestSpec, workingDir?: string): GotRequest;
declare function executeGotRequest(httpRequest: GotRequest): Promise<{
response: {
[key: string]: any;
};
executionTime: number;
byteLength: number;
error: string;
}>;
declare function getCurlRequest(request: RequestSpec, workingDir?: string): string;
declare function runAllTests(tests: Tests, responseData: ResponseData, stopOnFailure: boolean, rootSpec?: string | null, skip?: boolean): SpecResult;
declare function captureVariables(requestData: RequestSpec, responseData: ResponseData): {
capturedVars: Variables;
captureErrors: string;
};
declare function convertCollection(filePath: string): string;
declare function convertEnvironment(filePath: string): string;
export { type GotRequest, type RequestPosition, type RequestSpec, type ResponseData, type SpecResult, type TestResult, type Tests, VarStore, type Variables, captureVariables, constructGotRequest, convertCollection, convertEnvironment, executeGotRequest, getAllRequestSpecs, getCurlRequest, getEnvironments, getRequestPositions, getRequestSpec, loadVariables, replaceVariablesInRequest, runAllTests };