ts / dist / esm / spec-check.d.ts
234 words
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/**
 * Validate a parsed API response against the OpenAPI schema the committed
 * `spec/openapi.json` declares for it.
 *
 * Deliberately small: it checks the properties that actually catch drift
 * between the spec and what the API returns — declared types, `required`
 * keys, `enum`/`const` membership, `oneOf` alternatives, and — because
 * every object in this spec is `additionalProperties: false` — fields the
 * server sends that the schema does not list. Anything it does not
 * understand it passes.
 */
import type { MethodKey } from './types.js';
export type Schema = Readonly<{
    type?: string | readonly string[];
    properties?: Readonly<Record<string, Schema>>;
    required?: readonly string[];
    items?: Schema;
    enum?: readonly unknown[];
    const?: unknown;
    oneOf?: readonly Schema[];
    additionalProperties?: boolean | Schema;
}>;
type MediaTypes = Readonly<Record<string, Readonly<{
    schema?: Schema;
}>>>;
type Responses = Readonly<Record<string, Readonly<{
    content?: MediaTypes;
}>>>;
export type OpenApiSpec = Readonly<{
    paths?: Readonly<Record<string, Readonly<Partial<Record<MethodKey, Readonly<{
        responses?: Responses;
    }>>>>>>;
}>;
/**
 * Problems found validating VALUE against SCHEMA, as human-readable
 * strings; empty when the response conforms. PATH prefixes each message so
 * a problem can be located in a nested body.
 */
export declare const check: (schema: Schema | undefined, value: unknown, path?: string) => readonly string[];
/** The schema SPEC declares for METHOD PATH's STATUS response, or undefined when it documents no JSON body. */
export declare const responseSchema: (spec: OpenApiSpec, method: MethodKey, path: string, status: number) => Schema | undefined;
export {};

static mirror of HEAD · about · clone: git clone https://ird.cod-sursa.ro/ts.git