Commit 11b56b4
authored
Merge pull request #12 from jkbennemann/feat/enhance-features-for-dynamic-generation
Summary
This PR significantly enhances the Laravel API Documentation package with comprehensive improvements to parameter detection, response analysis, and OpenAPI schema generation. The changes ensure 100% accurate API documentation that correctly reflects actual Laravel application behavior.
Key Features Added
🏷️ Parameter Attribute Enhancement for Responses
Extended Parameter attributes to work for both request parameters AND response schemas
Enhanced OpenAPI documentation with developer-provided Parameter attribute metadata (types, descriptions, formats, examples)
Application-agnostic implementation that works across all Laravel applications without namespace dependencies
MediaType-level example generation from Parameter attribute examples
🔄 FormRequest Inheritance Support
Fixed validation rule detection for FormRequest classes that extend parent classes with rules
Inheritance chain traversal to find validation rules in parent FormRequest classes
Enhanced AST analysis to properly handle complex inheritance scenarios
Route parameter detection with proper exclusion from request body documentation
📊 Laravel Resource Response Analysis
Enhanced JsonResource detection for Resource::make() patterns in controller methods
DTO analysis for Resource proxies - automatically detects and analyzes Spatie Data DTOs wrapped by Resources
Constructor parameter analysis to extract schema from Resource-wrapped DTOs
Improved AST parsing with proper error handling and fallback mechanisms
🎯 HTTP Status Code Detection
Added setStatusCode() pattern detection for chained method calls like ->response()->setStatusCode(HTTP_CREATED)
Enhanced AST visitor with method-scoped analysis for accurate status code detection
HTTP constant resolution for ResponseAlias::HTTP_CREATED and similar patterns
Proper 201 Created documentation instead of incorrect 200 responses
📦 Laravel JsonResource Response Wrapping
Automatic wrapper detection for Laravel JsonResource responses
Support for custom $wrap properties
Default "data" wrapper handling when no custom wrapper is configured
Collection and single resource wrapping with proper OpenAPI schema structure
Accurate response examples that match actual API output
Technical Implementation
Enhanced Services
ResponseAnalyzer: Added Resource wrapper detection, constructor analysis, and DTO extraction
EnhancedResponseAnalyzer: Improved AST analysis with setStatusCode detection and method-scoped visitor
RequestAnalyzer: Added FormRequest inheritance traversal and Parameter attribute merging
New Capabilities
Dynamic class discovery for application-agnostic DTO analysis
Snake case mapping support for Spatie Data objects with MapName attributes
Comprehensive error handling with graceful fallbacks for analysis failures
Debug-friendly implementation with detailed metadata for troubleshooting
Testing
All changes have been thoroughly tested with:
✅ Complex inheritance chains and DTO structures
✅ Various Resource wrapping configurations
✅ HTTP status code detection patterns
✅ Parameter attribute processing for requests and responses
Breaking Changes
None - This PR is fully backward compatible and enhances existing functionality without breaking changes.
Impact
This PR transforms the package from generating basic API documentation to producing enterprise-grade, 100% accurate OpenAPI specifications that perfectly match actual Laravel application behavior. The enhancements ensure developers can rely on the generated documentation for client SDK generation, API testing, and integration work.File tree
64 files changed
+8257
-1817
lines changed- config
- src
- Attributes
- Commands
- Exceptions
- Http/Controllers
- Services
- Traits
- Traits
- tests
- Feature
- Stubs
- Controllers
- DTOs
- Models
- Requests
- Resources
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
64 files changed
+8257
-1817
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
69 | | - | |
| 69 | + | |
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
| |||
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
84 | | - | |
| 84 | + | |
85 | 85 | | |
86 | 86 | | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | 87 | | |
99 | 88 | | |
100 | 89 | | |
101 | 90 | | |
102 | 91 | | |
103 | | - | |
| 92 | + | |
104 | 93 | | |
105 | 94 | | |
106 | 95 | | |
| |||
109 | 98 | | |
110 | 99 | | |
111 | 100 | | |
112 | | - | |
113 | | - | |
114 | 101 | | |
115 | 102 | | |
116 | 103 | | |
| |||
123 | 110 | | |
124 | 111 | | |
125 | 112 | | |
126 | | - | |
| 113 | + | |
127 | 114 | | |
128 | 115 | | |
129 | 116 | | |
| 117 | + | |
130 | 118 | | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
131 | 123 | | |
132 | 124 | | |
133 | 125 | | |
134 | 126 | | |
135 | | - | |
136 | 127 | | |
137 | 128 | | |
138 | 129 | | |
| |||
146 | 137 | | |
147 | 138 | | |
148 | 139 | | |
149 | | - | |
| 140 | + | |
150 | 141 | | |
151 | 142 | | |
152 | 143 | | |
153 | 144 | | |
154 | 145 | | |
155 | 146 | | |
156 | | - | |
157 | | - | |
158 | 147 | | |
159 | | - | |
| 148 | + | |
160 | 149 | | |
161 | 150 | | |
162 | 151 | | |
| |||
165 | 154 | | |
166 | 155 | | |
167 | 156 | | |
| 157 | + | |
168 | 158 | | |
169 | 159 | | |
170 | 160 | | |
| |||
174 | 164 | | |
175 | 165 | | |
176 | 166 | | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
177 | 173 | | |
178 | 174 | | |
179 | 175 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
13 | 12 | | |
14 | 13 | | |
15 | 14 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
29 | | - | |
| 30 | + | |
30 | 31 | | |
| 32 | + | |
31 | 33 | | |
32 | 34 | | |
33 | 35 | | |
34 | | - | |
| 36 | + | |
35 | 37 | | |
36 | 38 | | |
| 39 | + | |
37 | 40 | | |
38 | 41 | | |
39 | 42 | | |
| |||
48 | 51 | | |
49 | 52 | | |
50 | 53 | | |
| 54 | + | |
51 | 55 | | |
52 | 56 | | |
53 | 57 | | |
| |||
58 | 62 | | |
59 | 63 | | |
60 | 64 | | |
61 | | - | |
| 65 | + | |
62 | 66 | | |
63 | 67 | | |
64 | 68 | | |
65 | 69 | | |
66 | 70 | | |
67 | 71 | | |
68 | 72 | | |
69 | | - | |
| 73 | + | |
| 74 | + | |
70 | 75 | | |
71 | 76 | | |
72 | | - | |
73 | | - | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
74 | 80 | | |
75 | 81 | | |
76 | 82 | | |
| |||
107 | 113 | | |
108 | 114 | | |
109 | 115 | | |
110 | | - | |
| 116 | + | |
111 | 117 | | |
112 | 118 | | |
113 | 119 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
10 | | - | |
11 | | - | |
| 9 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
| 28 | + | |
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | | - | |
| 34 | + | |
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
34 | 35 | | |
35 | 36 | | |
36 | 37 | | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
37 | 46 | | |
38 | 47 | | |
39 | 48 | | |
| |||
0 commit comments