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

@nldoc/openapi-utils

v1.3.112

Published

Utilities for building OpenAPI specifications.

Downloads

122

Readme

NLdoc OpenAPI Utilities

pipeline status coverage report Latest Release NPM Version

A TypeScript utility library for building OpenAPI 3.1.0 specifications programmatically. This library provides a fluent, type-safe API for creating and managing OpenAPI schemas, properties, and references.

Overview

This library provides a comprehensive set of utilities for working with OpenAPI specifications including:

  • Type-safe property builders for OpenAPI schemas
  • Resource and collection property management
  • Schema component references and examples
  • JSON type definitions and utilities
  • Fluent API for building complex schemas

The utilities provide a consistent, type-safe way to construct OpenAPI specifications, enabling better API documentation, validation, and integration with OpenAPI-based tools.

Getting Started

Prerequisites

  • Node.js >= 22.0.0 < 23.0.0
  • npm >= 10.0.0 < 12.0.0

Installation

Install the package via npm:

npm install @nldoc/openapi-utils

Or using yarn:

yarn add @nldoc/openapi-utils

Basic Usage

import {
  Property,
  Resource,
  CollectionProperty,
  ComponentSchemaReference
} from '@nldoc/openapi-utils';

// Create a simple property
const nameProperty = new Property('string')
  .setTitle('Name')
  .setDescription('The name of the resource')
  .setMinLength(1)
  .setMaxLength(100);

// Create a resource with properties
const userResource = new Resource('User', 'object')
  .addProperty('id', new Property('string').setFormat('uuid'), true)
  .addProperty('name', nameProperty, true)
  .addProperty('email', new Property('string').setFormat('email'), true)
  .addExample({
    id: '123e4567-e89b-12d3-a456-426614174000',
    name: 'John Doe',
    email: '[email protected]'
  });

// Create a collection property
const usersCollection = new CollectionProperty(['User'])
  .setMinItems(0)
  .setDescription('A collection of users');

// Create a schema reference
const userRef = ComponentSchemaReference('User');

Development

Local Setup

  1. Clone the repository:

    git clone https://gitlab.com/logius/nldoc/lib/typescript/openapi-utils.git
    cd openapi-utils
  2. Install dependencies:

    npm install
  3. Build the project:

    npm run build

Available Scripts

  • npm run test - Run the test suite with Vitest and coverage
  • npm run build - Build the TypeScript files for distribution
  • npm run lint - Lint the codebase using ESLint
  • npm run format - Format code using Prettier
  • npm run format:check - Check code formatting
  • npm run fix - Auto-fix linting and formatting issues
  • npm run release - Create a semantic release

API Components

The library provides several key classes and utilities:

Core Classes

  • Property: Base class for creating OpenAPI schema properties
  • Resource: Extended property class for creating complex object schemas
  • CollectionProperty: Specialized property for array/collection types

Reference Utilities

  • ComponentSchemaReference: Create references to schema components
  • ComponentExampleReference: Create references to example components
  • ReferenceKey: Generate reference keys for components

Type Definitions

  • Json: TypeScript types for JSON values
  • StrictOpenAPIObject: Strict typing for OpenAPI objects
  • OmitIndexSignature: Utility type for omitting index signatures

Helper Functions

  • assertHasTitle: Assertion function for schema titles
  • isArrayOfOneEmptyArray: Check for empty array patterns

API Documentation

Property Class

The Property class provides a fluent API for building OpenAPI schema properties:

const property = new Property('string')
  .setTitle('Example Property')
  .setDescription('A description of the property')
  .setFormat('email')
  .setMinLength(5)
  .setMaxLength(100)
  .addExample('[email protected]')
  .setDefault('[email protected]');

Resource Class

The Resource class extends Property for creating object schemas:

const resource = new Resource('Product', 'object')
  .addProperty('id', idProperty, true) // required
  .addProperty('name', nameProperty, true)
  .addProperty('price', priceProperty, false) // optional
  .setProperties({ description: descProperty }, ['description']);

CollectionProperty Class

The CollectionProperty class handles array types with discriminators:

const collection = new CollectionProperty(['Product', 'Service'], 'type')
  .setMinItems(1)
  .addExample([
    { type: 'Product', id: '1', name: 'Widget' },
    { type: 'Service', id: '2', name: 'Support' }
  ]);

Testing

Run the test suite:

npm test

Contributing

We welcome contributions! Please ensure:

  1. All tests pass (npm test)
  2. Code is properly formatted (npm run format:check)
  3. Linting rules are followed (npm run lint)
  4. Test coverage is maintained

License

This project is licensed under the European Union Public License 1.2 - see LICENSE for details.

Acknowledgements