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 🙏

© 2025 – Pkg Stats / Ryan Hefner

openapi-alchemist

v1.0.1

Published

Transform OpenAPI 3 to Swagger 2 with alchemical precision

Readme

OpenAPI Alchemist 🧪

CI npm version License: MIT

⚠️ Disclaimer: This is a fork of LucyBot-Inc/api-spec-converter, converted to TypeScript and focused on OpenAPI 3 to Swagger 2 conversion. For the original full-featured converter supporting multiple formats, please visit the original repository.

Transform OpenAPI 3 to Swagger 2 with alchemical precision

A TypeScript-converted minimal and focused API specification transformer that converts OpenAPI 3 to Swagger 2 with surgical accuracy.

Features

This package provides two main functionalities:

  1. OpenAPI 3 → Swagger 2 transformation
  2. OpenAPI 3 JSON ↔ YAML format conversion (semantic preservation, format-only conversion)

This version has been converted to TypeScript for Node.js v22+ with modern Promise-based APIs and improved type safety.

Installation

npm install openapi-alchemist

Usage

OpenAPI 3 to Swagger 2 Conversion

const openapiAlchemist = require('openapi-alchemist');

// Transform OpenAPI 3 specification to Swagger 2
openapiAlchemist.convert(
  {
    syntax: 'yaml',
    order: 'openapi',
    from: 'openapi_3',
    to: 'swagger_2',
    source: './path/to/your/openapi3.yaml', // or object
  },
  function (err, converted) {
    if (err) {
      console.error('Error converting:', err);
      return;
    }
    
    // Output as YAML
    const yamlString = converted.stringify({syntax: 'yaml'});
    console.log(yamlString);
    
    // Output as JSON
    const jsonString = converted.stringify({syntax: 'json'});
    console.log(jsonString);
  }
);

OpenAPI 3 JSON to YAML Conversion

const openapiAlchemist = require('openapi-alchemist');

// Transform OpenAPI 3 JSON to YAML (format conversion only)
openapiAlchemist.convert(
  {
    syntax: 'yaml',
    order: 'openapi',
    from: 'openapi_3',
    to: 'openapi_3', // Same format, different syntax
    source: './path/to/your/openapi3.json',
  },
  function (err, converted) {
    if (err) {
      console.error('Error converting:', err);
      return;
    }
    
    // Output as YAML
    const yamlString = converted.stringify({syntax: 'yaml'});
    console.log(yamlString);
  }
);

Using with Objects

const openapiAlchemist = require('openapi-alchemist');

const openApiSpec = {
  openapi: '3.0.0',
  info: {
    title: 'My API',
    version: '1.0.0'
  },
  paths: {
    '/users': {
      get: {
        responses: {
          '200': {
            description: 'Success',
            content: {
              'application/json': {
                schema: {
                  type: 'object',
                  properties: {
                    users: {
                      type: 'array',
                      items: {
                        type: 'string'
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
};

openapiAlchemist.convert(
  {
    from: 'openapi_3',
    to: 'swagger_2',
    source: openApiSpec, // Direct object
  },
  function (err, converted) {
    if (err) {
      console.error('Error:', err);
      return;
    }
    
    console.log('Converted successfully!');
    console.log('Swagger version:', converted.spec.swagger);
  }
);

API Reference

convert(options, callback)

Transforms API specifications between supported formats.

Parameters

  • options (Object):

    • from (String): Source format ('openapi_3')
    • to (String): Target format ('swagger_2' or 'openapi_3')
    • source (String|Object): Source specification (file path or object)
    • syntax (String, optional): Output syntax ('json' or 'yaml', default: 'json')
    • order (String, optional): Output ordering ('openapi', 'alpha', or 'false', default: 'openapi')
  • callback (Function): Callback function with signature (err, result)

Return Value

The callback receives a result object with:

  • spec: The converted specification object
  • stringify(options): Method to convert the spec to string format

Supported Node.js Versions

  • Node.js >= 22.0.0 (TypeScript version with modern Promise APIs)

What's Not Supported

This minimal version does not support:

  • RAML specifications
  • API Blueprint specifications
  • WADL specifications
  • Google Discovery documents
  • I/O Docs specifications
  • Swagger 1.x specifications
  • URL-based sources (only file paths and objects)
  • Swagger 2 → OpenAPI 3 conversion

Development

This package is built with TypeScript and compiled to CommonJS for Node.js compatibility. The source code is in the src/ directory and compiled output is in dist/.

Building

npm run build

Testing

npm test

Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Publishing

See .github/PUBLISHING.md for detailed publishing instructions.

License

MIT