Skip to content

swapneswarsundarray/agentif-api-sandbox

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Agentic API Sandbox

A comprehensive Spring Boot application that provides a sandbox environment for testing, mocking, and generating complete microservices from OpenAPI/Swagger specifications. It features a deterministic + AI-assisted workflow for rapid API development and deployment.

πŸš€ Features

Core Sandbox Features

  • API Specification Import: Import OpenAPI/Swagger specs from URLs
  • Mock Data Generation: Automatically generate realistic mock responses
  • Test Case Generation: AI-powered test case generation for API endpoints
  • Validation: Comprehensive request and response validation
  • Configurable Sandbox: Adjustable mock data and validation settings
  • RESTful API: Full REST API for managing and testing APIs

πŸ—οΈ Microservice Generation

  • Complete Microservice Generation: Transform OpenAPI specs into production-ready Spring Boot microservices
  • Database Schema Generation: Automatic entity and table creation with relationships
  • Full CRUD Operations: Complete REST APIs with pagination, search, and filtering
  • Realistic Test Data: Smart test data generation based on field types and contexts
  • Deployment Ready: Docker, Kubernetes, and production configurations
  • AI-Assisted Planning: Intelligent test planning and execution strategies

🧠 AI-Powered Features

  • API Analysis: Intelligent complexity analysis and testing recommendations
  • Test Plan Generation: Comprehensive test case creation with priority-based execution
  • Execution Planning: Optimized test workflow and scheduling
  • Quality Assurance: Automated validation and quality checks

Quick Start

Prerequisites

  • Java 17 or higher
  • Maven 3.6 or higher

Running the Application

  1. Clone the repository:
git clone <repository-url>
cd agentic-api-sandbox
  1. Build the application:
mvn clean install
  1. Run the application:
mvn spring-boot:run

The application will start on http://localhost:8080/api

API Documentation

Once the application is running, you can access:

  • Swagger UI: http://localhost:8080/api/swagger-ui.html
  • OpenAPI JSON: http://localhost:8080/api/api-docs

API Endpoints

Import API Specification

POST /api/sandbox/import/url?url=<swagger-url>

Get All API Specifications

GET /api/sandbox/specs

Get Specific API Specification

GET /api/sandbox/specs/{id}

Execute Endpoint

POST /api/sandbox/execute/{apiSpecId}/{endpointId}?statusCode=200

Configuration

GET /api/sandbox/config
PUT /api/sandbox/config

πŸ—οΈ Microservice Generation Endpoints

Generate Complete Microservice

POST /api/microservice/generate/{apiSpecId}

Transform an API specification into a complete Spring Boot microservice.

Download Generated Microservice

GET /api/microservice/download/{microserviceId}

Download the generated microservice as a ZIP file.

Preview Generated Files

GET /api/microservice/preview/{microserviceId}

Preview the generated microservice files before download.

Validate for Generation

POST /api/microservice/validate

Validate if an API specification is suitable for microservice generation.

🧠 AI Agent Endpoints

Analyze API Specification

GET /api/agent/analyze/{apiSpecId}

AI-powered analysis of API complexity and testing requirements.

Generate Test Plan

POST /api/agent/test-plan/{apiSpecId}

Generate comprehensive test plan with AI assistance.

Generate Execution Plan

POST /api/agent/execution-plan/{apiSpecId}

Create priority-based test execution strategy.

Configuration

The application can be configured via application.yml:

agentic:
  sandbox:
    mock-data:
      enabled: true
      default-response-delay: 100ms
    validation:
      strict-mode: false
    swagger:
      max-file-size: 10MB
      supported-versions: [3.0, 3.1]

Architecture

The application follows a layered architecture:

  • Controller Layer: REST API endpoints
  • Service Layer: Business logic and orchestration
  • Model Layer: Data models and entities
  • Agent Layer: AI-powered test planning and generation
  • Config Layer: Application configuration

Key Components

Services

Sandbox Services

  • SwaggerParserService: Parses OpenAPI/Swagger specifications
  • MockDataService: Generates mock responses based on endpoint definitions
  • ValidationService: Validates API specifications and requests
  • SandboxOrchestrator: Coordinates all sandbox operations

Microservice Generation Services

  • MicroserviceGenerator: Orchestrates complete microservice generation
  • DatabaseSchemaGenerator: Converts API specs to database schemas
  • EntityGenerator: Creates JPA entity classes with relationships
  • RepositoryGenerator: Generates Spring Data repository interfaces
  • ServiceGenerator: Creates business logic layer with CRUD operations
  • ControllerGenerator: Generates REST controllers with OpenAPI documentation
  • TestDataGenerator: Creates realistic test data based on field types
  • ConfigGenerator: Generates deployment configurations (Docker, Kubernetes)

