Repository navigation
feat: per-resource OpenAPI input schemas + spec completeness guard (needs laravel-api 5.11) - #10
Merged
Merged
Conversation
ResourceController serves every resource, so create/update declared no fields at all. They now declare `@input [operationSchema]`; laravel-api 5.11 calls it once per route with an OperationContext, and the schema is built from the resource's fields() and validationRules() (types, formats, required, nullable, enums, bounds, patterns, confirmed twins, translatable and file shapes). The same covers the resource-specific input of search, summary, tree, export, action, reorder, inlineUpdate and settings update. Also: system/search documents `q` and GlobalSearchResponse; dashboard/reset gets its docblock; tokenCreate abilities[] and action payload typed. OpenApiSpecCompletenessTest walks the generated spec: every create/update documents each validated field, no dangling $ref, api:lint reports nothing (including input.undeclared). Requires dskripchenko/laravel-api ^5.11. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
# Conflicts: # CHANGELOG.md
# Conflicts: # CHANGELOG.md # src/Widget/DashboardController.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
One
ResourceControllerserves every resource, socreate/updatedocumented no fields at all (the "Which@inputfields there are is decided byResource::fields()" prose). With laravel-api 5.11 a@input [method]receives anOperationContext(controller key = resource slug, action, Api class = panel), so:ResourceController::operationSchema(OperationContext)builds the input schema of one operation on one resource:create/update— fromfields()+validationRules($context): types, formats (email/uri/uuid/date/date-time/password),required,nullable, enums from options andin:/Rule::in/Rule::enum, min/max/between/size →minimum/maxLength/minItemsby type, flaglessregex:→pattern,confirmed→*_confirmation, translatable values per locale, the upload-first{disk, path}of file fields, multiple selects as arrays of enum, defaults and labels;search/summary/tree/export— filters keyed by field (or the{column, value}list form), sortable columns,group_by, exportable columns and registered formats;action—idsandkeyas an enum of dispatchable actions;reorder;inlineUpdate— editable columns.SettingsController::operationSchema— thevaluesof a settings group.Http\OpenApi\RulesSchema(rules + fields → object schema) andHttp\OpenApi\ResourceOperationSchema.system/searchdocumentsqand aGlobalSearchResponse;dashboard/resethad no docblock at all;tokenCreateabilities[]typed as strings;actionpayloadis an object. (actionids/key,dashboard/savewidgets.*andtokenCreatehad already been fixed in 1.31–1.33; the roadmap entries are now marked closed.)Measured on the test app's fixture resources (9 resources, 1 settings group, 1 screen): operations without any input 65/189 → 47/189 (the rest are GET reads and body-less actions); every
create/updatenow carries the resource's fields;api:lint→ 0 issues.Regression guard (BL-46):
tests/Feature/OpenApiSpecCompletenessTest.php— for every registered fixture resource, the documented create/update properties ⊇ the keys ofvalidationRules(); resource-specific inputs present; no$refto an undefined schema;OpenApiLinterreports nothing, including the newinput.undeclaredrule (an action that validates input and declares none). Plus a panel test (client panel's resource resolved in its own panel) andRulesSchemaTestunit tests.Test plan
vendor/bin/pest— 965 passed, run locally with laravel-api pointed at thefeat/operation-context-schemasbranch (temporary local override, not committed)vendor/bin/pint --test,vendor/bin/phpstan analyse— clean🤖 Generated with Claude Code