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