import type { ResourcefulModel } from "./mixin"; import type { ApplicationService, HttpContext } from "../types"; import type { ResourcefulModelColumnMetaSchema, ResourcefulModelComputedAccessorMetaSchema, ResourcefulModelRelationshipMetaSchema, ResourcefulModelMetaSchema, ResourcefulModelOpenApiSchema, ResourcefulModelOpenApiRelatedSchema } from "./types"; export interface GenerateModelSchemaOptions { includeRelations?: boolean; relationsDeepLevel?: number | null; ctx?: HttpContext; app?: ApplicationService; } export interface NormalizedGenerateModelSchemaOptions extends GenerateModelSchemaOptions { includeRelations: boolean; relationsDeepLevel: number | null; ctx?: HttpContext; app?: ApplicationService; } /** * Service class for generating OpenAPI schema objects from resourceful model metadata. * * This service encapsulates all OpenAPI-related functionality that was previously * embedded in the resourceful mixin, providing better code organization and * easier testing. It handles the extraction of data type information from * resourceful data types and generates proper OpenAPI schema objects with * vendor extensions for field capabilities (filterable, sortable, aggregatable). * * @example * ```typescript * const service = new OpenApiSchemaService() * const schema = await service.generateModelSchema('read', metaSchema, model) * ``` */ export declare class OpenApiSchemaService { #private; /** * Generates a complete OpenAPI schema object for a resourceful model. * * This method creates a comprehensive OpenAPI v3 schema representation of the model * by processing the provided metadata schema. The metadata should already have * field-level access control permissions evaluated for the given request context. * The generated schema includes vendor extensions that provide metadata about field * capabilities for API consumers: * - `x-resourceful-filterable`: Array of field names that can be used in filter operations * - `x-resourceful-sortable`: Array of field names that can be used in sort operations * - `x-resourceful-aggregatable`: Array of field names that can be used in aggregation operations * * @param operation - The operation type ('read' or 'write') to determine which fields to include * @param resourcefulModelMetaSchema - The resourceful model metadata with ACL filtering applied * @param model - Optional model class for additional context * @returns Complete OpenAPI schema object with field capability metadata * * @example * ```typescript * const service = new OpenApiSchemaService() * const schema = service.generateModelSchema('read', metaSchema, UserModel) * // Returns OpenAPI schema with vendor extensions: * // { * // type: 'object', * // properties: { ... }, * // 'x-resourceful-filterable': ['name', 'email', 'user.name'], * // 'x-resourceful-sortable': ['name', 'createdAt'], * // 'x-resourceful-aggregatable': ['totalSales', 'orderCount'] * // } * ``` */ generateModelSchema(operation: "read" | "write" | undefined, resourcefulModelMetaSchema: ResourcefulModelMetaSchema, options: NormalizedGenerateModelSchemaOptions, model?: ResourcefulModel): Promise; /** * Generates OpenAPI schema for a column property. * * This method converts resourceful column metadata into an OpenAPI schema object, * properly extracting data type information and preserving all existing schema * properties such as validation constraints, nullability, and access modifiers. * * @param propertyKey - The name of the column property * @param propertyMeta - The resourceful metadata for the column * @returns OpenAPI schema object for the column * * @example * ```typescript * const service = new OpenApiSchemaService() * const schema = service.generateColumnSchema('name', columnMeta) * // Returns: { type: 'string', minLength: 1, maxLength: 100, ... } * ``` */ generateColumnSchema(model: ResourcefulModel, propertyKey: string, propertyMeta: ResourcefulModelColumnMetaSchema): ResourcefulModelOpenApiSchema; /** * Generates OpenAPI schema for a computed accessor property. * * This method converts resourceful computed accessor metadata into an OpenAPI * schema object, applying the same data type extraction improvements as column * schema generation while maintaining all existing functionality. * * @param propertyKey - The name of the computed accessor property * @param propertyMeta - The resourceful metadata for the computed accessor * @returns OpenAPI schema object for the computed accessor * * @example * ```typescript * const service = new OpenApiSchemaService() * const schema = service.generateComputedAccessorSchema('fullName', accessorMeta) * // Returns: { type: 'string', readOnly: true, ... } * ``` */ generateComputedAccessorSchema(propertyKey: string, propertyMeta: ResourcefulModelComputedAccessorMetaSchema): ResourcefulModelOpenApiSchema; /** * Generates OpenAPI schema for a relationship property. * * This method converts resourceful relationship metadata into an OpenAPI * reference object, preserving existing relationship reference generation * logic and ensuring proper handling of related model references. * * @param propertyKey - The name of the relationship property * @param propertyMeta - The resourceful metadata for the relationship * @returns OpenAPI reference object for the relationship, or undefined if not applicable * * @example * ```typescript * const service = new OpenApiSchemaService() * const schema = service.generateRelationshipSchema('user', relationshipMeta) * // Returns: { $ref: '#/components/schemas/User' } * ``` */ generateRelationshipSchema(_propertyKey: string, propertyMeta: ResourcefulModelRelationshipMetaSchema, operation: 'read' | 'write', options: NormalizedGenerateModelSchemaOptions): Promise; /** * Extracts default value from property metadata using Joi description. * * This protected method provides access to the default value extraction logic * that was previously part of the mixin. It examines the Joi validator * description to find default values specified in the schema. * * @param propertyMeta - The resourceful metadata containing the validator * @returns The default value if found, undefined otherwise * * @example * ```typescript * const service = new OpenApiSchemaService() * const defaultValue = service.getDefaultValueFromPropertyMeta(propertyMeta) * ``` */ protected getDefaultValueFromPropertyMeta(propertyMeta: ResourcefulModelColumnMetaSchema | ResourcefulModelComputedAccessorMetaSchema): unknown | undefined; }