Skip to main content
Glama
kadykov

OpenAPI Schema Explorer

formatters.ts1.45 kB
import { dump as yamlDump } from 'js-yaml'; /** * Supported output formats */ export type OutputFormat = 'json' | 'yaml' | 'json-minified'; /** * Interface for formatters that handle different output formats */ export interface IFormatter { format(data: unknown): string; getMimeType(): string; } /** * JSON formatter with pretty printing */ export class JsonFormatter implements IFormatter { format(data: unknown): string { return JSON.stringify(data, null, 2); } getMimeType(): string { return 'application/json'; } } /** * Formats data as minified JSON. */ export class MinifiedJsonFormatter implements IFormatter { format(data: unknown): string { return JSON.stringify(data); } getMimeType(): string { return 'application/json'; } } /** * YAML formatter using js-yaml library */ export class YamlFormatter implements IFormatter { format(data: unknown): string { return yamlDump(data, { indent: 2, lineWidth: -1, // Don't wrap long lines noRefs: true, // Don't use references }); } getMimeType(): string { return 'text/yaml'; } } /** * Creates a formatter instance based on format name */ export function createFormatter(format: OutputFormat): IFormatter { switch (format) { case 'json': return new JsonFormatter(); case 'yaml': return new YamlFormatter(); case 'json-minified': return new MinifiedJsonFormatter(); } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/kadykov/mcp-openapi-schema-explorer'

If you have feedback or need assistance with the MCP directory API, please join our Discord server