npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@demokit-ai/schema

v0.2.0

Published

OpenAPI schema parsing with relationship detection for DemoKit

Readme

@demokit-ai/schema

Tests Coverage

OpenAPI schema parsing with relationship detection for DemoKit.

Installation

npm install @demokit-ai/schema

Features

  • OpenAPI Parsing - Parse OpenAPI 3.x specifications
  • Relationship Detection - Automatically detect model relationships
  • Schema Normalization - Convert to DemoKit's internal schema format
  • Type Inference - Infer property types and constraints
  • Validation - Validate schemas against OpenAPI spec
  • Full TypeScript support

Usage

Parse OpenAPI Spec

import { parseOpenAPI } from '@demokit-ai/schema'

const schema = await parseOpenAPI('./openapi.yaml')

console.log(schema.models)
// {
//   User: {
//     properties: {
//       id: { type: 'string', format: 'uuid' },
//       name: { type: 'string' },
//       email: { type: 'string', format: 'email' },
//     },
//     required: ['id', 'name', 'email'],
//   },
//   Order: { ... },
// }

console.log(schema.relationships)
// [
//   { from: { model: 'Order', field: 'userId' }, to: { model: 'User', field: 'id' }, type: 'many-to-one' },
// ]

Parse from URL

import { parseOpenAPI } from '@demokit-ai/schema'

const schema = await parseOpenAPI('https://api.example.com/openapi.json')

Parse from Object

import { parseOpenAPIObject } from '@demokit-ai/schema'

const spec = {
  openapi: '3.0.0',
  paths: { ... },
  components: {
    schemas: {
      User: { ... },
    },
  },
}

const schema = parseOpenAPIObject(spec)

Detect Relationships

import { detectRelationships } from '@demokit-ai/schema'

const models = {
  User: {
    properties: {
      id: { type: 'string' },
    },
  },
  Order: {
    properties: {
      id: { type: 'string' },
      userId: { type: 'string' },
    },
  },
}

const relationships = detectRelationships(models)
// [
//   {
//     from: { model: 'Order', field: 'userId' },
//     to: { model: 'User', field: 'id' },
//     type: 'many-to-one',
//   },
// ]

Define Schema Manually

import { defineSchema } from '@demokit-ai/schema'

const schema = defineSchema({
  models: {
    User: {
      properties: {
        id: { type: 'string', format: 'uuid' },
        name: { type: 'string', minLength: 1 },
        email: { type: 'string', format: 'email' },
        role: { type: 'string', enum: ['admin', 'user', 'guest'] },
        createdAt: { type: 'string', format: 'date-time' },
      },
      required: ['id', 'name', 'email'],
    },
    Order: {
      properties: {
        id: { type: 'string', format: 'uuid' },
        userId: {
          type: 'string',
          relationshipTo: { model: 'User', field: 'id' },
        },
        total: { type: 'number', minimum: 0 },
        status: { type: 'string', enum: ['pending', 'completed', 'cancelled'] },
      },
      required: ['id', 'userId', 'total', 'status'],
    },
  },
})

Validate Schema

import { validateSchema } from '@demokit-ai/schema'

const result = validateSchema(schema)

if (!result.valid) {
  console.error('Schema errors:', result.errors)
}

API Reference

parseOpenAPI(pathOrUrl)

Parse an OpenAPI spec from a file path or URL.

Returns: Promise<DemokitSchema>

parseOpenAPIObject(spec)

Parse an OpenAPI spec from a JavaScript object.

Returns: DemokitSchema

detectRelationships(models)

Detect relationships between models based on field naming conventions.

Returns: Relationship[]

defineSchema(options)

Define a schema manually with full type inference.

Options:

  • models - Model definitions
  • relationships - Explicit relationship definitions (optional)

Returns: DemokitSchema

validateSchema(schema)

Validate a schema for correctness.

Returns:

  • valid - Whether schema is valid
  • errors - Array of validation errors
  • warnings - Array of warnings

Types

DemokitSchema

interface DemokitSchema {
  version: string
  models: Record<string, DataModel>
  relationships: Relationship[]
}

DataModel

interface DataModel {
  properties: Record<string, PropertyDef>
  required?: string[]
}

PropertyDef

interface PropertyDef {
  type: 'string' | 'number' | 'integer' | 'boolean' | 'array' | 'object'
  name?: string
  format?: string
  enum?: unknown[]
  minimum?: number
  maximum?: number
  minLength?: number
  maxLength?: number
  pattern?: string
  nullable?: boolean
  default?: unknown
  example?: unknown
  relationshipTo?: { model: string; field: string }
  items?: PropertyDef | DataModel
}

Relationship

interface Relationship {
  from: { model: string; field: string }
  to: { model: string; field: string }
  type: 'one-to-one' | 'one-to-many' | 'many-to-one' | 'many-to-many'
}

License

MIT