跳到正文
Skillpedia
API 与服务器(后端)40k · #7313

openapi-to-application-code

它能做什么

这个工具可以根据一个描述 API 的文件(称为 OpenAPI)创建一个完整的、可直接使用的应用程序。它会理解 API 应该如何工作,并生成所需的代码。

适用场景

  • ✓当你已经有 API 描述文件,并希望得到一个使用该 API 的应用程序时。
  • ✓当你想基于现有 API 快速创建一个应用原型时。
  • ✓当你开始一个新项目,希望自动生成基础代码结构时。

技能链接

https://github.com/github/awesome-copilot/blob/main/skills/openapi-to-application-code/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/github/awesome-copilot/blob/main/skills/openapi-to-application-code/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“根据 https://api.example.com/v2/openapi.json 中的 OpenAPI 规范生成一个应用,使用 Spring Boot 框架,并采用 JWT 身份验证。”

每周 5 个新技能,1 分钟读完。

工作原理

AI 会读取 API 描述(OpenAPI),理解其中的数据和可用功能。然后它会搭建应用的结构,为各个部分编写代码(比如接收请求、处理数据、返回响应),并添加测试和文档。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Generate Application from OpenAPI Spec

Your goal is to generate a complete, working application from an OpenAPI specification using the active framework's conventions and best practices.

Input Requirements

  1. OpenAPI Specification: Provide either:

    • A URL to the OpenAPI spec (e.g., https://api.example.com/openapi.json)
    • A local file path to the OpenAPI spec
    • The full OpenAPI specification content pasted directly
  2. Project Details (if not in spec):

    • Project name and description
    • Target framework and version
    • Package/namespace naming conventions
    • Authentication method (if not specified in OpenAPI)

Generation Process

Step 1: Analyze the OpenAPI Specification

  • Validate the OpenAPI spec for completeness and correctness
  • Identify all endpoints, HTTP methods, request/response schemas
  • Extract authentication requirements and security schemes
  • Note data model relationships and constraints
  • Flag any ambiguities or incomplete definitions

Step 2: Design Application Architecture

  • Plan directory structure appropriate for the framework
  • Identify controller/handler grouping by resource or domain
  • Design service layer organization for business logic
  • Plan data models and entity relationships
  • Design configuration and initialization strategy

Step 3: Generate Application Code

  • Create project structure with build/package configuration files
  • Generate models/DTOs from OpenAPI schemas
  • Generate controllers/handlers with route mappings
  • Generate service layer with business logic
  • Generate repository/data access layer if applicable
  • Add error handling, validation, and logging
  • Generate configuration and startup code

Step 4: Add Supporting Files

  • Generate appropriate unit tests for services and controllers
  • Create README with setup and running instructions
  • Add .gitignore and environment configuration templates
  • Generate API documentation files
  • Create example requests/integration tests

Output Structure

The generated application will include:

project-name/
├── README.md                      # Setup and usage instructions
├── [build-config]                 # Framework-specific build files (pom.xml, build.gradle, package.json, etc.)
├── src/
│   ├── main/
│   │   ├── [language]/
│   │   │   ├── controllers/       # HTTP endpoint handlers
│   │   │   ├── services/          # Business logic
│   │   │   ├── models/            # Data models and DTOs
│   │   │   ├── repositories/      # Data access (if applicable)
│   │   │   └── config/            # Application configuration
│   │   └── resources/             # Configuration files
│   └── test/
│       ├── [language]/
│       │   ├── controllers/       # Controller tests
│       │   └── services/          # Service tests
│       └── resources/             # Test configuration
├── .gitignore
├── .env.example                   # Environment variables template
└── docker-compose.yml             # Optional: Docker setup (if applicable)

Best Practices Applied

  • Framework Conventions: Follows framework-specific naming, structure, and patterns
  • Separation of Concerns: Clear layers with controllers, services, and repositories
  • Error Handling: Comprehensive error handling with meaningful responses
  • Validation: Input validation and schema validation throughout
  • Logging: Structured logging for debugging and monitoring
  • Testing: Unit tests for services and controllers
  • Documentation: Inline code documentation and setup instructions
  • Security: Implements authentication/authorization from OpenAPI spec
  • Scalability: Design patterns support growth and maintenance

Next Steps

After generation:

  1. Review the generated code structure and make customizations as needed
  2. Install dependencies according to framework requirements
  3. Configure environment variables and database connections
  4. Run tests to verify generated code
  5. Start the development server
  6. Test endpoints using the provided examples

Questions to Ask if Needed

  • Should the application include database/ORM setup, or just in-memory/mock data?
  • Do you want Docker configuration for containerization?
  • Should authentication be JWT, OAuth2, API keys, or basic auth?
  • Do you need integration tests or just unit tests?
  • Any specific database technology preferences?
  • Should the API include pagination, filtering, and sorting examples?
常见问题

什么是 OpenAPI 规范?

它是一个描述 API 工作方式的文件,详细说明 API 接收和返回哪些数据,以及可以执行哪些操作。

生成的应用能直接运行吗?

可以。目标是生成一个完整且可用的应用,只需稍作配置就能运行。

我能选择应用使用的技术吗?

可以。如果 API 规范中没有指定,你可以自己指定想用的框架和其他技术。

详情

作者的原始描述

Generate a complete, production-ready application from an OpenAPI specification

repo: github/awesome-copilot

热度

GitHub 星标
40k
排名
#7313
许可证
MIT
更新时间
2026/10/15

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能