Emit more correct openAPI spec - #2476
Open
four-random-common-words wants to merge 12 commits into
Open
Conversation
four-random-common-words
force-pushed
the
2024-emit-correct-api-spec
branch
from
September 9, 2026 11:09
3825d6f to
ad794e9
Compare
four-random-common-words
marked this pull request as ready for review
September 9, 2026 11:45
four-random-common-words
force-pushed
the
2024-emit-correct-api-spec
branch
from
September 10, 2026 09:01
87db4f1 to
c34ee0f
Compare
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.
Issue: #2404
Frontend PR: hashtopolis/web-ui#817
Hashtopolis Client PR: hashtopolis/python-hashtopolis#11
Goal
Make the served OpenAPI spec describe what the helper endpoints actually return, and make the helper responses themselves JSON:API-compliant where they were not. This is the backend half of hashtopolis/web-ui#2404: the frontend generates its types from this spec, so every mismatch here became a runtime schema violation there.
How to review
Start with
HelperApiPathBuilder.phpandJsonApiFragments.phpfor the spec side, thenAbstractBaseAPI.phpandAbstractModelAPI.phpfor the permission split. The helper edits are small and follow from those.openapi.jsonand the fixtures are generated output; CI verifies they match the code, so skip them.Mechanism
getResponse()on a helper now distinguishes a single model ("File") from a list ("Task[]"). Two new optional hooks cover the cases a sample value cannot express:getMetaResponseSchema()formetamembers with dynamic keys (dates, ids), andgetNoContentMethods()for actions that answer 204.HelperApiPathBuilderturns those declarations into<Helper>Responseschemas instead of pointing every helper at the model route'sSingleResponse. To do so,ModelApiPathBuildernow registers each model's resource object as its own<Model>ResourceObjectcomponent so helpers can reference the same shape inside a slimmer envelope (jsonapianddata, nolinksormeta).meta, resources live indata. Helpers that return plain numbers (completed counts, cracks per day) now put them undermetawith an emptydataarray, as JSON:API requires. Helpers that return a model return it as a resource object underdata.preCommon()is split intobootRequest()(user lookup, AccessControl, route parser) andauthorize()(permission check). The serializersgetOneResource()andgetManyResources()now only callbootRequest(). The action that invokes them does the permission check with its own requirements. This lets a POST helper return a model resource without also needing the model route's create permission.Mechanical changes that follow
getAccessGroups,getBestTasksAgent,getCracksOfTask,getGlobalConfigdeclareModel[].getCracksOfTaskcarries a comment thatHash[]is a simplification for the binary-hashlist case.meta.getCompletedCountreturns viagetMetaResponse()and documents its keys with a sample map.getCracksPerDayusesgetMetaResponseSchema()and still emits{}for an empty result.recountFileLinesreturns the File. It hands back the model instead of an attribute array, so the file comes back as a resource object underdata.currentUserPATCH documented as 204. The spec no longer claims a 200 body for it.AbstractModelAPI::get()callspreCommon(). The relationship routes callbootRequest()plusauthorize()on the related API class before serializing.metaand check the recounted file underdata.FullSpecTestandSpecBuilderHelperApiTestassert the new helper response components and the 204. Three new spec fixtures (config, crackerbinarytype, hashtype) capture the addedResourceObjectcomponents.openapi.jsonregenerated. Bulk diff, produced by the builder from the changes above.