@swarmion/serverless-contracts
Version:
Generate and use type-safe contracts between your Serverless services.
107 lines • 5.39 kB
TypeScript
import { JSONSchema } from 'json-schema-to-ts';
import { StringDictionaryJSONSchema } from '../../types/constrainedJSONSchema';
import { HttpMethod, HttpStatusCodes } from '../../types/http';
import { ApiGatewayAuthorizerType, ApiGatewayIntegrationType } from './types/constants';
/**
* ApiGatewayContract:
*
* a contract used to define a type-safe interaction between AWS Services through Api Gateway.
*
* Main features:
* - input and output dynamic validation with JSONSchemas on both end of the contract;
* - type inference for both input and output;
* - generation of a contract document that can be checked for breaking changes;
* - generation of open api documentation
*/
export declare class ApiGatewayContract<Path extends string = string, Method extends HttpMethod = HttpMethod, IntegrationType extends ApiGatewayIntegrationType = ApiGatewayIntegrationType, AuthorizerType extends ApiGatewayAuthorizerType = undefined, PathParametersSchema extends StringDictionaryJSONSchema | undefined = undefined, QueryStringParametersSchema extends StringDictionaryJSONSchema | undefined = undefined, HeadersSchema extends StringDictionaryJSONSchema | undefined = undefined, RequestContextSchema extends JSONSchema | undefined = undefined, BodySchema extends JSONSchema | undefined = undefined, PropsOutputSchemas extends Partial<Record<HttpStatusCodes, JSONSchema>> | undefined = undefined, OutputSchemas = Exclude<PropsOutputSchemas, undefined>> {
contractType: "apiGateway";
id: string;
path: Path;
method: Method;
integrationType: IntegrationType;
authorizerType: AuthorizerType;
pathParametersSchema: PathParametersSchema;
queryStringParametersSchema: QueryStringParametersSchema;
headersSchema: HeadersSchema;
requestContextSchema: RequestContextSchema;
bodySchema: BodySchema;
outputSchemas: OutputSchemas;
inputSchema: JSONSchema;
/**
* Builds a new ApiGateway contract
*
* @param props - the contract properties
*/
constructor(props: {
/**
* An id to uniquely identify the contract among services. Beware of uniqueness!
*/
id: string;
/**
* The path on which the lambda will be triggered
*/
path: Path;
/**
* The http method
*/
method: Method;
/**
* `'httpApi'` or `'restApi'`, see https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-vs-rest.html
*/
integrationType: IntegrationType;
/**
* Indicates which type of authorizer is used for this contract.
*/
authorizerType?: AuthorizerType;
/**
* A JSONSchema used to validate the path parameters and infer their types.
*
* Please note that the `as const` directive is necessary to properly infer the type from the schema.
* See https://github.com/ThomasAribart/json-schema-to-ts#fromschema.
*/
pathParametersSchema?: PathParametersSchema;
/**
* A JSONSchema used to validate the query parameters and infer their types.
*
* Please note that the `as const` directive is necessary to properly infer the type from the schema.
* See https://github.com/ThomasAribart/json-schema-to-ts#fromschema.
*/
queryStringParametersSchema?: QueryStringParametersSchema;
/**
* A JSONSchema used to validate the headers and infer their types.
*
* Please note that the `as const` directive is necessary to properly infer the type from the schema.
* See https://github.com/ThomasAribart/json-schema-to-ts#fromschema.
*/
headersSchema?: HeadersSchema;
/**
* A JSONSchema used to validate the requestContext and infer its type.
*
* Please note that the `as const` directive is necessary to properly infer the type from the schema.
* See https://github.com/ThomasAribart/json-schema-to-ts#fromschema.
*/
requestContextSchema?: RequestContextSchema;
/**
* A JSONSchema used to validate the body and infer its type.
*
* Please note that the `as const` directive is necessary to properly infer the type from the schema.
* See https://github.com/ThomasAribart/json-schema-to-ts#fromschema.
*/
bodySchema?: BodySchema;
/**
* A record of JSONSchemas used to validate different outputs and infer their types depending on the return status code.
*
* Please note that the `as const` directive is necessary to properly infer the type from the schema.
* See https://github.com/ThomasAribart/json-schema-to-ts#fromschema.
*/
outputSchemas?: PropsOutputSchemas;
});
private getInputSchema;
}
/**
* The type of an ApiGateway contract using all default types.
*
* It is used internally to type contract features input
*/
export type GenericApiGatewayContract = ApiGatewayContract<string, HttpMethod, ApiGatewayIntegrationType, ApiGatewayAuthorizerType, StringDictionaryJSONSchema | undefined, StringDictionaryJSONSchema | undefined, StringDictionaryJSONSchema | undefined, JSONSchema | undefined, JSONSchema | undefined, Partial<Record<HttpStatusCodes, JSONSchema>>>;
//# sourceMappingURL=apiGatewayContract.d.ts.map