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

aak-swagger-typescript-api

v1.0.5

Published

Generate typescript/javascript api from swagger schema

Downloads

9

Readme

aak-swagger-typescript-api

This is a fork of the package swagger-typescript-api 🔱

🔥 This package is designed to work together with the package aak-nuxt-auth-fetch


NPM badge

Generate api via swagger scheme.
Supports OA 3.0, 2.0, JSON, yaml
Generated api module use fetch from npm package aak-nuxt-auth-fetch

Thanks to the developers of the project https://www.npmjs.com/package/swagger-typescript-api

📦 Get Started

  1. Install aak-swagger-typescript-api as project dependency:
npm i -D aak-swagger-typescript-api
  1. Put down your swagger.json to the root folder of the project
  2. Run the command in your terminal
npx swagger-typescript-api -p ./swagger.json -o ./utils/api --sort-routes --sort-types --extract-request-params
  1. In the folder utils/api/, there will be a file Api.ts for use in your project 🤝

📄 Usage

Usage: sta [options]
Usage: swagger-typescript-api [options]
Usage: swagger-typescript-api generate-templates [options]

Options:
  -v, --version                 output the current version
  -p, --path <string>           path/url to swagger scheme
  -o, --output <string>         output path of typescript api file (default: "./")
  -n, --name <string>           name of output typescript api file (default: "Api.ts")
  -t, --templates <string>      path to folder containing templates
  -d, --default-as-success      use "default" response status code as success response too.
                                some swagger schemas use "default" response status code as success response type by default. (default: false)
  -r, --responses               generate additional information about request responses
                                also add typings for bad responses (default: false)
  --union-enums                 generate all "enum" types as union types (T1 | T2 | TN) (default: false)
  --add-readonly                generate readonly properties (default: false)
  --route-types                 generate type definitions for API routes (default: false)
  --enum-names-as-values        use values in 'x-enumNames' as enum values (not only as keys) (default: false)
  --extract-request-params      extract request params to data contract (Also combine path params and query params into one object) (default: false)
  --extract-request-body        extract request body type to data contract (default: false)
  --extract-response-body       extract response body type to data contract (default: false)
  --extract-response-error      extract response error type to data contract (default: false)
  --silent                      Output only errors to console (default: false)
  --default-response <type>     default type for empty response schema (default: "void")
  --api-class-name <string>     name of the api class (default: "Api")
  --patch                       fix up small errors in the swagger source definition (default: false)
  --sort-types                  sort fields and types (default: false)
  --sort-routes                 sort routes in alphabetical order (default: false)
  --extract-enums               extract all enums from inline interface\type content to typescript 

The optimal command to usenpx:

npx swagger-typescript-api -p ./swagger.json -o ./utils/types -n apiTypes.ts --sort-routes --sort-types --extract-request-params

Also you can use npx:

npx swagger-typescript-api -p ./swagger.json -o ./src -n myApi.ts

🚀 How it looks

📝 License

Licensed under the MIT License.