1.0.261 • Published 4 months ago

swagger-to-interfaces v1.0.261

Weekly downloads
32
License
ISC
Repository
gitlab
Last release
4 months ago

Swagger to Interfaces

Super lightweight typescript interface generator.

✨Generate Typescript interfaces, enums and api endpoints straight from the swagger

WHY ?!

Swagger codegen allows you to generate a whole heavyweight full-blown client. Most of us frontend developers do not use it. We want to use our regular flow and loose the hassle of duplicating the server's schema. swagger-to-interfaces is a lightweight library designed to auto generate only data which is useful.


⭐Installation

  npm install swagger-to-interfaces

⭐Usage


  swagger-to-interfaces --pathToFile=/path/to/json/swagger.json --destinationFolderName=./src/swagger2Ts

⭐Environment

Arguments: Include the following args on activation:

  • --destinationFolderName

  • --pathToFile OR --swaggerUrl

OR

.env file: create a .env file at the root directory of your project with the following variables:

⭐File generation


Three files will be created: 1. ♕ interfaces.ts interfaces.ts all model definitions in Typescript interfaces.

  1. endpoints.ts endpoints.ts
    ```typescript
    [operationId: string]: {
       method: 'post' | 'get' | 'put' | 'delete';
       url?: string;
       getUrl?: (...params: any) => string};
       contentType?: string;
    }
    ```   
  1. enums.ts enums.ts all enum definitions.

Common flow

♙ Get the swagger json from the server.

♘ Add it to the UI project (for example: /path/to/json/swagger).

♗ Add a hook to your package.json scripts section:

"build-swagger": "swagger-to-typescript --pathToFile=/path/to/json/swagger"

♕ Add this hook to your build process:

"prebuild": "npm run build-swagger"

♔ Make sure to commit your swagger.json, so the UI build is not dependent on external resources.

view in npmjs.org

1.0.261

4 months ago

1.0.260

4 months ago

1.0.252

4 months ago

1.0.255

4 months ago

1.0.254

4 months ago

1.0.250

4 months ago

1.0.257

4 months ago

1.0.259

4 months ago

1.0.258

4 months ago

1.0.245

4 months ago

1.0.247

4 months ago

1.0.241

10 months ago

1.0.244

8 months ago

1.0.222

1 year ago

1.0.228

1 year ago

1.0.225

1 year ago

1.0.217

1 year ago

1.0.219

1 year ago

1.0.215

1 year ago

1.0.240

1 year ago

1.0.230

1 year ago

1.0.233

1 year ago

1.0.209

2 years ago

1.0.207

2 years ago

1.0.204

2 years ago

1.0.186

2 years ago

1.0.189

2 years ago

1.0.182

2 years ago

1.0.184

2 years ago

1.0.201

2 years ago

1.0.180

2 years ago

1.0.176

2 years ago

1.0.197

2 years ago

1.0.178

2 years ago

1.0.199

2 years ago

1.0.172

2 years ago

1.0.193

2 years ago

1.0.174

2 years ago

1.0.191

2 years ago

1.0.160

3 years ago

1.0.158

3 years ago

1.0.155

3 years ago

1.0.153

3 years ago

1.0.150

3 years ago

1.0.146

3 years ago

1.0.148

3 years ago

1.0.135

3 years ago

1.0.137

3 years ago

1.0.132

3 years ago

1.0.130

3 years ago

1.0.128

3 years ago

1.0.123

3 years ago

1.0.120

3 years ago

1.0.118

3 years ago

1.0.116

3 years ago

1.0.114

3 years ago

1.0.112

3 years ago

1.0.110

4 years ago

1.0.108

4 years ago

1.0.101

4 years ago

1.0.103

4 years ago

1.0.105

4 years ago

1.0.99

4 years ago

1.0.97

4 years ago

1.0.95

4 years ago

1.0.91

4 years ago

1.0.93

4 years ago

1.0.87

4 years ago

1.0.89

4 years ago

1.0.83

4 years ago

1.0.0

4 years ago