Skip to content

feat(jsonapi): add JsonAPIResponse base class + JSON:API serialization#93

Merged
bedus-creation merged 4 commits into
mainfrom
task/feat-jsonapi-response
Jun 7, 2026
Merged

feat(jsonapi): add JsonAPIResponse base class + JSON:API serialization#93
bedus-creation merged 4 commits into
mainfrom
task/feat-jsonapi-response

Conversation

@bedus-creation

Copy link
Copy Markdown
Contributor

Summary

  • Adds JsonAPIResponse base class at src/fastapi_startkit/jsonapi/response.py for building JSON:API-compliant single-resource responses
  • Adds JsonAPIListResponse for collection endpoints (data is a list)
  • Supports serialize(include=[...]) for sideloading related resources into included[], with deduplication and dot-notation for nested includes
  • Overridable hooks: to_attributes(), to_relationships(), to_links(), to_meta()
  • Exports JsonAPIResponse and JsonAPIListResponse from src/fastapi_startkit/jsonapi/__init__.py
  • Returns a plain dict safe to return directly from any FastAPI endpoint

Test plan

  • 46 new tests under fastapi_startkit/tests/jsonapi/
    • test_response.py — envelope structure, attributes, relationships, links, meta, include=
    • test_list_response.py — list data shape, deduplication, links/meta override
    • test_include.py — include= query param simulation, multi-rel, dedup, relationship linkage
  • Full suite (484 tests) passes with zero regressions: uv run pytest tests/ --ignore=tests/masoniteorm -v

🤖 Generated with Claude Code

bedus-creation and others added 4 commits June 7, 2026 15:45
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>
@bedus-creation bedus-creation merged commit d04b20b into main Jun 7, 2026
3 checks passed
@bedus-creation bedus-creation deleted the task/feat-jsonapi-response branch June 8, 2026 07:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant