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

@protocolnebula/ts-openapi-generator

v2.6.0

Published

Build API and models from Swagger/OpenAPI to use in any project type

Downloads

24

Readme

Logo

TypeScript OpenApi/Swagger Generator

Description :scroll:

This script is written in TypeScript, it can generate all Models and APIs (serivces) in any kind of language.

Currently it exports to Angular 2 but you can create your own templates (check templates folder).

You can modify those files to adapt to your code.

It's planned for a future to let configure this script instead need to modify the source code.

Installation :electric_plug:

npm i @protocolnebula/ts-openapi-generator

You need to copy "ApiBase" which is the "dependences" to work. This will be changed in a future and will not be required to be copied. You can just download ApiBase folder and save in your project in the same folder that you will "output" the generated data or copy with this command.

mkdir -p src/generatedApi
cp -r node_modules/ts-openapi-generator/ApiBase src/generatedApi/ApiBase

Usage :hammer_and_pick:

The script

Is recommended to add a script to your package.json or package manager that you use.

Change src/generatedApi by your desired folder to generate the code. If you not specify mock-output, -o + mock/ will be used.

Note that -t (template) and --mock-engine are optional, you can only use some of them.

transform-swagger \
  -f URI/TO/SWAGGER/JSON/OR/YAML \
  -o src/generatedApi/ \
  -t angular2 \
  --mock-engine json-server \
  --mock-output path/to/mock

Config file :gear:

The settings of the config file are the same than cli one (but in camelCase).

Create the config file (you choose the name and the location)

We will use as example transfrom-config.json example's one.

{
  "clean": true,
  "file": "./examples/openApiFiles/passportescaperoom.com.json",
  "outputFolder": "./examples/generated/angular2",
  "template": "angular2",
  "mock-generator": "json-server",
  "mock-output": "examples/generated/mocks/json-server",
  "saveFile": "./openApiFiles/passportescaperoom.com"
}

Launch the script

transform-swagger --config-file ./examples/transform-config.json

Main CLI commands :open_book:

Usage: transform-swagger [options]

Options:
  --version, -v        Show version number                             [boolean]
  --config-file        Configuration file to use (values from cli will overwrite
                       this file).
  --mock-generator     Specify the generator to use to generate mocks. If none
                       provider, mocks will not be generated
  --mock-output        The path where mock will be generated. If no specified,
                       output-folder/mock will be used
  --mock-partial       If true, only mock data will be generated instead of all
                       files                          [boolean] [default: false]
  --clean              No clean the output-folder, so old files will remain
                                                       [boolean] [default: true]
  -f, --file           Path OR URL to the swagger document to parse   [required]
  -o, --output-folder  Specify the output folder (generated folders will be
                       replaced)                             [default: "output"]
  -t, --template       Template (preset) name or path to a template
  -h, --help           Show help                                       [boolean]
  -s, --save-file                                    [default: "./openapi_temp"]

Examples:
  cli -f swagger.js -o api/ -t angular2  Convert a Swagger JSON file to
                                         compatible-angular API

Supported generators :toolbox:

API/Models

Plugin name refers to the template parameter (-t or --template in the cli)

| Language/Framework | Status | Plugin name (-t) | |--------------------|--------|------------------| | Angular 2 | Beta | angular2 |

Mock engine

Generator name refers to the mock-generator parameter (--mock-generator in the cli)

| Engine | Status | Generator name (--mock-generator) | |--------|--------|-----------------------------------| | json-server | Beta | json-server |

Development :memo:

Run with watch (internet file)

This will generate a file in output/temp.json|yaml

npm run start:dev -- -f URL_TO_SWAGGER.JSON/YAML

Run with watch (local file)

You can re-use the downloaded file or specify another folder

npm run start:dev -- -f output/temp.json -o src/generatedApi/ -t angular2