1.0.2 • Published 5 months ago

@waiin/openapi-tools v1.0.2

Weekly downloads
-
License
Apache 2.0
Repository
github
Last release
5 months ago

@waiin/openapi-tools

Effortless API Integration for React with OpenAPI

šŸ”§ @waiin/openapi-tools is a powerful tool and library designed to streamline API development by generating proxy services and Redux integrations for React applications based on OpenAPI specifications. It supports any JSON from Swagger, allowing seamless API consumption with minimal effort.


✨ Features

šŸ”¹ Proxy Generation

āœ… Automatically creates API service layers from OpenAPI specs.
āœ… Supports RESTful API requests with built-in configurations.
āœ… Reduces boilerplate code for API calls.

šŸ”¹ Redux Integration

āœ… Generates Redux slices and hooks for API state management.
āœ… Provides seamless state management for API responses.
āœ… Enables easy caching and refetching of data.

šŸ”¹ Swagger & OpenAPI Compatibility

āœ… Works with any JSON format from Swagger/OpenAPI.
āœ… Parses OpenAPI definitions to generate type-safe API services.

šŸ”¹ Customizable Output

āœ… Allows modifications to generated services.
āœ… Configurable templates for service generation.

šŸ”¹ Developer-Friendly Usage

āœ… Simple CLI commands for API generation.
āœ… Minimal configuration required for setup.


šŸ“¦ Installation

Install using npm:

npm install @waiin/openapi-tools

āš™ļø Setup & Usage

1ļøāƒ£ Add script in package.json

"scripts": {
  "generate": "npx openapi-tools --source <local_path_or_url> --output <output_directory>"
}

2ļøāƒ£ Example Script Execution

šŸ“‚ Using a Local File

"scripts": {
  "generate": "npx openapi-tools --source D:/Waiin/controller-api/gen/http/openapi3.json --output src/middleware"
}

🌐 Using a URL

"scripts": {
  "generate": "npx openapi-tools --source https://petstore3.swagger.io/api/v3/openapi.json --output src/middleware"
}

3ļøāƒ£ Run the Script in Terminal

npm run generate

šŸ”— Expected Integration in React

Generated API hooks and Redux slices allow easy integration:

import { useEffect } from "react";
import { useDispatch, useSelector } from "react-redux";
import { listFindPetsByStatus, StatusEnum } from "./api/petService";

const App = () => {
  const dispatch = useDispatch();
  const pets = useSelector((state: any) => state.petReducer);

  useEffect(() => {
    dispatch(listFindPetsByStatus(StatusEnum.Sold));
  }, [dispatch]);

  return <div>{JSON.stringify(pets)}</div>;
};

šŸ”§ Create New File or Existing section for Calls

const axiosInstance = axios.create({ baseURL: 'https://petstore3.swagger.io/api/v3' });
 
axiosInstance.interceptors.response.use(
  (response) => response,
  (error) => Promise.reject((error.response && error.response.data) || 'Something went wrong!')
);
export const store = configureStore({
  reducer: CombineReducers,
  middleware: (getDefaultMiddleware) => getDefaultMiddleware().concat(thunk, axiosMiddleware(axiosInstance)),
});
export type RootStateType = ReturnType<typeof store.getState>;

šŸ“œ Why Choose @waiin/openapi-tools?

šŸš€ Boost Productivity – Save time on writing API calls manually.
⚔ Seamless Redux Integration – Get auto-generated slices & hooks.
šŸ“– Type-Safe Code – Ensures strong typing with OpenAPI.
šŸ”§ Customizable & Scalable – Modify templates as per project needs.


šŸ”„ Supercharge your API workflow today! Install and start using @waiin/openapi-tools now. šŸš€

1.0.2

5 months ago

1.0.1

5 months ago

1.0.0

5 months ago