Comprehensive tooling for working with OpenAPI definitions
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Advanced operation discovery by URL, method, operationId, and comprehensive operation analysis through the Operation, Callback, and Webhook classes.
Get an Operation instance for a specific path and HTTP method.
/**
* Get Operation instance for a path and method
* @param path - OpenAPI path (e.g., "/users/{id}")
* @param method - HTTP method
* @param opts - Options including webhook flag
* @returns Operation or Webhook instance
*/
operation(path: string, method: HttpMethods, opts?: { isWebhook?: boolean }): Operation;Usage Examples:
// Get a standard operation
const getUserOp = oas.operation("/users/{id}", "get");
console.log(getUserOp.getSummary());
console.log(getUserOp.getParameters());
// Get a webhook (OpenAPI 3.1)
const webhookOp = oas.operation("newUser", "post", { isWebhook: true });
if (webhookOp.isWebhook()) {
console.log("This is a webhook operation");
}
// Handle missing operations gracefully
const missingOp = oas.operation("/nonexistent", "get");
console.log(missingOp.getSummary()); // undefined for missing operationsFind all possible operation matches for a complete URL without specifying method.
/**
* Find all operation matches for a complete URL
* @param url - Complete URL to match against
* @returns Object mapping paths to arrays of path matches
*/
findOperationMatches(url: string): PathMatches;Usage Examples:
const matches = oas.findOperationMatches("https://api.example.com/users/123");
if (matches) {
matches.forEach(match => {
console.log(`Matched path: ${match.url.path}`);
console.log(`Path parameters:`, match.url.slugs);
console.log(`Original path: ${match.url.nonNormalizedPath}`);
});
}Find a specific operation by complete URL and HTTP method.
/**
* Find operation by complete URL and method
* @param url - Complete URL including origin and path
* @param method - HTTP method to match
* @returns Path match object or undefined if not found
*/
findOperation(url: string, method: HttpMethods): PathMatch | undefined;Usage Examples:
const match = oas.findOperation("https://api.example.com/users/123", "get");
if (match) {
console.log(`Found operation: ${match.url.method} ${match.url.path}`);
console.log(`Parameters extracted:`, match.url.slugs); // { ":id": "123" }
console.log(`Server origin: ${match.url.origin}`);
}Get an Operation instance directly from a complete URL and method.
/**
* Get Operation instance from complete URL and method
* @param url - Complete URL to resolve
* @param method - HTTP method
* @returns Operation instance or undefined if not found
*/
getOperation(url: string, method: HttpMethods): Operation | undefined;Usage Examples:
const operation = oas.getOperation("https://api.example.com/users/123", "get");
if (operation) {
console.log(`Operation ID: ${operation.getOperationId()}`);
console.log(`Summary: ${operation.getSummary()}`);
console.log(`Required parameters: ${operation.hasRequiredParameters()}`);
// Use all Operation methods
const params = operation.getParameters();
const security = operation.getSecurity();
const responses = operation.getResponseStatusCodes();
}Find an operation anywhere in the API definition by its operationId.
/**
* Find operation by operationId
* @param id - operationId to search for (exact match, case-sensitive)
* @returns Operation or Webhook instance, or undefined if not found
*/
getOperationById(id: string): Operation | Webhook | undefined;Usage Examples:
// Find by explicit operationId
const getUserOp = oas.getOperationById("getUser");
if (getUserOp) {
console.log(`Found: ${getUserOp.method.toUpperCase()} ${getUserOp.path}`);
}
// Find webhook by operationId
const webhookOp = oas.getOperationById("userCreated");
if (webhookOp?.isWebhook()) {
console.log("Found webhook operation");
}
// Handle generated operationIds
const generatedOp = oas.getOperationById("getUsersUserId"); // Generated from GET /users/{id}Find an operation by URL without specifying the HTTP method.
/**
* Find operation by URL without specifying method
* @param url - Complete URL to match
* @returns Path match for the best matching operation
*/
findOperationWithoutMethod(url: string): PathMatch | undefined;Usage Examples:
const match = oas.findOperationWithoutMethod("https://api.example.com/users/123");
if (match) {
// Will find the operation with the fewest path parameters
console.log(`Best match: ${match.url.path}`);
console.log(`Available methods:`, Object.keys(match.operation));
}The Operation class provides comprehensive analysis capabilities:
interface Operation {
/** Get operation summary */
getSummary(): string;
/** Get operation description */
getDescription(): string;
/** Get operation tags with metadata */
getTags(): TagObject[];
/** Check if operation is deprecated */
isDeprecated(): boolean;
/** Check if this is a webhook operation */
isWebhook(): boolean;
}interface Operation {
/** Check if operation has an operationId */
hasOperationId(): boolean;
/** Get operationId or generate one from path and method */
getOperationId(opts?: OperationIDGeneratorOptions): string;
}Usage Examples:
const operation = oas.operation("/users/{id}", "get");
// Basic info
console.log(`Summary: ${operation.getSummary()}`);
console.log(`Description: ${operation.getDescription()}`);
console.log(`Deprecated: ${operation.isDeprecated()}`);
// Tags
const tags = operation.getTags();
tags.forEach(tag => {
console.log(`Tag: ${tag.name}, Description: ${tag.description || 'N/A'}`);
});
// Operation ID
if (operation.hasOperationId()) {
console.log(`Operation ID: ${operation.getOperationId()}`);
} else {
console.log(`Generated ID: ${operation.getOperationId()}`);
}interface Operation {
/** Get primary content type for this operation */
getContentType(): string;
/** Check if operation uses form URL encoding */
isFormUrlEncoded(): boolean;
/** Check if operation uses multipart encoding */
isMultipart(): boolean;
/** Check if operation uses JSON */
isJson(): boolean;
/** Check if operation uses XML */
isXml(): boolean;
}Usage Examples:
const operation = oas.operation("/users", "post");
console.log(`Content type: ${operation.getContentType()}`);
// Type-specific handling
if (operation.isJson()) {
console.log("Handle JSON payload");
} else if (operation.isFormUrlEncoded()) {
console.log("Handle form data");
} else if (operation.isMultipart()) {
console.log("Handle file uploads");
}For OpenAPI 3.1 webhook operations:
class Webhook extends Operation {
/** OpenAPI 3.1 document reference */
declare api: OAS31Document;
/** Get summary with webhook-specific fallbacks */
getSummary(): string;
/** Get description with webhook-specific fallbacks */
getDescription(): string;
}For callback operations within regular operations:
class Callback extends Operation {
/** Callback identifier */
identifier: string;
/** Parent path item schema */
parentSchema: PathItemObject;
/** Get callback identifier */
getIdentifier(): string;
/** Get summary with callback-specific fallbacks */
getSummary(): string;
/** Get description with callback-specific fallbacks */
getDescription(): string;
/** Get parameters with parent parameter inheritance */
getParameters(): ParameterObject[];
}The library handles complex URL patterns and server variables:
// Supports server variables in discovery
// Server: "https://{region}.api.example.com/{version}"
const operation = oas.getOperation("https://us.api.example.com/v1/users/123", "get");
// Handles path parameters
// Path: "/users/{userId}/orders/{orderId}"
const match = oas.findOperation("https://api.example.com/users/123/orders/456", "get");
console.log(match?.url.slugs); // { ":userId": "123", ":orderId": "456" }// Automatically matches against all defined servers
const servers = [
"https://api.example.com",
"https://staging.example.com",
"https://{region}.example.com"
];
// Will match any of the above servers
const operation = oas.getOperation("https://staging.example.com/users/123", "get");Install with Tessl CLI
npx tessl i tessl/npm-oasdocs