UNPKG

@scalar/oas-utils

Version:

Open API spec and Yaml handling utilities

52 lines 2.39 kB
import type { HttpMethod } from '@scalar/helpers/http/http-methods'; import type { Request as HarRequest } from 'har-format'; import type { OperationObject } from '@scalar/workspace-store/schemas/v3.1/strict/path-operations'; import { type Dereference } from '@scalar/workspace-store/schemas/v3.1/type-guard'; import type { ServerObject } from '@scalar/workspace-store/schemas/v3.1/strict/server'; import type { SecuritySchemeObject } from '@scalar/workspace-store/schemas/v3.1/strict/security-scheme'; export type OperationToHarProps = { /** OpenAPI Operation object */ operation: Dereference<OperationObject>; /** HTTP method of the operation */ method: HttpMethod; /** Path of the operation */ path: string; /** * requestBody.content[contentType].example to use for the request, it should be pre-selected and discriminated */ example?: unknown; /** * Content type of the request * * @defaults to the first content type in the operation.requestBody.content */ contentType?: string; /** OpenAPI Server object */ server?: ServerObject | undefined; /** OpenAPI SecurityScheme objects which are applicable to the operation */ securitySchemes?: SecuritySchemeObject[]; }; /** * Converts an OpenAPI Operation to a HarRequest format for generating HTTP request snippets. * * This function transforms OpenAPI 3.1 operation objects into HAR (HTTP Archive) format requests, * which can be used to generate code snippets for various programming languages and HTTP clients. * * The conversion handles: * - Server URL processing and path parameter substitution * - Query parameter formatting based on OpenAPI parameter styles * - Request body processing with content type handling * - Security scheme integration (API keys, etc.) * * The resulting HarRequest object follows the HAR specification and includes: * - HTTP method and URL * - Headers and query parameters * - Request body (if present) * - Cookie information * - Size calculations for headers and body * * @see https://w3c.github.io/web-performance/specs/HAR/Overview.html * @see https://spec.openapis.org/oas/v3.1.0#operation-object */ export declare const operationToHar: ({ operation, contentType, method, path, server, securitySchemes, example, }: OperationToHarProps) => HarRequest; //# sourceMappingURL=operation-to-har.d.ts.map