import { IPrism, IPrismComponents, IPrismProxyConfig, IPrismMockConfig } from '@stoplight/prism-core'; import { Overwrite } from 'utility-types'; import { Dictionary, HttpMethod, IHttpOperation, INodeExample, INodeExternalExample } from '@stoplight/types'; import type { JSONSchema7 } from 'json-schema'; import { Either } from 'fp-ts/Either'; export type PrismHttpInstance = IPrism; export type PrismHttpComponents = IPrismComponents; export interface IHttpOperationConfig { mediaTypes?: string[]; code?: number; exampleKey?: string; dynamic: boolean; } export type IHttpMockConfig = Overwrite; export type IHttpProxyConfig = Overwrite; export type IHttpConfig = IHttpProxyConfig | IHttpMockConfig; export type IHttpNameValues = Dictionary; export type IHttpNameValue = Dictionary; export interface IHttpUrl { baseUrl?: string; path: string; query?: IHttpNameValues; } export interface IHttpRequest { method: HttpMethod; url: IHttpUrl; headers?: IHttpNameValue; body?: unknown; } export interface IHttpResponse { statusCode: number; headers?: IHttpNameValue; body?: unknown; } export type ProblemJson = { type: string; title: string; status: number; detail: string; }; export class ProblemJsonError extends Error { public static fromTemplate( template: Omit, detail?: string, additional?: Dictionary ): ProblemJsonError { return new ProblemJsonError( `https://stoplight.io/prism/errors#${template.type}`, template.title, template.status, detail || '', additional ); } public static toProblemJson( error: Error & { detail?: string; status?: number; additional?: Dictionary } ): ProblemJson { return { type: error.name && error.name !== 'Error' ? error.name : 'https://stoplight.io/prism/errors#UNKNOWN', title: error.message, status: error.status || 500, detail: error.detail || '', ...error.additional, }; } constructor( readonly name: string, readonly message: string, readonly status: number, readonly detail: string, readonly additional?: Dictionary ) { super(message); } } export type ContentExample = INodeExample | INodeExternalExample; export type PayloadGenerator = (f: JSONSchema) => Either; export type PickRequired = Omit & Required>; export type JSONSchema = JSONSchema7;