evals
scenario-1
scenario-10
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
Build a TypeScript utility that generates and validates OpenAPI metadata and documentation structures.
Create a module that constructs well-typed OpenAPI metadata sections including API information, contact details, license information, server configurations, and external documentation references. The module should provide strongly-typed builders and validators for these metadata components.
Create a function buildApiInfo that constructs complete API information with the following parameters:
The function should return a properly typed info object with all metadata fields.
Create a function buildServerConfig that constructs server configurations with:
The function should return a properly typed server object.
Create a function buildExternalDocs that constructs external documentation references with:
The function should return a properly typed external documentation object.
Create a function buildTag that constructs operation tags with:
The function should return a properly typed tag object.
import type { OpenAPIV3 } from 'openapi-types';
/**
* Builds an OpenAPI info object with required metadata and optional contact/license.
*/
export function buildApiInfo(
title: string,
description: string,
version: string,
contact?: { name?: string; url?: string; email?: string },
license?: { name: string; url?: string }
): OpenAPIV3.InfoObject;
/**
* Builds a server configuration object.
*/
export function buildServerConfig(
url: string,
description?: string
): OpenAPIV3.ServerObject;
/**
* Builds an external documentation object.
*/
export function buildExternalDocs(
url: string,
description?: string
): OpenAPIV3.ExternalDocumentationObject;
/**
* Builds a tag object for categorizing operations.
*/
export function buildTag(
name: string,
description?: string,
externalDocs?: OpenAPIV3.ExternalDocumentationObject
): OpenAPIV3.TagObject;Provides TypeScript type definitions for OpenAPI specifications.