@vercube/schema
Version:
Schema (swagger) module for Vercube framework
57 lines (56 loc) • 1.77 kB
text/typescript
import { RouteConfig } from "@asteasolutions/zod-to-openapi";
import { z } from "zod";
import { App, BasePlugin } from "@vercube/core";
//#region src/Decorators/Schema.d.ts
interface SchemaDecoratorOptions extends Omit<RouteConfig, 'method' | 'path'> {}
/**
* A decorator function for registering OpenAPI schema metadata for a route.
*
* This function creates an instance of the SchemaDecorator class and registers
* the schema with the specified options.
*
* @param {SchemaDecoratorOptions} params - The schema options for the route.
* @returns {Function} - The decorator function.
*/
declare function Schema(params: SchemaDecoratorOptions): Function;
//#endregion
//#region src/Plugins/SchemaPlugin.d.ts
/**
* Schema Plugin for Vercube framework
*
* Provides OpenAPI/Swagger schema generation and validation capabilities:
* - Automatic OpenAPI schema generation from Zod schemas
* - Route-level schema validation via @Schema decorator
* - Runtime schema access via /_schema endpoint
* - Seamless integration with request validation (@Body, @Query, etc)
*
* @example
* ```ts
* import { createApp } from '@vercube/core';
* import { SchemaPlugin } from '@vercube/schema';
*
* const app = createApp({
* setup: async (app) => {
* app.addPlugin(SchemaPlugin);
* }
* });
* ```
*
* @see {@link https://vercube.dev} for full documentation
*/
declare class SchemaPlugin<T = unknown> extends BasePlugin<T> {
/**
* The name of the plugin.
* @override
*/
name: string;
/**
* Method to use the plugin with the given app.
* @param {App} app - The application instance.
* @returns {void | Promise<void>}
* @override
*/
use(app: App, options: T): void | Promise<void>;
}
//#endregion
export { Schema, SchemaPlugin, z };