feat(jsonapi): add JsonAPIResponse base class + JSON:API serialization#93
Merged
Conversation
Implements a JsonAPIResponse base class and JsonAPIListResponse for building JSON:API-compliant response envelopes. Supports to_attributes(), to_relationships(), to_links(), to_meta() hooks, serialize(include=[]) for sideloading related resources, and deduplication of included items. Adds 46 tests covering structure, relationships, include= logic, and list responses. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…FastAPI direct-return support
- parse_include("author,comments") → ["author", "comments"]
- parse_fields({"fields[posts]": "title,body"}) → {"posts": ["title", "body"]}
- serialize(include=..., fields=...) applies sparse fieldset filtering to
both primary data and included resources
- JsonAPIResponse / JsonAPIListResponse now subclass starlette.responses.Response
so returning them directly from a FastAPI endpoint works without calling
.serialize() manually; ?include= and fields[*]= are parsed automatically
from the live ASGI scope
- Response Content-Type is application/vnd.api+json
- 29 new tests (75 total in the jsonapi suite); 513 pass overall
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Removes `import pytest` from three test files where it was imported but never used, fixing F401 lint errors that blocked CI. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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
JsonAPIResponsebase class atsrc/fastapi_startkit/jsonapi/response.pyfor building JSON:API-compliant single-resource responsesJsonAPIListResponsefor collection endpoints (datais a list)serialize(include=[...])for sideloading related resources intoincluded[], with deduplication and dot-notation for nested includesto_attributes(),to_relationships(),to_links(),to_meta()JsonAPIResponseandJsonAPIListResponsefromsrc/fastapi_startkit/jsonapi/__init__.pydictsafe to return directly from any FastAPI endpointTest plan
fastapi_startkit/tests/jsonapi/test_response.py— envelope structure, attributes, relationships, links, meta, include=test_list_response.py— list data shape, deduplication, links/meta overridetest_include.py— include= query param simulation, multi-rel, dedup, relationship linkageuv run pytest tests/ --ignore=tests/masoniteorm -v🤖 Generated with Claude Code