Problem Statement:
In the process of developing a multi-layered RESTful system, which includes both backend and frontend components, there is a need to identify new endpoints and update existing ones. It is crucial that these updates are reflected in the RESTful client interface or API client proxy. However, the conventional approach involves manual implementation, resulting in numerous issues such as time wastage, inconsistencies between the API definitions and client representation, and a lack of documentation necessary for proper API utilization.
Proposition:
We propose the implementation of a user-friendly auto-generation system that can simultaneously create a well-documented API client proxy. This solution will involve integrating third-party libraries, executing shell commands, and configuring Visual Studio settings.
Prerequisites:
Methodology:
Explanation:
In the API project properties, (1) enable the documentation file, and (2) specify the output XML filename and path.
Source: Adding Swagger to ASP.NET Core Web API Using XML Documentation
Include the on-build generated file in the Swagger configuration to make all documentation references appear in the Swagger UI.
Run the following commands to enable on-build Swagger JSON config file generation and set the path to the Web API project:
To test JSON config file generation, run the following command:
Install AutoRest using npm:
Generate the AutoRest client using the following command:
If the above steps work as expected, you can copy the commands to the post-build section in the Web API build properties. These commands include:
Build your project, and in the file explorer, you should find a folder named "autogen-api-tsclient" located in the root folder of the project.