1
---
2
name: openapi-to-application-code
3
description: 'Generate a complete, production-ready application from an OpenAPI specification'
4
---
5
6
# Generate Application from OpenAPI Spec
7
8
Your goal is to generate a complete, working application from an OpenAPI specification using the active framework's conventions and best practices.
9
10
## Input Requirements
11
12
1. **OpenAPI Specification**: Provide either:
13
- A URL to the OpenAPI spec (e.g., `https://api.example.com/openapi.json`)
14
- A local file path to the OpenAPI spec
15
- The full OpenAPI specification content pasted directly
16
17
2. **Project Details** (if not in spec):
18
- Project name and description
19
- Target framework and version
20
- Package/namespace naming conventions
21
- Authentication method (if not specified in OpenAPI)
22
23
## Generation Process
24
25
### Step 1: Analyze the OpenAPI Specification
26
- Validate the OpenAPI spec for completeness and correctness
27
- Identify all endpoints, HTTP methods, request/response schemas
28
- Extract authentication requirements and security schemes
29
- Note data model relationships and constraints
30
- Flag any ambiguities or incomplete definitions
31
32
### Step 2: Design Application Architecture
33
- Plan directory structure appropriate for the framework
34
- Identify controller/handler grouping by resource or domain
35
- Design service layer organization for business logic
36
- Plan data models and entity relationships
37
- Design configuration and initialization strategy
38
39
### Step 3: Generate Application Code
40
- Create project structure with build/package configuration files
41
- Generate models/DTOs from OpenAPI schemas
42
- Generate controllers/handlers with route mappings
43
- Generate service layer with business logic
44
- Generate repository/data access layer if applicable
45
- Add error handling, validation, and logging
46
- Generate configuration and startup code
47
48
### Step 4: Add Supporting Files
49
- Generate appropriate unit tests for services and controllers
50
- Create README with setup and running instructions
51
- Add .gitignore and environment configuration templates
52
- Generate API documentation files
53
- Create example requests/integration tests
54
55
## Output Structure
56
57
The generated application will include:
58
59
```
60
project-name/
61
├── README.md # Setup and usage instructions
62
├── [build-config] # Framework-specific build files (pom.xml, build.gradle, package.json, etc.)
63
├── src/
64
│ ├── main/
65
│ │ ├── [language]/
66
│ │ │ ├── controllers/ # HTTP endpoint handlers
67
│ │ │ ├── services/ # Business logic
68
│ │ │ ├── models/ # Data models and DTOs
69
│ │ │ ├── repositories/ # Data access (if applicable)
70
│ │ │ └── config/ # Application configuration
71
│ │ └── resources/ # Configuration files
72
│ └── test/
73
│ ├── [language]/
74
│ │ ├── controllers/ # Controller tests
75
│ │ └── services/ # Service tests
76
│ └── resources/ # Test configuration
77
├── .gitignore
78
├── .env.example # Environment variables template
79
└── docker-compose.yml # Optional: Docker setup (if applicable)
80
```
81
82
## Best Practices Applied
83
84
- **Framework Conventions**: Follows framework-specific naming, structure, and patterns
85
- **Separation of Concerns**: Clear layers with controllers, services, and repositories
86
- **Error Handling**: Comprehensive error handling with meaningful responses
87
- **Validation**: Input validation and schema validation throughout
88
- **Logging**: Structured logging for debugging and monitoring
89
- **Testing**: Unit tests for services and controllers
90
- **Documentation**: Inline code documentation and setup instructions
91
- **Security**: Implements authentication/authorization from OpenAPI spec
92
- **Scalability**: Design patterns support growth and maintenance
93
94
## Next Steps
95
96
After generation:
97
98
1. Review the generated code structure and make customizations as needed
99
2. Install dependencies according to framework requirements
100
3. Configure environment variables and database connections
101
4. Run tests to verify generated code
102
5. Start the development server
103
6. Test endpoints using the provided examples
104
105
## Questions to Ask if Needed
106
107
- Should the application include database/ORM setup, or just in-memory/mock data?
108
- Do you want Docker configuration for containerization?
109
- Should authentication be JWT, OAuth2, API keys, or basic auth?
110
- Do you need integration tests or just unit tests?
111
- Any specific database technology preferences?
112
- Should the API include pagination, filtering, and sorting examples?
113