https://github.com/nightmaregaurav/swagger-endpoints-gen
Auto generate typescript models and endpoints from swagger.json
https://github.com/nightmaregaurav/swagger-endpoints-gen
api api-integration automate-swagger developer-tool developer-tools endpoints-specification interface-builder models-generation openapi-generator swagger swagger-codegen swagger-model-generator typescript typescript-interface-generator typescript-models
Last synced: 8 months ago
JSON representation
Auto generate typescript models and endpoints from swagger.json
- Host: GitHub
- URL: https://github.com/nightmaregaurav/swagger-endpoints-gen
- Owner: nightmaregaurav
- License: mit
- Created: 2022-12-30T03:30:27.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-01-10T16:38:29.000Z (over 2 years ago)
- Last Synced: 2025-08-29T20:55:51.516Z (9 months ago)
- Topics: api, api-integration, automate-swagger, developer-tool, developer-tools, endpoints-specification, interface-builder, models-generation, openapi-generator, swagger, swagger-codegen, swagger-model-generator, typescript, typescript-interface-generator, typescript-models
- Language: TypeScript
- Homepage:
- Size: 104 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Swagger Endpoints Generator (Ts/Js)
[](https://badge.fury.io/js/@nightmaregaurav%2Fswagger-endpoints-gen) [](http://hits.dwyl.com/nightmaregaurav/swagger-endpoints-gen)
[](https://nodei.co/npm/@nightmaregaurav/swagger-endpoints-gen/)
***
### Description
Automatically generate typescript models and endpoints from `swagger.json` so api call is as simple as writing `endpoints.API__GET__my_object.call({data:value});`
### Installation
Install swagger-endpoints-gen globally (Preferred)
```bash
npm install -g @nightmaregaurav/swagger-endpoints-gen
```
install swagger-endpoints-gen locally as dev dependency
```bash
npm install -D @nightmaregaurav/swagger-endpoints-gen
````
### Usage
## For command line usage
Contents of `in.json`:
```json
[
{
"outDir": "/path/to/output/folder1",
"baseUrl": "http://base.url.system",
"bearerTokenImportPath": "@/auth/authHelpers",
"successErrorMiddlewarePath": "@/middlewares/baseMiddlewares",
"cacheHelperPath": "@/helpers/cacheHelpers",
"swaggers": [],
"swaggerUrls": ["http://base.url.system/swagger/v1/swagger.json"],
"removeComments": true
},
{
"outDir": "/path/to/output/folder2",
"baseUrl": "http://base.url.system",
"bearerTokenImportPath": "@/auth/authHelpers",
"successErrorMiddlewarePath": "@/middlewares/baseMiddlewares",
"cacheHelperPath": "@/helpers/cacheHelpers",
"swaggers": [],
"swaggerUrls": ["http://base.url.system/swagger/v1/swagger2.json"],
"removeComments": false
}
]
```
``` bash
npx generate-endpoints-from-swagger in.json
```
## For programmatic usage
```typescript
import { createEndpointsAndModels } from '@nightmaregaurav/swagger-endpoints-gen';
import swagger1 from './swagger1.json';
import swagger2 from './swagger2.json';
import swagger3 from './swagger3.json';
import swagger4 from './swagger4.json';
createEndpointsAndModels({
outDir: "./endpoints",
bearerTokenImportPath: "@/auth/authHelpers",
successErrorMiddlewarePath: "@/middlewares/baseMiddlewares",
cacheHelperPath: "@/helpers/cacheHelpers",
baseUrl: "https://api.example.com",
swaggers: [swagger1, swagger2, swagger3, swagger4],
swaggerUrls: ["https://api.example.com/swagger/v1/swagger.json", "https://api.example.com/swagger/v2/swagger.json", "https://api.example.com/swagger/v3/swagger.json"],
"removeComments": true
});
```
### Example usage of generated endpoints
```typescript
import { endpoints } from './endpoints';
let userInfo: UserModel = await endpoints.API__GET__user__userId.call({userId: 1});
let userId: number = await endpoints.API__POST__user__schoolId.call({schoolId:2}, {data: {name: "John Doe"}});
// rest of the codes
```
***
## Technical Details
* Language: Typescript
## How to Contribute
* Fork the repository
* Clone the forked repository
* Make changes
* Commit and push the changes
* Create a pull request
* Wait for the pull request to be merged
* Celebrate
* Repeat
*If you are new to open source, you can read [this](https://opensource.guide/how-to-contribute/) to learn how to contribute to open source projects.*
*If you are new to GitHub, you can read [this](https://guides.github.com/activities/hello-world/) to learn how to use GitHub.*
*If you are new to Git, you can read [this](https://www.atlassian.com/git/tutorials/learn-git-with-bitbucket-cloud) to learn how to use Git.*
*If you are new to TypeScript, you can read [this](https://www.typescriptlang.org/docs/handbook/typescript-in-5-minutes.html) to learn how to use TypeScript.*
## License
Swagger Endpoints Generator is released under the MIT License. You can find the full license details in the [LICENSE](LICENSE) file.
Made with ❤️ by [NightmareGaurav](https://github.com/nightmaregaurav).
---
Open For Contribution
---