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 🙏

© 2024 – Pkg Stats / Ryan Hefner

openapi-refactorer

v0.1.0

Published

Break monolithic OpenAPI documents into several files (and put them back together).

Downloads

81

Readme

OpenAPI Refactorer

Break monolithic OpenAPI (f.k.a. Swagger) documents into several files (and put them back together). The resulting entrypoint is a valid OpenAPI document and still compatible with common tools.

Currently only the paths object is used for refactoring.

Installation

Install as a CLI

npm install -g openapi-refactorer

Install as a Node.js Module

npm install openapi-refactorer

Usage

Basic usage:

openapi-refactorer -i spider.yaml -o baby_spiders.yaml

NOTE: existing files will be overwritten

CLI Options

  -V, --version        output the version number
  -i, --input <file>   path of the input OpenAPI file.
  -o, --output [file]  path of the main output OpenAPI file. Required if --join option is not used. When omitted, output is sent to stdout. Missing directories within the file path will be created. Existing file are promptlessly overwritten.
  --join               whether to join/bundle the an OpenAPI file tree into one document.
  -h, --help           output usage information

Example

Input file

openapi: 3.0.0
info:
  # (...)
paths:
  /pets:
    get:
      summary: List all pets
      operationId: listPets
      # (...)
      responses:
        default:
          description: unexpected error
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
    post:
      summary: Create a pet
      operationId: createPets
      # (...)
  /pets/{petId}:
    get:
      summary: Info for a specific pet
      operationId: showPetById
      # (...)
      responses:
        default:
          description: unexpected error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  schemas:
    Error:
      required:
        - code
        - message
      properties:
        code:
          type: integer
          format: int32
        message:
          type: string

Command

openapi-refactorer -i petstore.yaml -o out/main.yaml

Output file structure

out/
 ├ main.yaml
 └ paths/
    ├ pets.yaml
    └ pets/
       └ {petId}.yaml

Output files

openapi: 3.0.0
info:
  # (...)
paths:
  /pets:
    $ref: 'paths/pets.yaml#'
  '/pets/{petId}':
    $ref: 'paths/pets/%7BpetId%7D.yaml#'
components:
  schemas:
    Error:
      required:
        - code
        - message
      properties:
        code:
          type: integer
          format: int32
        message:
          type: string
get:
  summary: List all pets
  operationId: listPets
  # (...)
  responses:
    default:
      description: unexpected error
      content:
        application/json:
          schema:
            $ref: "../main.yaml#/components/schemas/Error"
post:
  summary: Create a pet
  operationId: createPets
  # (...)
get:
  summary: Info for a specific pet
  operationId: showPetById
  # (...)
  responses:
    default:
      description: unexpected error
      content:
        application/json:
          schema:
            $ref: '../../main.yaml#/components/schemas/Error'

Known Issues

  • When joining/bundling: If a reference points to a definition object which itself references directly to another one, the reference is completely resolved. This produces an equivalent document as the original, but not exactly the same document.

Contributing

I'm open for ideas to make OpenAPI Refactorer better. Just send a pull request or open an issue (especially it's more involved).

License

MIT © 2019 Alexis Luengas