arrest
Version:
OpenAPI v3 compliant REST framework for Node.js, with support for MongoDB and JSON-Schema
73 lines (72 loc) • 2.79 kB
TypeScript
import { AnyMongoAbility } from '@casl/ability';
import { OpenAPIV3 } from 'openapi-police';
/**
* Rebase a obj.$ref value, following the rules:
*
* <ext_schema_name>#/definitions/<schema_name> to #/components/schemas/<ext_schema_name>/definitions/<schema_name>
* #/definitions/<schema_def_name> to #/components/schemas/<schema_name>/definitions/<schema_def_name>
* <ext_schema_name>#/properties/<prop_name> to #/components/schemas/<ext_schema_name>/properties/<prop_name>
* #/properties/<prop_name> to #/components/schemas/<schema_name>/definitions/<prop_name>
* <ext_schema_name># to #/components/schemas/<ext_schema_name>
* <ext_schema_name> to #/components/schemas/<ext_schema_name>
*
* @export
* @param {string} schemaName
* @param {*} obj
* @returns {*} the modified obj with rebased $ref property
*/
export declare function refsRebaser(schemaName: string, obj: any): any;
/**
* Recursively move all OpenAPI spec schemas' definitions properties and rebase $refs accordingly
*
* @export
* @param {*} fullSpec - the full OpenAPI spec object eventually containing definitions properties
* @returns {*} - the transformed spec with rebased definitions
*/
export declare function rebaseOASDefinitions(fullSpec: any): OpenAPIV3.Document;
/**
* Remove $schema property from a JSON Schema
*
* @param obj - the JSON Schema object
* @returns Object - the JSON Schema without $schema definition property
*/
export declare function removeSchemaDeclaration(obj: any): any;
/**
* Types for counting occurrences of schemas and parameters in openapi specs
*/
export interface OccurrencesTable {
schemas: Occurrence | {};
parameters: Occurrence | {};
responses: Occurrence | {};
}
export interface Occurrence {
count: number;
referencedBy: string[];
}
/**
* Remove all schema definitions from spec.components.schemas, from spec.components.parameters,
* and from spec.components.responses when there isn't any $ref pointing to them.
* The function modifies the document passed in input.
*
* @param spec - the OpenAPIV3.Document to "clean"
* @returns the clean OpenAPIV3.Document
*/
export declare function removeUnusedSchemas(spec: OpenAPIV3.Document): OpenAPIV3.Document;
export declare function checkAbility(ability: AnyMongoAbility, resource: string, action: string, data?: any, filterFields?: boolean, filterData?: boolean): any;
export interface CSVOptions {
fields: string[] | {
[key: string]: string;
};
unwind?: string;
forceUnwind?: boolean;
separator?: string;
decimal?: string;
quotes?: boolean;
escape?: string;
eol?: string;
dateFormat?: string;
timezone?: string;
header: boolean;
filename?: string;
}
export declare function toCSV(data: any[], options: CSVOptions): string;