JSPM

openapi-ref-resolver

0.0.6
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 4
  • Score
    100M100P100Q31085F
  • License MIT

Package Exports

  • openapi-ref-resolver
  • openapi-ref-resolver/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (openapi-ref-resolver) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

openapi-ref-resolver

Simple resolver for bundling/dereferencing OpenAPI specifications (YAML and JSON).

Supported OpenAPI versions:

  • 3.0.0, 3.0.1, 3.0.2

How to use

npm install openapi-ref-resolver

Bundle:

import { bundleOpenApiSpec } from 'openapi-ref-resolver';

const bundled = bundleOpenApiSpec('./api.yaml');
console.log(JSON.stringify(bundled.document, null, 2));

Dereference:

import { dereferenceOpenApiSpec } from 'openapi-ref-resolver';

const dereferenced = dereferenceOpenApiSpec('./api.yaml');
console.log(JSON.stringify(dereferenced.document, null, 2));

Missing features

  • Support for OpenAPI v2
  • Resolve URI references (only file: scheme is supported)

But why another reference resolver?

I started this project while I was working on some OpenAPI-based custom code generator. At that time, I tried several libraries for bundling a multi-file YAML spec into a single-file JSON spec (a pretty common use case for code generation).

Long story short, I never managed to find a library that satisfies the following requirements, even for the simplest specs:

  • paths references inlined, all other references locally resolved into components/*.
  • generate readable local references, not #/paths/~1api~1v1~garbledstuff/post/requestBody/content/application~1json/schema/properties/oh/god/why
  • Javascript library
  • no preprocessing required with a manual tool
  • produce a valid spec file

This library certainly has quirks too, so please open issues. Also, the code is very simple and PRs are welcome!