Models

Sandbox Models

  • ApiSpec: Represents an imported API specification
  • Endpoint: Represents an API endpoint with its configuration
  • RequestPayload: Defines request payload structure and validation

Microservice Models

  • MicroserviceSpec: Complete microservice specification
  • EntitySpec: Database entity definitions with field specifications
  • FieldSpec: Field type, validation, and database mapping
  • RelationshipSpec: Entity relationship definitions

Controllers

  • SandboxController: Core sandbox functionality endpoints
  • MicroserviceController: Microservice generation endpoints
  • AgentController: AI-powered test planning and analysis

Agent

  • AgentPlanner: Generates comprehensive test plans and execution strategies

Usage Examples

Import an API Specification

curl -X POST "http://localhost:8080/api/sandbox/import/url?url=https://petstore.swagger.io/v2/swagger.json"

Execute an Endpoint

curl -X POST "http://localhost:8080/api/sandbox/execute/{apiSpecId}/{endpointId}" \
  -H "Content-Type: application/json" \
  -d '{"name": "Test Pet", "status": "available"}'

Update Configuration

curl -X PUT "http://localhost:8080/api/sandbox/config" \
  -H "Content-Type: application/json" \
  -d '{"mockDataEnabled": true, "validationStrictMode": false}'

πŸ—οΈ Microservice Generation Example

Generate a Complete Microservice

# 1. Import an API specification
curl -X POST "http://localhost:8080/api/sandbox/import/url?url=https://petstore.swagger.io/v2/swagger.json"

# 2. Generate a complete microservice from the imported spec
curl -X POST "http://localhost:8080/api/microservice/generate/{apiSpecId}" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "pet-store-microservice",
    "packageName": "com.example.petstore",
    "databaseType": "postgresql",
    "buildTool": "maven"
  }'

# 3. Preview the generated files
curl -X GET "http://localhost:8080/api/microservice/preview/{microserviceId}"

# 4. Download the complete microservice as ZIP
curl -X GET "http://localhost:8080/api/microservice/download/{microserviceId}" \
  -o pet-store-microservice.zip

AI-Powered Test Planning

# 1. Analyze the API specification
curl -X GET "http://localhost:8080/api/agent/analyze/{apiSpecId}"

# 2. Generate comprehensive test plan
curl -X POST "http://localhost:8080/api/agent/test-plan/{apiSpecId}"

# 3. Create execution plan
curl -X POST "http://localhost:8080/api/agent/execution-plan/{apiSpecId}"

Generated Microservice Features

The generated microservice includes:

πŸ“Š Database Layer

  • JPA Entities: Complete with relationships and validation
  • Repositories: Spring Data with custom queries
  • Database Migrations: Automatic schema generation
  • Test Data: Realistic sample data

βš™οΈ Service Layer

  • Business Logic: Complete CRUD operations
  • Validation: Input validation and business rules
  • Transaction Management: Proper transaction boundaries
  • Error Handling: Comprehensive error management

🌐 REST API Layer

  • OpenAPI Documentation: Complete API documentation
  • CRUD Endpoints: Full REST operations
  • Pagination & Sorting: Efficient data retrieval
  • Search & Filtering: Advanced query capabilities

πŸ“¦ Deployment Ready

  • Dockerfile: Container configuration
  • Kubernetes: Orchestration manifests
  • Docker Compose: Local development setup
  • Environment Configs: Multiple environment support

Development

Project Structure

src/main/java/com/agentic/sandbox/
β”œβ”€β”€ controller/
β”‚   └── SandboxController.java
β”œβ”€β”€ service/
β”‚   β”œβ”€β”€ SwaggerParserService.java
β”‚   β”œβ”€β”€ MockDataService.java
β”‚   β”œβ”€β”€ ValidationService.java
β”‚   └── SandboxOrchestrator.java
β”œβ”€β”€ model/
β”‚   β”œβ”€β”€ ApiSpec.java
β”‚   β”œβ”€β”€ Endpoint.java
β”‚   └── RequestPayload.java
β”œβ”€β”€ agent/
β”‚   └── AgentPlanner.java
└── config/
    └── AppConfig.java

Adding New Features

  1. Add new models in the model package
  2. Implement business logic in the service package
  3. Expose functionality through the controller package
  4. Add configuration in the config package

Testing

Run the tests with:

mvn test

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for new functionality
  5. Submit a pull request

License

This project is licensed under the MIT License.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages