Repository navigation
Add a layered ViewSet API - #63
Draft
jgoclawski wants to merge 10 commits into
Draft
jgoclawski wants to merge 10 commits into
jgoclawski wants to merge 10 commits into
Conversation
Positional forms from 1.4 keep working without warnings: services raise
ForbiddenError('...') in many places.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
jgoclawski
force-pushed
the
api_layers_redesign
branch
from
October 18, 2026 09:10
6233a1c to
a9cd4b6
Compare
jgoclawski
marked this pull request as draft
October 18, 2026 09:13
jgoclawski
force-pushed
the
api_layers_redesign
branch
from
October 18, 2026 19:42
a9cd4b6 to
59990b6
Compare
Failed commits and flushes roll the session back before the error is translated, so a scoped session stays usable after a Conflict. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Deprecation is documentation only: no runtime warnings, because existing services declare hundreds of legacy ViewSets. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
jgoclawski
force-pushed
the
api_layers_redesign
branch
from
October 18, 2026 21:40
59990b6 to
212c1a0
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.
Summary
A new way to build JSON:API endpoints from small layers, next to the existing classes, which keep working unchanged.
A
ViewSetdeclares a resource: schema, filter schema,allowed_actions,guards,object_permissions,middlewaresand onedata_service. A request goes through these layers in a fixed order:405before the request body is parsed. The default is empty, so a ViewSet that declares nothing serves nothing.flask_jsonapi.permissions.CheckObjectPermission), always the outermost data layer.Noneby default; a subclass can switch it off for another audience. On lists, the layer's filter restricts the query to objects the client may list (and may answer403for a scope the client named but may not list); if the per-object check still drops an object, the view logs a warning and hides the total, so a total never counts objects the client cannot see.inner, the rest of the chain, so it can act before and after the call.ResourceNotFound,PermissionDenied,InvalidData,Conflict,Unavailable, ...), which the view translates to JSON:API errors in one place.One vocabulary from declaration to repository:
Actions.create/read/list/update/destroymap tocreate(data),read(id),list(filters, sorting, pagination)returningListResult(items, total),update(resource, data),destroy(resource). Detail actions load the object once and hand it toupdateanddestroy. Presentation work such as rendering belongs in the schema. Layers are instances created once and shared by all requests, so they must keep no per-request state.Documentation: a guide with how-to recipes and a full, tested example in
docs/guide.rst; reference pagesdocs/layers.rst,docs/view_sets.rst,docs/views.rst; a migration guide indocs/migration.rst.Main additions
flask_jsonapi.ViewSet,DetailView,ListView;Actions.list(Actions.read_manykept as an alias)flask_jsonapi.guards.Guardflask_jsonapi.permissions.ObjectPermissions,CheckObjectPermissionflask_jsonapi.middlewares:Middleware,build_pipeline,CheckRequiredListFiltersflask_jsonapi.data_services:DataService,ListResult, its exceptions,LegacyRepositoryAdapter, anddata_services.sqlalchemy_repositories.SqlAlchemyModelRepositoryUnauthorized,UnprocessableEntity,ServiceUnavailableChanges for existing code (no migration needed)
logger.exceptionand answered with a generic500without internal details;flask.abort()responses are converted too.@app.errorhandler) no longer run for exceptions raised inside flask-jsonapi views, and in testing mode such exceptions no longer propagate to the test client.HEADis served by theGEThandler; a PATCH with a wrong resourcetypeanswers409.detailandsourceare omitted from error objects; exception classes accept keyword arguments, and every positional form that worked before still works.Testing
docs/examples/full_example.pyand every documented request and response is asserted bytests/test_docs_full_example.py.Builds on #62.
🤖 Generated with Claude Code