Compiles OMG to OpenAPI 3.1
npm install omg-compilerCompiles OMG (OpenAPI Markdown Grammar) AST to OpenAPI 3.1 specification.
``bash`
npm install omg-compiler
`typescript
import { loadApi } from 'omg-parser';
import { compileToOpenApi, serialize } from 'omg-compiler';
// Load API from directory
const api = loadApi('/path/to/api/api.omg.md');
// Compile to OpenAPI
const openapi = compileToOpenApi(api);
// Serialize to YAML or JSON
const yaml = serialize(openapi, 'yaml');
const json = serialize(openapi, 'json');
`
`typescript
import { detectFormat } from 'omg-compiler';
detectFormat('output.yaml'); // 'yaml'
detectFormat('output.json'); // 'json'
detectFormat('output.yml'); // 'yaml'
`
Compiles a parsed OMG API to an OpenAPI 3.1 document.
Features:
- Converts OMG types to OpenAPI schemas
- Extracts nested schemas to components/schemasx-*
- Generates meaningful schema names from context
- Handles circular references
- Passes through vendor extensions ( fields)
Serializes an OpenAPI document to YAML or JSON string.
Detects the output format from a file path extension.
The compiler generates fully compliant OpenAPI 3.1 specifications:
- openapi: 3.1.0null
- JSON Schema compatibility
- in type arrays for nullable$ref
- for shared schemascomponents/schemas
- Full support
- Security schemes
- Server definitions
- External documentation links
`yaml``
openapi: 3.1.0
info:
title: My API
version: 1.0.0
paths:
/users/{id}:
get:
operationId: get-user
parameters:
- name: id
in: path
required: true
schema:
type: string
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/User'
components:
schemas:
User:
type: object
properties:
id:
type: string
name:
type: string
MIT