This FastAPI application generates OpenAPI v3 specifications based on user prompts using an AI model. It also logs all requests and responses.
- Features
- Requirements
- Installation
- Usage
- API Endpoints
- Database
- Docker Deployment
- Contributing
- License
- Generate OpenAPI v3 specifications from user prompts
- Log all requests and responses
- Retrieve logs of past interactions
- Dockerized application for easy deployment
- Python 3.12+
- FastAPI
- Pydantic
- OpenAI Python Client
- Peewee ORM
- Uvicorn ASGI server
-
Clone the repository:
git clone https://github.com/0xstackforge/openapi-spec-generator.git cd openapi-spec-generator -
Create a virtual environment:
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate` -
Install the required packages:
pip install -r requirements.txt
-
Start the FastAPI server:
uvicorn main:app --reload -
The API will be available at
http://localhost:8000 -
Use the
/openapi-spec-generatorendpoint to generate OpenAPI specifications -
View logs using the
/logsendpoint
Generate an OpenAPI v3 specification based on a user prompt.
Request Body:
{
"prompt": "Create an API for a todo list application"
}Response:
A JSON object containing the generated OpenAPI v3 specification.
Retrieve the logs of past interactions.
Query Parameters:
limit(optional): Number of log entries to return (default: 1000)
Response:
An array of log entries, each containing:
timestamp: The time of the requestrequest: The original requestresponse: The generated response
The application uses SQLite to store logs. The database file ai_service.db will be created in the project root directory.
- Docker
- Docker Compose
- Build and start the services:
docker-compose up --build- Access the application:
- Main application: http://localhost:8000
- Ollama API: http://localhost:11434
- Stop the services:
docker-compose downTo run the application using Docker directly:
-
Build the Docker image:
docker build -t openapi-spec-generator . -
Run the container:
docker run -p 8000:8000 openapi-spec-generator
The API will be available at http://localhost:8000
erDiagram
LogEntry {
int id PK
datetime timestamp
text request
text response
}
- Fork the repository
- Create a feature branch (
git checkout -b feature/your-feature-name) - Commit your changes (
git commit -m 'Add your feature') - Push to the branch (
git push origin feature/your-feature-name) - Open a Pull Request