JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 9
  • Score
    100M100P100Q43575F
  • License ISC

Parse, Flatten, and Dereference JSON Schema $ref pointers

Package Exports

  • openapi-ref-flatten

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-flatten) 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 Flatten

Resolve $ref values in JSON Schema, OpenAPI (Swagger), and any other objects with $ref values inside them.

Project status: draft

TODOs

  • resolve $ref;
  • add README;
  • make the code more elegant;
  • add tests;
  • add yaml reader;
  • (???) support --dereference flag;

Installation

Supported in modern browsers and node.

npm i openapi-ref-flatten

Example

For the convenience of examples, I will use YAML-files (see TODOs). Currently only JSON is supported.

Input

For example, we have the following project structure:

super-project/
    |--- api/
          |--- example.yml
    |--- models/
          |--- pet-model.yml
          |--- kind-model.yml
  

The files contain the following:

# file: super-project/api/example.yml
pet1:
  $ref: ../models/pet-model.yml#/components/schemas/Pet
pet2:
  $ref: ../models/pet-model.yml#/components/schemas/Pet
kind1:
  $ref: ../models/kind-model.yml#/components/schemas/Kind
# file: super-project/models/pet-model.yml
components:
  schemas:
    Pet:
      type: object
      properties:
        name:
          type: string
        kind:
          $ref: ./kind-model.yml#/components/schemas/Kind
# file: super-project/models/kind-model.yml
components:
  schemas:
    Kind:
      type: object
      properties:
        name:
          type: string

Output

Run command:

node cli.js --input ./super-project/api/example.yml --output ./dist/result.yml
# file: dist/result.yml
pet1:
  $ref: #/components/schemas/Pet
pet2:
  $ref: #/components/schemas/Pet
kind1:
  $ref: #/components/schemas/Kind

components:
  schemas:
    Pet:
      type: object
      properties:
        name:
          type: string
        kind:
          $ref: #/components/schemas/Kind
    Kind:
      type: object
      properties:
        name:
          type: string

Classic dereference

In a simple dereference, we will have the following output:

node cli.js --input ./super-project/api/example.yml --output ./dist/result.yml --derefence

The --derefence flag is not supported now.

pet1:
  type: object
  properties:
    name:
      type: string
    kind:
      type: object
      properties:
        name:
          type: string
pet2:
  type: object
  properties:
    name:
      type: string
    kind:
      type: object
      properties:
        name:
          type: string
kind1:
  type: object
  properties:
    name:
      type: string