import { JSONObject } from "kuzzle-sdk"; import { KuzzleRequest } from "../../api/request"; /** * API controller definition. * * @example * { * actions: { * sayHello: { * handler: async request => `Hello, ${request.input.args.name}`, * http: [{ verb: 'post', path: '/greeting/hello/:name' }] * } * } * } */ export type ControllerDefinition = { /** * Definition of controller actions * * @example * { * sayHello: { * handler: async request => `Hello, ${request.input.args.name}`, * http: [{ * verb: 'post', * path: '/greeting/hello/:name', * openapi: { * description: "Simply say hello", * responses: { * 200: { * description: "Custom greeting", * content: { * "application/json": { * schema: { * type: "string", * } * } * } * } * } * } * }] * } * } */ actions: { /** * Name of the API action */ [action: string]: { /** * Function handler for incoming requests. */ handler: (request: KuzzleRequest) => Promise; /** * Declare HTTP routes (optional). * Http routes will be auto-generated unless at least one is provided * or an empty array is provided. */ http?: HttpRoute[]; }; }; }; /** * Http route definition */ export type HttpRoute = { /** * HTTP verb. */ verb: "get" | "head" | "post" | "put" | "delete" | "patch" | "options"; /** * Route path. * A route starting with `/` will be prefixed by `/_` otherwise the route * will be prefixed by `/_//`. */ path: string; /** * Provide a (openAPI specification v3)[https://swagger.io/specification/#paths-object] for this route. * Kuzzle only expect the `paths` object of the specification. * When not defined, Kuzzle generate one from the action definition by itself. * * @example * { * description: "Simply say hello", * parameters: [{ * in: "path", * name: "name", * schema: { * type: "string" * }, * required: true, * }], * responses: { * 200: { * description: "Custom greeting", * content: { * "application/json": { * schema: { * type: "string", * } * } * } * } * } * } */ openapi?: JSONObject; };