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

swagger-extract-dto

v1.0.3

Published

extract DTO definitions from swagger json file

Downloads

4

Readme

swagger-extract-dto

The problem

Most complex frontend applications have a complex API connection. The API structure is not so simple in a typical case, so it would be great to have some formal description.

Fortunately, in many cases we have Swagger/OpenAPI description which is generated by some tools on the backend side. However, this Swagger/OpenAPI is just a JSON file which is not very usable without additional efforts.

Solution

This library helps to work on the frontend with Swagger/OpenAPI API description in next way

  • it takes the Swagger/OpenAPI JSON as input
  • it produces Typescript defintion for each API method
  • it produces ENDPOINT string/function - depends on parameters existance
  • it produces types definitions for each DTO which is used in the API
  • it produces enums definitions
  • it produces response DTO definitions
  • it produces body DTO definitions
  • it produces dereferenced JSON schema for each endpoint; it can be used for API response validation

Example

> npm i swagger-extract-dto
> npx swagger-extract-dto -j -f ./src/sample/petstore.json -o ./tmp/petstore
> tree ./tmp/petstore

./tmp/petstore
├── ApiResponse.ts
├── Category.ts
├── Order.ts
├── Pet.ts
├── Tag.ts
├── User.ts
├── info.json
├── petFindByStatus_get.ts
├── petFindByStatus_get_response.schema.json
├── petFindByTags_get.ts
├── petFindByTags_get_response.schema.json
├── petPetIdUploadImage_post.ts
├── petPetIdUploadImage_post_response.schema.json
├── petPetId_delete.ts
├── petPetId_get.ts
├── petPetId_get_response.schema.json
├── petPetId_post.ts
├── pet_post.ts
├── pet_put.ts
├── storeInventory_get.ts
├── storeInventory_get_response.schema.json
├── storeOrderOrderId_delete.ts
├── storeOrderOrderId_get.ts
├── storeOrderOrderId_get_response.schema.json
├── storeOrder_post.ts
├── storeOrder_post_response.schema.json
├── userCreateWithArray_post.ts
├── userCreateWithList_post.ts
├── userLogin_get.ts
├── userLogin_get_response.schema.json
├── userLogout_get.ts
├── userUsername_delete.ts
├── userUsername_get.ts
├── userUsername_get_response.schema.json
├── userUsername_put.ts
└── user_post.ts

0 directories, 36 files

Options

> npx ./dist/swagger-extract-dto.js

Usage: swagger-extract-dto.js [options]

Options:
      --version  Show version number                                   [boolean]
  -f, --file     use a Swagger API file                               [required]
  -o, --out      output folder                                        [required]
  -j, --json     generate response JSON schema                         [boolean]
  -h, --help     Show help                                             [boolean]

Examples:
  swagger-extract-dto.js -f foo.json -o     process foo.json and place
  ./api                                     definitions to ./api folder

copyright 2021

Missing required arguments: f, o