Skip to main content

Overview

The runtime API provides utilities for working with OpenAPI schemas, translations, and common documentation patterns.

Import

import { modelName, resolveRef, handleCJKWhitespaces } from 'doom'

Functions

modelName

Extracts and formats a model name from a schema reference.
export const modelName = (ref: string) => string
ref
string
required
OpenAPI schema reference (e.g., #/components/schemas/User or api.v1.User)
return
string
Capitalized model name extracted from the reference
Example:
import { modelName } from 'doom'

const name1 = modelName('#/components/schemas/user')
// Returns: 'User'

const name2 = modelName('api.v1.Pet')
// Returns: 'Pet'

resolveRef

Resolves an OpenAPI schema reference to its definition.
export const resolveRef = <T extends object = OpenAPIV3_1.SchemaObject>(
  openapi: OpenAPIV3_1.Document,
  ref: string,
) => T
openapi
OpenAPIV3_1.Document
required
OpenAPI document object containing the schemas
ref
string
required
Schema reference to resolve (supports shorthand without #/components/schemas/)
return
T
The resolved schema object of type T (defaults to OpenAPIV3_1.SchemaObject)
Example:
import { resolveRef } from 'doom'
import type { OpenAPIV3_1 } from 'openapi-types'

const openapi: OpenAPIV3_1.Document = {
  openapi: '3.1.0',
  info: { title: 'API', version: '1.0.0' },
  paths: {},
  components: {
    schemas: {
      User: {
        type: 'object',
        properties: {
          id: { type: 'string' },
          name: { type: 'string' }
        }
      }
    }
  }
}

// Resolve with full reference
const schema1 = resolveRef(openapi, '#/components/schemas/User')

// Resolve with shorthand
const schema2 = resolveRef(openapi, 'User')

// Both return the same schema object

handleCJKWhitespaces

Handles whitespace around Chinese, Japanese, and Korean (CJK) characters for proper text formatting.
export const handleCJKWhitespaces = (text?: string) => string
text
string
Text that may contain CJK characters
return
string
Text with properly formatted whitespace around CJK characters
Example:
import { handleCJKWhitespaces } from 'doom'

const text1 = handleCJKWhitespaces('Hello')
// Returns: ' Hello '

const text2 = handleCJKWhitespaces('你好')
// Returns: '你好'

const text3 = handleCJKWhitespaces('Hello世界')
// Returns: ' Hello世界'

Constants

COMMON_REFS

Mapping of common Kubernetes API references to their documentation URLs.
export const COMMON_REFS: Record<string, string>
Default References:
{
  'v1alpha1.ListMeta': 'https://kubernetes.io/docs/reference/kubernetes-api/common-definitions/list-meta/',
  'v1.ObjectMeta': 'https://kubernetes.io/docs/reference/kubernetes-api/common-definitions/object-meta/',
  // ... additional custom references from config
}
Usage:
import { COMMON_REFS } from 'doom'

const metaUrl = COMMON_REFS['v1.ObjectMeta']
// Returns: 'https://kubernetes.io/docs/reference/kubernetes-api/common-definitions/object-meta/'

omitRoutePathRefs

Filters out references that match a specific route path.
export const omitRoutePathRefs = (
  routePath: string
) => Record<string, string>
routePath
string
required
Route path to exclude from references
return
Record<string, string>
Filtered reference mapping excluding the specified route
Example:
import { omitRoutePathRefs } from 'doom'

const refs = omitRoutePathRefs('/api/object-meta')
// Returns COMMON_REFS without any references pointing to /api/object-meta

CJK_PATTERN

Regular expression pattern for matching CJK (Chinese, Japanese, Korean) characters.
export const CJK_PATTERN = /\p{sc=Han}/u
Usage:
import { CJK_PATTERN } from 'doom'

if (CJK_PATTERN.test('你好')) {
  console.log('Contains CJK characters')
}

Translation System

The runtime includes a comprehensive translation system with support for English, Chinese, and Russian.

Available Translations

export const TRANSLATIONS = {
  en: Translation,
  zh: Translation,
  ru: Translation
}
Common Translation Keys:
  • collapse_all - “Collapse All” text
  • expand_all - “Expand All” text
  • download_pdf - “Download PDF” text
  • toc - “TOC” (Table of Contents)
  • ai_assistant - “AI Assistant” text
  • login / logout - Authentication labels
  • thinking - AI thinking indicator
See the Hooks API for how to use translations in your components.

See Also

Build docs developers (and LLMs) love