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

@eriklenaerts/openapi-docgen

v0.4.100

Published

Generate an Open API document to kick start your REST API design or development.

Downloads

39

Readme

Open API Document Generator

Generate new Open API documents based on your own API REST guidelines.

Prerequisites

You have nodejs installed on your computer, if not download it here: https://nodejs.org/en/download/

Basic usage

Open a command line terminal

> npm install -g @eriklenaerts/openapi-docgen
> mkdir your-app
> cd your-app
> openapi-docgen

First time setup

For your convenience there's a command line switch to create local configuration file. (Basically a copy of the .env.example).

> openapi-docgen --setup

Read the configuration chapter below for the various options.

Features

  • Generate OAS (aka swagger) documents in JSON or YAML
  • Provide resource names and it will deal with pluralisaton (English only)
  • Select the operations GET, POST, PUT, ... you like for each resource
  • Classify resources in specified tags
  • Generates placeholder schema's for every resource
  • Interactive prompt or provide command line arguments
  • Generate OAS documents based on your own specifications, there's one included for the Digipolis API System 7.0.
  • Create your own templates (based on Handlebars)
  • Work with templates from the file system or online.

Examples

// Show the commandline help
> openapi-docgen -h     

//Generate an API called 'Appointment' the rest will be prompted
> openapi-docgen Appointment       

//Generate an API called 'Appointment' with two resources 'location' and 'service'
> openapi-docgen Appointment -r 'location, service'     

//Generate an API called 'Appointment' with two resources 'location' and 'tenant', the latter will be classified under the `System` tag
> openapi-docgen Appointment -r 'location, tenant::system'  

//Generate an API called 'Appointment' with two resources 'location' and a sub resource 'address'
> openapi-docgen Appointment -r 'location, location/address'    

//Generate an API called 'Appointment' with a resource 'address' as a sub resource, a minimal parent 'location' resource will be added with a list and read operation
> openapi-docgen Appointment -r 'location/address'    

//Generate an API called 'Appointment' with two resources 'location' and 'service'. Only the list (GET collection) will be generated for the location. check out the operations modifier below
> openapi-docgen Appointment -r 'location[2], service'     

Calculate the Operations modifier

You can determine per resource what operations need to be generated. Simply provide a number - that is the sum of the modifiers in the table below, to modify the generator's behaviour. This modifier can be added in square brackets with each resource in the command line.

Tip: you can change the default ops modifier yourself

To calculcate this number, use the following table: | Operation | Description | modifier | |----------- |-------------------------------------- |---------- | | GET | list all resources of the collection | 1 | | POST | add a resource to the collection | 2 | | POST (async) | add a resource asynchronously | 4 | | GET | retrieve a resource (by id) | 8 | | HEAD | check if resource exist | 16 | | PUT | replace a resource | 32 | | PATCH | update a resource | 64 | | DELETE | delete a resource | 128 |

Some examples:

// generate only an operation to list (GET) all locations resources
> openapi-docgen Appointment -r 'location[1]'

// generate operation to list (GET) all locations resources and delete a resource
> openapi-docgen Appointment -r 'location[129]'

// generate operation to list (GET) all locations resources, retrieve one by id (GET) and check if one exists (HEAD)
> openapi-docgen Appointment -r 'location[25]'

Note: be sure to specify the modifier on the resource itself, not on the parent indicator

// this will not work
> openapi-docgen Appointment -r 'location, location[2]/address[8]'

// this will not work either
> openapi-docgen Appointment -r 'location[2]/address[8]'

// this is what you need 
> openapi-docgen Appointment -r 'location[2], location/address[8]'

// or this works as well. Basically, the generator will use [9] as a modifier for location that is, both the list and retrieve GET operations.
// (it does not make much sense to have child resources with no way to access the parent resources)
> openapi-docgen Appointment -r 'location/address[8]'

Configuration

Use the .env configuration file to set the following environment variables.

Tip: use the --setup command line switch to create a sample configuration file, see also first time setup.

| Config variable | Description | Default value | |------------------------- |------------------------------------------------------------------------------------------------------------------------------------------------- |------------------------ | | TEMPLATE_PROVIDER | Specify the source of the templates. ('FileSystem' or 'Online') | FileSystem | | TEMPLATES_BASE_LOCATION | Set the base location for the given Template Provider. | | | DEFAULT_TEMPLATE | Set the default template, though the --template cli argument takes precedence. | basic.hbs | | DEFAULT_OUTPUT_LOCATION | Set the default output location in case nothing was provided using the --output cli argument. | current working folder | | UNIQUE_OUTPUT_FILENAME | If true, each output file will have a unique part in the filename so it always writes a new file. if false, the file is overwritten each time. | false | | DEFAULT_OPS_MODIFIER | When no ops modifier was provided for a resource, use this default. Calculate the modifier here | 235 |

Contribute

  • Find me at https://github.com/eriklenaerts/openapi-generator
  • Fork away or sent Pull Requests :v:

Note to myself: Development

To debug:

  • set Toggle Auto Attach to smart or always using Command Palette (⇧⌘P), restart Terminal, see also https://code.visualstudio.com/docs/nodejs/nodejs-debugging#_auto-attach
  • open the code in Visual Studio Code.
  • set breakpoints in the code
  • type node bin/generator in a terminal

Note to myself: Publish this package on npm

  • increase version number in the package.json file
  • ececute the npm publish command in a terminal
  • FYI: to check all versions of this package so far on npm, execute npm show @eriklenaerts/openapi-docgen versions --json