import type { Method } from '../../types/Method.js'; import type { OasPathItem } from '../pathItem/PathItem.js'; import type { OasParameter } from '../parameter/Parameter.js'; import type { OasRequestBody } from '../requestBody/RequestBody.js'; import type { OasResponse } from '../response/Response.js'; import type { OasParameterLocation } from '../parameter/parameter-types.js'; import type { OasSchema } from '../schema/Schema.js'; import type { OasRef } from '../ref/Ref.js'; import { OasObject } from '../object/Object.js'; import type { ToJsonSchemaOptions } from '../schema/Schema.js'; import type { OpenAPIV3 } from 'openapi-types'; import type { OasSecurityRequirement } from '../securityRequirement/SecurityRequirement.js'; /** * Fields for configuring an OpenAPI operation object. * * Contains all the properties needed to define a complete OpenAPI operation, * including path information, parameters, request/response specifications, * security requirements, and metadata. */ export type OperationFields = { /** The API path for this operation */ path: string; /** The HTTP method for this operation */ method: Method; /** The parent path item containing this operation */ pathItem: OasPathItem | undefined; /** Unique identifier for the operation */ operationId?: string | undefined; /** Brief summary of the operation */ summary?: string | undefined; /** Tags for organizing operations in documentation */ tags?: string[] | undefined; /** Detailed description of the operation */ description?: string | undefined; /** Parameters accepted by this operation */ parameters?: (OasParameter | OasRef<'parameter'>)[] | undefined; /** Request body specification for this operation */ requestBody?: OasRequestBody | OasRef<'requestBody'> | undefined; /** Response specifications mapped by status code */ responses: Record>; /** Security requirements for this operation */ security?: OasSecurityRequirement[] | undefined; /** Whether this operation is deprecated */ deprecated?: boolean | undefined; /** OpenAPI specification extensions */ extensionFields?: Record; }; /** * Arguments passed to request body mapping functions. */ export type ToRequestBodyMapArgs = { schema: OasSchema | OasRef<'schema'>; requestBody: OasRequestBody; }; /** * Represents an OpenAPI Operation Object in the SKMTC OAS processing system. * * The `OasOperation` class encapsulates a single API operation (path + method combination) * with all its associated metadata, parameters, request/response specifications, and * security requirements. It provides utilities for extracting common operation data * like success responses and request bodies. * * ## Key Features * * - **Path and Method**: Unique combination identifying the operation * - **Metadata Access**: Operation ID, summary, description, tags, and deprecation status * - **Parameter Handling**: Query, path, header, and cookie parameters * - **Request/Response Specs**: Type-safe access to request body and response definitions * - **Security Context**: Operation-specific security requirements * - **Success Response Utils**: Helper methods to identify and extract successful responses * * @example Basic operation properties * ```typescript * import { OasOperation } from '@skmtc/core'; * * // Typically created during document parsing * const getUserOp = new OasOperation({ * path: '/users/{id}', * method: 'get', * operationId: 'getUserById', * summary: 'Get user by ID', * description: 'Retrieves a single user by their unique identifier', * parameters: [ * // Path parameter for user ID * { name: 'id', in: 'path', required: true, schema: { type: 'string' } } * ], * responses: { * '200': { description: 'User found', content: { ... } }, * '404': { description: 'User not found' } * } * }); * * console.log(getUserOp.path); // '/users/{id}' * console.log(getUserOp.method); // 'get' * console.log(getUserOp.operationId); // 'getUserById' * ``` * * @example Working with success responses * ```typescript * // Find the primary success response * const successResponse = operation.toSuccessResponse(); * if (successResponse) { * const resolved = successResponse.resolve(); * console.log('Success response:', resolved.description); * } * * // Get the HTTP status code for success * const successCode = operation.toSuccessResponseCode(); * console.log('Success status:', successCode); // '200', '201', 'default', etc. * ``` * * @example Extracting request body data * ```typescript * // Extract request body with custom transformation * const requestData = operation.toRequestBody(({ schema, requestBody }) => { * return { * schema: schema, * contentType: 'application/json', * required: requestBody.required ?? false, * description: requestBody.description * }; * }); * * if (requestData) { * console.log('Request schema:', requestData.schema); * console.log('Required:', requestData.required); * } * ``` * * @example Parameter processing * ```typescript * // Process operation parameters by location * const pathParams = operation.parameters?.filter(param => { * const resolved = param.resolve(); * return resolved.in === 'path'; * }); * * const queryParams = operation.parameters?.filter(param => { * const resolved = param.resolve(); * return resolved.in === 'query'; * }); * * console.log('Path parameters:', pathParams?.length); * console.log('Query parameters:', queryParams?.length); * ``` * * @example Security requirements * ```typescript * if (operation.security) { * console.log('Operation has specific security requirements'); * for (const requirement of operation.security) { * // Process security schemes for this operation * Object.keys(requirement.schemes).forEach(scheme => { * console.log(`Security scheme: ${scheme}`); * }); * } * } else { * console.log('Operation uses default document security'); * } * ``` */ export declare class OasOperation { /** Type identifier for OAS operation objects */ oasType: 'operation'; /** The API path for this operation */ path: string; /** The HTTP method for this operation */ method: Method; /** The parent path item containing this operation */ pathItem: OasPathItem | undefined; /** Unique identifier for the operation */ operationId: string | undefined; /** Brief summary of the operation */ summary: string | undefined; /** Tags for organizing operations in documentation */ tags: string[] | undefined; /** Detailed description of the operation */ description: string | undefined; /** Parameters accepted by this operation */ parameters: (OasParameter | OasRef<'parameter'>)[] | undefined; /** Request body specification for this operation */ requestBody: OasRequestBody | OasRef<'requestBody'> | undefined; /** Response specifications mapped by status code */ responses: Record>; /** Security requirements for this operation */ security: OasSecurityRequirement[] | undefined; /** Whether this operation is deprecated */ deprecated: boolean | undefined; /** OpenAPI specification extensions */ extensionFields: Record | undefined; /** * Creates a new OasOperation instance from operation field data. * * @param fields - Operation field data from OpenAPI specification */ constructor(fields: OperationFields); /** * Returns the successful response definition for this operation. * * Looks for the lowest numbered 2xx response code and returns its response definition. * * @returns Success response object or undefined if none found */ toSuccessResponse(): OasResponse | OasRef<'response'> | undefined; /** * Returns the HTTP status code for the primary success response. * * Finds the lowest numbered 2xx status code in the responses. * * @returns Success status code as string or undefined if none found */ toSuccessResponseCode(): string | undefined; /** * Maps the request body schema to a custom value using the provided mapping function. * * @param map - Function to transform the request body schema and metadata * @param mediaType - Media type to extract schema from (default: 'application/json') * @returns Mapped value or undefined if no request body schema found */ toRequestBody(map: ({ schema, requestBody }: ToRequestBodyMapArgs) => V, mediaType?: string): V | undefined; /** * Resolve all parameters and optionally filter by location * * @param filter - only include parameters from specified locations * @returns */ toParams(filter?: OasParameterLocation[]): OasParameter[]; /** * Creates an OAS object representation of operation parameters. * * @param filter - Optional array of parameter locations to include * @returns OAS object with parameter properties */ toParametersObject(filter?: OasParameterLocation[]): OasObject; /** * Converts the operation to OpenAPI v3 JSON schema format. * * @param options - Conversion options for nested components * @returns OpenAPI v3 operation object */ toJsonSchema(options: ToJsonSchemaOptions): OpenAPIV3.OperationObject; /** * Serializes the operation to a plain JavaScript object. * * @returns Plain object representation of the operation */ toJSON(): object; } //# sourceMappingURL=Operation.d.ts.map