This command-line tool generates Swagger documentation for API endpoints using OpenAI's GPT model. It takes a description, request payload, response payload and output format as input and returns Swagger documentation based on the provided details.
- Node.js (v14 or newer)
- Git (for cloning the repository)
- An OpenAI API key (you can obtain one by signing up at https://beta.openai.com/signup/)
- Clone the repository to your local machine:
git clone https://github.com/yourusername/gpt-api-doc-generator.git
- Navigate to the project folder and install the dependencies:
cd gpt-api-doc-generator
npm install
- Set up your OpenAI API key. Create a
.env
file in the root directory of the project and add your OpenAI API key:
OPENAI_API_KEY=your_openai_api_key
-
In the terminal, navigate to the project directory.
-
Run the command:
node index.js
The application will prompt you for the following information:
- Enter the description of the API endpoint.
- Enter the request payload (JSON) in a one-line format.
- Enter the response payload (JSON) in a one-line format.
- Enter the desired output format (JSON or YAML).
After providing the required information, the application will generate Swagger documentation for the given API endpoint and display it in the console.
- The tool will generate and output the Swagger documentation based on the provided details.
- Description:
Retrieve a list of users
- Request payload (JSON, one-line format):
{"page": 1, "pageSize": 10}
- Response payload (JSON, one-line format):
{"data": [{"id": 1, "name": "John Doe", "email": "john.doe@example.com"}, {"id": 2, "name": "Jane Doe", "email": "jane.doe@example.com"}], "total": 100, "page": 1, "pageSize": 10}
- Desired output format (JSON or YAML):
JSON
Use this test input to run the command line application and generate Swagger documentation with descriptions for each field in the request and response payloads.
-
Fork the repository on GitHub.
-
Clone your fork to your local machine:
git clone https://github.com/reinaldoperes/gpt-api-doc-generator.git
- Create a new branch for your changes:
git checkout -b my-feature-branch
-
Make your changes and improvements to the code.
-
Add and commit your changes:
git add .
git commit -m "My new feature or improvement"
- Push your changes to your fork:
git push origin my-feature-branch
- Create a pull request from your fork to the original repository.
This project is licensed under the MIT License.