1.0.261 • Published 1 year ago

swagger-to-interfaces v1.0.261

Weekly downloads
32
License
ISC
Repository
gitlab
Last release
1 year 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

1 year ago

1.0.260

2 years ago

1.0.252

2 years ago

1.0.255

2 years ago

1.0.254

2 years ago

1.0.250

2 years ago

1.0.257

2 years ago

1.0.259

2 years ago

1.0.258

2 years ago

1.0.245

2 years ago

1.0.247

2 years ago

1.0.241

2 years ago

1.0.244

2 years ago

1.0.222

2 years ago

1.0.228

2 years ago

1.0.225

2 years ago

1.0.217

2 years ago

1.0.219

2 years ago

1.0.215

2 years ago

1.0.240

2 years ago

1.0.230

2 years ago

1.0.233

2 years ago

1.0.209

3 years ago

1.0.207

3 years ago

1.0.204

3 years ago

1.0.186

4 years ago

1.0.189

4 years ago

1.0.182

4 years ago

1.0.184

4 years ago

1.0.201

3 years ago

1.0.180

4 years ago

1.0.176

4 years ago

1.0.197

4 years ago

1.0.178

4 years ago

1.0.199

4 years ago

1.0.172

4 years ago

1.0.193

4 years ago

1.0.174

4 years ago

1.0.191

4 years ago

1.0.160

4 years ago

1.0.158

4 years ago

1.0.155

4 years ago

1.0.153

4 years ago

1.0.150

4 years ago

1.0.146

5 years ago

1.0.148

5 years ago

1.0.135

5 years ago

1.0.137

5 years ago

1.0.132

5 years ago

1.0.130

5 years ago

1.0.128

5 years ago

1.0.123

5 years ago

1.0.120

5 years ago

1.0.118

5 years ago

1.0.116

5 years ago

1.0.114

5 years ago

1.0.112

5 years ago

1.0.110

5 years ago

1.0.108

5 years ago

1.0.101

5 years ago

1.0.103

5 years ago

1.0.105

5 years ago

1.0.99

5 years ago

1.0.97

5 years ago

1.0.95

5 years ago

1.0.91

5 years ago

1.0.93

5 years ago

1.0.87

5 years ago

1.0.89

5 years ago

1.0.83

6 years ago

1.0.0

6 years ago