arrest
Version:
OpenAPI v3 compliant REST framework for Node.js, with support for MongoDB and JSON-Schema
39 lines (38 loc) • 1.3 kB
TypeScript
import { Router, RouterOptions } from 'express';
import { OpenAPIV3 } from 'openapi-police';
import { API } from './api.js';
import { Operation } from './operation.js';
import { APIRequestHandler, Method } from './types.js';
export interface OperationFactory {
new (resource: Resource, path: string, method: Method): Operation;
}
export interface Routes {
[path: string]: {
[method in Method]?: OperationFactory | APIRequestHandler;
};
}
export interface ResourceDefinition {
name?: string;
description?: string;
externalDocs?: OpenAPIV3.ExternalDocumentationObject;
namePlural?: string;
id?: string;
title?: string;
summaryFields?: string[];
routes?: Routes;
[ext: string]: any;
}
export declare class Resource {
info: ResourceDefinition;
api: API;
protected operations: Operation[];
constructor(info?: ResourceDefinition, routes?: Routes);
protected initInfo(): void;
get basePath(): string;
get scopeDescription(): string;
addOperation(op: Operation): this;
addOperation(path: string, method: Method, handler: OperationFactory | APIRequestHandler, id?: string): this;
attach(api: API): void;
router(base: Router, options?: RouterOptions): Promise<Router>;
static capitalize(s: any): any;
}