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

@superhero/http-server-using-oas

v4.8.2

Published

Integrates the HTTP server and OAS (OpenAPI Specification) @superhero components

Readme

HTTP Server using OAS

A routing bridge module that connects OpenAPI Specification (OAS) definitions with the @superhero/http-server, enabling automatic route creation, request validation, and response conformance. Designed for the Superhero Tool-Chain, this module allows for fully declarative HTTP APIs, grounded in specification adapted architecture.

Features

  • Specification driven routing: Dynamically registers routes from OpenAPI JSON specifications.
  • Schema validation: Automatically validates parameters, request bodies, and responses.
  • Component reference resolution: Supports $ref linking across parameters, request bodies, responses, and schemas.
  • Dynamic middleware injection: Adds validation middleware as required by the specifications.
  • Declarative dispatcher mapping: Connects OAS operations directly to logic handlers.
  • Robust error handling: Emits structured errors for invalid config or unsupported content types.

Installation

npm install @superhero/http-server-using-oas

Usage

You must supply an OpenAPI 3.x Specification as a JSON object in the oas configuration field.

import Core from '@superhero/core'

const core = new Core()

await core.add('@superhero/oas')
await core.add('@superhero/http-server')
await core.add('@superhero/http-server-using-oas')

core.locate.config.assign({
  oas: {
    paths: {
      "/foo": {
        "get":  { "responses": { "200": {} }},
        "post": { "responses": { "200": {} }}
      }
    }
  }
})

await core.bootstrap()

const oasBridge = core.locate('@superhero/http-server-using-oas')

oasBridge.setOasRoute('/foo', 'get',  'dispatcher/for/get')
oasBridge.setOasRoute('/foo', 'post', 'dispatcher/for/post')

Automatic Middleware Injection

Depending on the OAS operation, the following are automatically injected:

  • @superhero/http-server-using-oas/dispatcher/upstream/parameters
  • @superhero/http-server-using-oas/dispatcher/upstream/request-bodies
  • @superhero/http-server-using-oas/dispatcher/downstream/responses

Supported requestBody.content-type:

  • Only application/json is currently supported

More Complete OAS Example

This module resolves $ref-based components in OpenAPI JSON specifications:

{
  "paths": {
    "/example": {
      "post": {
        "requestBody": {
          "$ref": "#/components/requestBodies/ExampleRequestBody"
        },
        "responses": {
          "200": {
            "$ref": "#/components/responses/SuccessResult"
          }
        }
      }
    }
  },
  "components": {
    "requestBodies": {
      "ExampleRequestBody": {
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Foo"
            }
          }
        }
      }
    },
    "responses": {
      "SuccessResult": {
        "description": "Successful result",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Result"
            }
          }
        }
      }
    },
    "schemas": {
      "Foo": {
        "type": "object",
        "properties": {
          "foo": { "type": "string" }
        }
      },
      "Result": {
        "type": "object",
        "properties": {
          "result": { "type": "string" }
        }
      }
    }
  }
}

Configuration Summary

| Method/Property | Description | |--------------------------------------------------------|-----------------------------------------------------------------------| | setOasRoute(path, method, dispatcher, [middlewares]) | Registers a route from the OpenAPI JSON spec | | requestBodyContentTypeRouteMap(type) | Maps supported content-types to upstream middleware | | Middleware auto-injection | Based on the parameters, requestBody, and responses in the spec | | Error signaling | Emits detailed errors on spec validation or misuse |

Tests

Run the test suite:

npm test

Test Coverage

────────────────────────────────── ⋅⋆ Suite ⋆⋅ ─────────────────────────────────

@superhero/http-server-using-oas 
├─ Can set a simple specification ✔ 107.543ms
├─ Can add middleware for requestBody content ✔ 16.743ms
├─ Can add middleware for parameters ✔ 19.857ms
├─ Specification with reference to components 
│  ├─ GET method using default parameter query parameter ✔ 37.413ms
│  ├─ GET method not using required parameter ✔ 9.606ms
│  ├─ GET method using bar parameter ✔ 5.497ms
│  ├─ GET method using header parameter ✔ 4.792ms
│  ├─ POST method using request body ✔ 11.069ms
│  └─ ✔ 91.067ms
└─ ✔ 238.450ms

─────────────────────────────────── Coverage ───────────────────────────────────

Files                                            Coverage   Functions   Branches
dispatcher/downstream/responses.js                    69%         75%        80%
dispatcher/options.js                                 10%         33%       100%
dispatcher/upstream/parameters.js                    100%        100%       100%
dispatcher/upstream/request-bodies.js                 75%         75%       100%
index.js                                              82%        100%        58%
index.test.js                                        100%        100%       100%
Total                                                 68%         88%        83%

License

MIT

Contributing

Issues and pull requests are welcome.