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

ts-from-swagger

v1.0.3

Published

Generate TypeScript interfaces and enums quickly and easily from Swagger definition JSON with our lightweight tool. Improve your development workflow by automatically generating type-safe code that's easy to maintain and understand. Say goodbye to manual

Downloads

5

Readme

:chopsticks: ts-from-swagger

  • :date:03-15-2023 :pushpin:Beta Version 1.0.2
  • :computer:NajibRachid :purple_circle:ANMOON :office: XHUB

Generate TypeScript interfaces and enums quickly and easily from Swagger definition JSON with our lightweight tool. Improve your development workflow by automatically generating type-safe code that's easy to maintain and understand. Say goodbye to manual coding and hello to streamlined development with our Swagger definition Typescript generator.

keywords: ts-from-swagger, swagger2ts, typescript generator, type-safe, type-safe rest Apis, type safety, TypeScript interfaces generator, Swagger to TypeScript converter, NPM package for generating TypeScript interfaces from Swagger, TypeScript definitions from Swagger, Swagger JSON to TypeScript, TypeScript code from Swagger schema, TypeScript typings from Swagger definition, Swagger interface to TypeScript conversion, TypeScript enum generator from Swagger JSON, TypeScript code generation from Swagger definition., Convert Swagger JSON to TypeScript code, tsgen.


Features

  • [x] Lightweight, & No dependencies.
  • [x] Simple & Easy to use.
  • [x] Fetch directly from Swagger Schema URL.
  • [x] Support interfaces and enums.
  • [x] Support required fields.
  • [x] Respects naming conventions.
  • [ ] Authorization for Swagger.
  • [ ] Supports both OpenAPI versions 2 & 3.
  • [ ] Supports both JSON & YML.

Install

#npm
npm i ts-from-swagger --save-dev

#yarn
yarn add ts-from-swagger --dev

Usage

Specify your swagger JSON url and followed by output directory(default is: ./src/definitions)

npx ts-from-swagger https://petstore.swagger.io/v2/swagger.json ./path/to/output/dir

Or add a script to your package.json file:

  "scripts": {
    "ts-from-swagger": "npx ts-from-swagger https://petstore.swagger.io/v2/swagger.json ./path/to/output/dir"
  }

Then run the script with npm run:

npm run ts-from-swagger

Demo

Write types safe code from your frontend to your backend API, backend agnostic as long as you use Swagger.

import axios from "axios";
import { PetStatus } from "./definitions/enums/PetStatus.enum";
import { Category } from "./definitions/interfaces/Category.interface";
import { Pet } from "./definitions/interfaces/Pet.interface";
import { Tag } from "./definitions/interfaces/Tag.interface";

const cats: Category = {
  id: 1,
  name: "Cats",
};

const friendly: Tag = {
  id: 1,
  name: "friendly",
};

const mellow: Tag = {
  id: 2,
  name: "mellow",
};

const newPet: Pet = {
  id: 123,
  name: "Mischievous",
  category: cats,
  // photoUrls: ["https://picsum.photos/200"], // not required
  tags: [friendly, mellow],
  status: PetStatus.AVAILABLE,
};

axios
  .post("https://petstore.swagger.io/v2/pet", newPet)
  .then((response) => {
    console.log(response.data);
  })
  .catch((error) => {
    console.error(error);
  });

Releases

  - Initial Version 1.0.0 : 11/03/2023
    - Project Setup.
    - Theory & prove of concept.
  - Alpha Version 1.0.1 : 13/03/2023
    - CLI configuration.
    - Generate Enums.
    - Fix Wrong type for arrays.
    - Fix OutputPath make recursive.
  - Beta Version 1.0.2 : 15/03/2023
    - Fix Imports.
    - Make Subfolders.
    - Respect naming conventions.
    - Refactor Code.
  - Beta Version 1.0.3 : 17/03/2023
    - Add simple CLI logs.
    - Fix run npx: node v14.21.1 / npm v6.14.17
  - [Agenda] Beta Version 1.0.x : xx/03/2023
    - Add Authorization.
    - Add support for Swagger version 3.
    - Add support for YML.
    - Fix issue: npx command on later node/npm versions.

Contributing

Contributions are welcome! If you find a bug or have a feature request, please open an issue on the GitHub repository.

Tests included:

   npm test

License

This project is licensed under the MIT License. See the LICENSE file for more information. Feel free to use it in your own projects, or contribute to its development on GitHub.