The api-di-connector
package provides the ability to generate connectors for working with your Swagger API. It supports Swagger version v3 and utilizes a restClient based on the Axios library.
npm i -D api-di-connector
npm i axios axios-retry
npx api-di-connector
√ Add Swagger Link: example.com/v3/api-docs
√ Project Language: js/ts
This repository contains a service implementation with the following directory structure:
service
|-- ApiService
| |-- api
| | |-- ApiModule1Class1
| |-- ApiDiContainer
| |-- RestClient
| |-- interfaces (optional for TypeScript)
| |-- SwaggerSchemas
The ApiService directory encompasses the core functionality of the service.
The ApiDiContainer is a dependency injection container that consolidates all classes defined in the api directory. It serves as a centralized mechanism for managing dependencies within the service.
The RestClient module defines the basic methods for interacting with the axios library, providing a foundation for making HTTP requests. It encapsulates common functionalities required for communication with external APIs.
If TypeScript is chosen as the language, the interfaces directory contains TypeScript interfaces that represent the schemas defined in the Swagger documentation
- Generation of connectors for PATCH, POST, DELETE, GET requests based on Swagger specification v3.
- Addition of query parameters, path parameters, and body for POST requests to the respective controllers.
- Generation of annotations for controllers.
- Use of Bearer authorization in request headers.
// Example usage of generated connectors
import ApiDiContainer from '@service/apiService/apiDiContainer';
ApiDiContainer.ProxyApiUser.getUsers().then((res) => {
this.setState({ listOfUser: res.data });
});
- Ensure that your Swagger API adheres to the Swagger v3 specification.
- Before usage, make sure you have the Axios package installed.
This project is licensed under the ISC License.