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

s2n

v0.1.2

Published

Transform Swagger API Json Schema to JavaScript interfaces

Downloads

5

Readme

s2n

The Swagger to Node provides a simple way to create TypeScript interfaces based on swagger documentation JSON.

You can use it to populate some BFF's SDK or just to make API calls simpler, by using it on your front-end project.

The problem

In large scale projects, it is very common the usage of various programming languages/frameworks to expose some service, and the most common way to do the communication of all, it's by expose some REST API with swagger documentation, (which is great!). But swagger just provides us UI or JSON schema validation. No IntelliSense at all. And that's where s2n becomes useful. It will read the Swagger JSON and create a TypeScript interface for you. In 2 seconds

How can be this possible?

Swagger provides us a very nice structured documentation of all of our routes and methods. s2n only parses it and generate TypeScript code based on it. It will use Axios to make the request, so it's nice to know how Axios works.

Limitations

If you're a Windows user, ensure that you're using POSIX directory navigation by using the CLI.

# this will cause some bugs with path
s2n [...args] --definitions-path do\\not\\do\\this

# this is how you should do it
s2n [...args] --defnitions-path do/this/instead

Usage

First, you'll need to install s2n globally on your machine. You can do it with the following command:

npm i -g s2n

After that, you must be able to use the CLI with s2n

TIP: Try to type s2n --help on your terminal, to see all the available documented commands.

Example of usage:

s2n --name Petstore --json-url https://petstore.swagger.io/v2/swagger.json

Required arguments

You must pass two arguments to the CLI, otherwise, it will throw an error. They're:

  • --name: name of the service that will be parsed (will be rendered with this);
  • --json-url: the URL of Swagger documentation JSON. This must be over the HTTP protocol.

Available arguments

  • --name: name of the service that will be parsed (will be rendered with this);
  • --json-url: the URL of Swagger documentation JSON. This must be over the HTTP protocol.
  • --definitions-path -DP: path where all definitions will be rendered (relative to process.cwd());
  • --service-path -SP: path where the service will be rendered (relative to process.cwd()).

Credits

This package was entirely designed and developed by @danielbonifacio.

Thanks to Axios team to provide the HTTP library.

Thanks to pag! for giving me the opportunity to explore this architecture and apply it on a large project.

License

MIT