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

swagger-schema-utils

v1.0.0

Published

Utilities for normalising and resolving complex (multi-file) Swagger schemas

Readme

swagger-schema-utils

Utilities for normalising and resolving complex (multi-file) Swagger schemas.

Rationale

For complex APIs, a single Swagger file grows to an unmaintainable length over time. Worse still, authors are often forced to add a lot of duplicate configuration in order to create a working schema. This module allows decomposing your schemas into multiple source files and provides the necessary workarounds and tooling needed to integrate your schema with existing Swagger tooling.

Note that this module only works with the more user-friendly YAML schemas currently, though it would be simple enough to implement JSON ones in resolveExternalRefs.js.

Issues addressed

Bundling of external schema files

Since most Swagger libraries only deal with a single schema, the most important function this module performs is to resolve external references and inline them into the master schema. Other solutions are out there (eg. swagger-parser), but have quirks of their own when it comes to resolution order and module reuse.

Our resolver is dumb- it will ALWAYS load external schemas in at their mounted $ref location. For best results & smallest resulting schemas we recommend you load your externals in under #/definitions/ and refer to them by their definition path in all other locations.

Use of additionalProperties with sub-schemas

A known issue with JSON Schema Draft v4 is unnecessary verbosity when combining additionalProperties: false with allOf / anyOf etc in order to restrict the allowable input fields.

Our loading algorithm detects this for all models loaded under #/definitions/, and will create empty attribute definitions for all fields in sub-schemas up to the toplevel one. This workaround indicates to the JSON schema parser that all attributes defined in child schemas should be allowed when other additional properites are not.

Usage

Loading schemas

Simply pass your schema file path to loadSchema and you'll get back a promise for a normalised, flattened version. In ES7, simply:

import { loadSchema } from 'swagger-schema-utils';

async function getMyAppSchema() {
	return await loadSchema('./path/to/schema.yaml');
}

In an ES6 or ES5 environment the function will return a promise that you can .then() and .catch() with as usual.

Using the CLI

You may wish to export single-file schemas in order to integrate more easily with other systems or external users of your API. This module provides the swagger-schema-utils CLI command for performing these functions.

Flattening schemas

swagger-schema-utils -s {root_input_schema.yaml} -e {dest_file.yaml}

Exporting model schemas from #definitions

Simply add the -f flag, indicating the ID of the definition you wish to export.

swagger-schema-utils -s {root_input_schema.yaml} -f {definitionID} -e {dest_file.yaml}

License

Made with :heart: at Everledger.io and released under an MIT license.