sdekkers/compass 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

sdekkers/compass

Composer 安装命令:

composer require sdekkers/compass

包简介

Zero-config OpenAPI documentation generator for Laravel modular applications

README 文档

README

Latest Version on Packagist PHP Version License

Zero-config OpenAPI documentation for Laravel. No annotations. No docblocks. Just reads your code.

Features

  • 🔍 Automatic OpenAPI 3.0 spec generation from Laravel routes
  • 📋 Schema extraction from FormRequest validation rules
  • 📦 Response schemas from JsonResource classes
  • 🔐 Auth detection from middleware (Passport, Sanctum, Bearer)
  • 🏷️ Module-based route grouping via controller namespaces
  • 🖥️ Built-in Swagger UI at /docs
  • 📄 YAML and JSON output

Requirements

  • PHP 8.4+
  • Laravel 11 or 12

Installation

composer require sdekkers/compass

Quick Start

php artisan compass:generate

Your openapi.yaml and openapi.json are now in storage/app/compass/. Visit /docs to see the Swagger UI.

Configuration

Publish the config file:

php artisan vendor:publish --tag=compass-config

Key options in config/compass.php:

Option Description
title API documentation title
version API version string
servers Server URLs for the spec
routes.prefixes Route prefixes to include (default: ['api'])
routes.exclude_patterns Glob patterns to exclude
grouping.enabled Auto-group by module namespace
ui.enabled Enable/disable Swagger UI
ui.path URL path for Swagger UI (default: docs)

How It Works

Compass inspects your Laravel application and extracts:

  • Routes — HTTP method, URI, parameters, and middleware from the router
  • Request validation — FormRequest rules() are mapped to OpenAPI request body schemas
  • Response schemas — JsonResource toArray() keys become response schemas
  • Authentication — Middleware like auth:api and auth:sanctum map to security schemes
  • Grouping — Controllers in App\Modules\{Name}\Controllers\ are automatically tagged

Validation Rule Mapping

Laravel Rule OpenAPI
string {type: "string"}
integer {type: "integer"}
boolean {type: "boolean"}
email {type: "string", format: "email"}
uuid {type: "string", format: "uuid"}
date {type: "string", format: "date"}
max:255 {maxLength: 255}
min:1 {minimum: 1}
in:a,b,c {enum: ["a","b","c"]}
nullable {nullable: true}

Contributing

Please see CONTRIBUTING.md for details.

License

The MIT License (MIT). Please see LICENSE for more information.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: ISC
  • 更新时间: 2026-02-20

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固