@kakilangit/openapi-viewer
v0.1.0
Published
WebAssembly bindings for OpenAPI Viewer tool
Maintainers
Readme
@kakilangit/openapi-viewer
WebAssembly bindings for OpenAPI Viewer tool.
Overview
This package provides OpenAPI 3.0.x specification parsing and viewing functionality compiled to WebAssembly from Rust. It supports:
- Parsing - Parse OpenAPI specifications from JSON or YAML
- Extraction - Extract API info, endpoints, and server URLs
- Conversion - Convert between JSON and YAML formats
Installation
npm install @kakilangit/openapi-viewerUsage
import init, {
parse_openapi,
yaml_to_json,
json_to_yaml,
OpenApiInfo
} from '@kakilangit/openapi-viewer';
// Initialize the WASM module
await init();
// Parse an OpenAPI specification
const spec = `
openapi: "3.0.0"
info:
title: Pet Store API
version: 1.0.0
paths:
/pets:
get:
summary: List pets
operationId: listPets
responses:
"200":
description: Success
`;
const info = parse_openapi(spec);
console.log(info.title); // "Pet Store API"
console.log(info.api_version); // "1.0.0"
console.log(info.paths); // Array of endpoint info
// Convert YAML to JSON
const json = yaml_to_json(spec);
console.log(json); // Formatted JSON string
// Convert JSON to YAML
const yaml = json_to_yaml('{"key": "value"}');
console.log(yaml); // YAML stringAPI
Functions
parse_openapi(input)
Parses an OpenAPI 3.0.x specification from JSON or YAML string.
input(string): The OpenAPI specification in JSON or YAML format
Returns OpenApiInfo:
version: OpenAPI version (e.g., "3.0.0")title: API titledescription: API description (if present)api_version: API version stringpaths: Array of endpoint informationpath: Path pattern (e.g., "/users/{id}")method: HTTP method (GET, POST, etc.)summary: Operation summary (if present)description: Operation description (if present)operation_id: Operation ID (if present)
servers: Array of server URLs
yaml_to_json(input)
Converts a YAML string to formatted JSON.
input(string): YAML content
Returns: string - Formatted JSON string
json_to_yaml(input)
Converts a JSON string to YAML.
input(string): JSON content
Returns: string - YAML string
Features
- Fast OpenAPI parsing via WebAssembly
- Support for OpenAPI 3.0.x specifications
- Automatic format detection (JSON/YAML)
- Bidirectional JSON/YAML conversion
- Structured endpoint extraction
License
MIT
