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

@devexperts/swagger-codegen-ts

v2.0.0-alpha.29

Published

TS generator for swagger spec

Downloads

29,846

Readme

Build Status

Typesafe OpenAPI generator for TypeScript

Features

  • Generates client code from OpenAPI 3.0, 2.0 (aka Swagger) and AsyncAPI specs
  • Pluggable HTTP clients: can use fetch, Axios or any other library
  • Flexible response types: works with Promises and reactive streams like RxJS
  • Runtime type checks: validates server responses against the spec
  • Written in pure TypeScript using fp-ts and io-ts libraries

Demo code

The examples below refer to the Pet Store OpenAPI 3.0 schema.

After running the codegen, interacting with a REST API may be as simple as this:

import { petController as createPetController } from "./src/generated/petstore.json/paths/PetController";
import { Pet } from "./src/generated/petstore.json/components/schemas/Pet";

// Creating a controller, see the "HTTP Clients" wiki page for more details
const petController = createPetController({ httpClient: fetchHttpClient });

// The returned object is guaranteed to be a valid `Pet`
const createdPet: Promise<Pet> = petController.addPet({
  body: {
    // The parameters are statically typed, IntelliSense works, too
    name: "Spotty",
    photoUrls: [],
  },
});

More usage scenarios are supported - check the usage page for more detail.

Installation

  1. Make sure the peer dependencies are installed, then install the codegen itself:

    yarn add typescript fp-ts io-ts io-ts-types
    yarn add -D @devexperts/swagger-codegen-ts
  2. Create a console script that would invoke the generate function, passing the options such as path to the schema file and the output directory. See the Generators page for the API reference, and examples/generate for sample scripts.

  3. In most cases, you might want to include the code generation step into the build and local launch scripts. Example:

    /* package.json */
    
      "scripts": {
    +   "generate:api": "ts-node scripts/generate-api.ts",
    -   "start": "react-scripts start",
    +   "start": "yarn generate:api && react-scripts start",
    -   "build": "react-scripts build"
    +   "build": "yarn generate:api && react-scripts build"
      }

Contributing

Please read the Contributors Guide for more information.