1 | /// <reference types="express" />
|
2 | import { ReferenceObject, SchemaObject } from '@loopback/openapi-v3';
|
3 | import { Request } from '../types';
|
4 | /**
|
5 | * Request body with metadata
|
6 | */
|
7 | export type RequestBody = {
|
8 | /**
|
9 | * Parsed value of the request body
|
10 | */
|
11 | value: any | undefined;
|
12 | /**
|
13 | * Is coercion required? Some forms of request such as urlencoded don't
|
14 | * have rich types such as number or boolean.
|
15 | */
|
16 | coercionRequired?: boolean;
|
17 | /**
|
18 | * Resolved media type
|
19 | */
|
20 | mediaType?: string;
|
21 | /**
|
22 | * Corresponding schema for the request body
|
23 | */
|
24 | schema?: SchemaObject | ReferenceObject;
|
25 | };
|
26 | /**
|
27 | * Interface to be implemented by body parser extensions
|
28 | */
|
29 | export interface BodyParser {
|
30 | /**
|
31 | * Name of the parser
|
32 | */
|
33 | name: string | symbol;
|
34 | /**
|
35 | * Indicate if the given media type is supported
|
36 | * @param mediaType - Media type
|
37 | */
|
38 | supports(mediaType: string): boolean;
|
39 | /**
|
40 | * Parse the request body
|
41 | * @param request - http request
|
42 | */
|
43 | parse(request: Request): Promise<RequestBody>;
|
44 | }
|
45 | /**
|
46 | * Plain function for body parsing
|
47 | */
|
48 | export type BodyParserFunction = (request: Request) => Promise<RequestBody>;
|
49 | /**
|
50 | * Binding tag for request body parser extensions
|
51 | */
|
52 | export declare const REQUEST_BODY_PARSER_TAG = "rest.requestBodyParser";
|