or run

npx @tessl/cli init
Log in

Version

Files

tile.json

task.mdevals/scenario-5/

OpenAPI Document Analyzer

Build a utility that analyzes OpenAPI documents regardless of their specification version (2.0, 3.0, or 3.1). The analyzer should extract and count key elements from any valid OpenAPI document.

Requirements

Implement a function analyzeDocument that accepts an OpenAPI document of any version and returns an analysis object containing:

  • version: The OpenAPI version string (e.g., "2.0", "3.0.0", "3.1.0")
  • operationCount: Total number of operations across all paths
  • parameterCount: Total number of parameters used across all operations

The function should work with OpenAPI 2.0 (Swagger), OpenAPI 3.0, and OpenAPI 3.1 documents without requiring version-specific handling.

Test Cases

  • Given an OpenAPI 3.0 document with 2 paths (GET /users and POST /users), where GET has 1 query parameter and POST has 1 body parameter, the function returns {version: "3.0.0", operationCount: 2, parameterCount: 2} @test

  • Given an OpenAPI 2.0 document with 1 path (GET /items) that has 2 query parameters, the function returns {version: "2.0", operationCount: 1, parameterCount: 2} @test

  • Given an OpenAPI 3.1 document with 3 paths each containing 1 operation with no parameters, the function returns {version: "3.1.0", operationCount: 3, parameterCount: 0} @test

Implementation

@generates

API

export interface AnalysisResult {
  version: string;
  operationCount: number;
  parameterCount: number;
}

export function analyzeDocument(document: unknown): AnalysisResult;

Dependencies { .dependencies }

openapi-types { .dependency }

Provides TypeScript type definitions for OpenAPI specifications.

@satisfied-by