@apistudio/apim-cli
Version:
CLI for API Management Products
150 lines (142 loc) • 5.17 kB
text/typescript
/**
* Copyright Super iPaaS Integration LLC, an IBM Company 2024
*/
import {FormParamDefinition, RequestBodyDefinition} from 'postman-collection';
import {Test,Test_Headers,Test_Auth, Test_Raw,
Test_UrlEncodedFormData,Test_Parameters,
Test_FormData,Test_Payload,Test_Settings,
Test_Assertions,Test_Request,Test_Environment, Test_Spec
} from '@apic/api-model/test/Test.js';
import {Environment as EnvironmentKind, Environment_Spec} from '@apic/api-model/test/Environment.js';
import {Assertion} from '@apic/api-model/test/Assertion.js';
import {Assert} from '@apic/api-model/test/common/Assert.js';
import {Variable} from '@apic/api-model/test/common/Variable.js';
import {Metadata} from '@apic/api-model/common/Metadata.js';
import {NewmanRunExecution} from 'newman';
import {GenericAssetAdaptor} from '@apic/api-model/adaptor/GenericAssetAdaptor.js';
import { AssertType } from '../service/assertMapper.js';
import {Ref} from '@apic/api-model/common/Ref.js';
export interface ExtendedNewmanRunExecution extends NewmanRunExecution {
id?:string
}
export interface ExtendedRequestBodyDefinition extends RequestBodyDefinition {
options?: {
raw: {
language: string;
};
};
}
export interface ExtendedFormParamDefinition extends FormParamDefinition {
type?: string;
src?: string;
}
export type Environment=Required<EnvironmentKind>;
export type TestSpec=Required<Test>;
export type RequestHeader=Required<Test_Headers>;
export type RequestAuth=Partial<Test_Auth>;
export type RawData=Partial<Test_Raw>;
export type UrlEncodedFormDataItem=Required<Test_UrlEncodedFormData>;
export type RequestParameter=Required<Test_Parameters>;
export type FormDataItem=Required<Test_FormData>;
export type RequestBodyObject=Partial<Test_Payload>;
export type RequestSettting=Partial<Test_Settings>;
export type ExpType=Required<Assert>;
export type Assertions=Partial<Test_Assertions>;
export type TestAssertion=Required<Assertion>;
export type RequestItem=Required<Test_Request>;
export type TestEnvironment=Partial<Test_Environment>;
export type EnvironmentVariable=Required<Variable>;
export type ApiReference=Required<Ref>;
export type Spec=Required<Test_Spec>;
export type Env_Spec=Required<Environment_Spec>;
export type TestMetadata=Required<Metadata>;
export interface SpecObject {
[key: string]: SpecObject | string;
}
export interface ErrorResponse {
code: string;
field: string;
description: string;
}
export type YamlContent=Required<GenericAssetAdaptor>;
export interface TestManagerInterface {
processFile(buffer: Buffer): Promise<unknown[]|null>;
}
export interface IConverter {
toString(input: number): string;
}
export interface AssetManagerInterface {
createAssetReferenceMap(buffer: Buffer): Promise<Map<string, boolean>>;
updateMapWithMetadata(yamlContent: YamlContent, refMap: Map<string, boolean>): void;
updateMapWithGatewayEndpoints(data: Buffer, refMap: Map<string, boolean>): Promise<void>;
}
export interface YamlValidatorInterface {
validateYamlFiles(buffer: Buffer): Promise<boolean>;
}
export interface RefParserInterface {
parseRef(ref: string): { namespace?: string, name: string, version: string };
}
export interface IGatewayAssetHandler {
getApiEndpoints(key: string):Promise<string[]>;
}
export interface IZipManager {
getEntryByName(entryName: string): Promise<string | undefined>;
}
export interface ICollectionCreator {
createCollection(parsedData: TestSpec, fileBuffer: Buffer):Promise<PostmanCollection>;
}
export interface PostmanCollection {
info: {
name: string;
version: string;
schema: string;
};
item: Array<{
name: string;
event: Array<{
listen: string;
script: {
exec: string[];
};
}>;
protocolProfileBehavior?: {
disableUrlEncoding?: boolean;
strictSSL?: boolean;
};
request: {
url: {
raw: string;
protocol: string;
host: string[];
path: string[];
port?: string;
query?: Array<{ key: string; value: string }>;
};
method: string;
header: Array<{ key: string; value: string }>;
body?: {
mode: string;
raw?: string;
formdata?: Array<{
key: string;
value?: string;
src?: string;
type: string;
}>;
urlencoded?: Array<{ key: string; value: string }>;
};
auth?: {
type: string;
basic?: Array<{ key: string; value: string }>;
bearer?: Array<{ key: string; value: string }>;
};
};
}>;
}
export interface IAssertMapper
{
converttoAssertionStructure(yamlObject: AssertType): string;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
getAssertionModel(name: string, key: string, value: any, action:string): string;
// validateAssertionModel()
}