承接 dandoetech/laravel-openapi-generator 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

dandoetech/laravel-openapi-generator

最新稳定版本:v0.2.0

Composer 安装命令:

composer require dandoetech/laravel-openapi-generator

包简介

Laravel bridge for DanDoeTech OpenAPI generator: artisan export command and wiring.

README 文档

README

Pre-release — Architecture by senior tech lead, implementation largely AI-assisted with human review. Not fully reviewed. Architecture may change before v1.0.0.

Laravel bridge for the DanDoeTech OpenAPI generator. Provides an Artisan command to export OpenAPI 3.1 specs from the Resource Registry.

Installation

composer require dandoetech/laravel-openapi-generator

The service provider is auto-discovered. Publish the config:

php artisan vendor:publish --tag=ddt-openapi-config

Requires dandoetech/laravel-resource-registry.

Quick Start

Export the spec:

php artisan openapi:export

This generates an OpenAPI 3.1 JSON file at storage/app/openapi.json (configurable).

Override title or version:

php artisan openapi:export --title="Catalog API" --oaversion="2.0.0"
php artisan openapi:export --output="public/openapi.json"

What Gets Generated

Every registered resource produces:

  • GET /{resource} — list endpoint
  • POST /{resource} — create endpoint
  • GET /{resource}/{id} — show endpoint
  • A component schema with all fields and computed fields

Example output (abbreviated):

{
  "openapi": "3.1.0",
  "info": { "title": "API", "version": "1.0.0" },
  "servers": [{ "url": "http://localhost/api", "description": "Primary API" }],
  "paths": {
    "/product": {
      "get": { "summary": "List Product" },
      "post": { "summary": "Create Product" }
    },
    "/product/{id}": {
      "get": { "summary": "Fetch Product" }
    }
  },
  "components": {
    "schemas": {
      "Product": {
        "type": "object",
        "properties": {
          "name": { "type": "string" },
          "price": { "type": "number", "format": "double" },
          "category_name": { "type": "string" }
        },
        "required": ["name", "price"]
      },
      "ProblemJson": { "..." : "..." }
    }
  }
}

Computed fields (like category_name) appear in schemas as regular properties. Error responses use the RFC 7807 ProblemJson schema.

Configuration

config/ddt_openapi.php:

return [
    // OpenAPI info block
    'title'   => env('OPENAPI_TITLE', 'API'),
    'version' => env('OPENAPI_VERSION', '1.0.0'),

    // Output path relative to storage_path()
    'output'  => env('OPENAPI_OUTPUT', 'app/openapi.json'),
];

The server URL is built from config('app.url') and the API prefix from config('ddt_api.prefix') (configured in laravel-generic-api).

Programmatic Use

Generate the spec in code:

use DanDoeTech\LaravelOpenApiGenerator\Services\OpenApiGenerator;

$generator = app(OpenApiGenerator::class);
$spec = $generator->create(); // array

return response()->json($spec);

API Overview

Class Purpose
OpenApiServiceProvider Registers config, artisan command
OpenApiExportCommand openapi:export with --output, --title, --oaversion options
OpenApiGenerator (service) Builds spec from Registry + config, returns array

Testing

composer install
composer test        # PHPUnit (Orchestra Testbench)
composer qa          # cs:check + phpstan + test

License

MIT

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 5
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-15

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固