Skip to content

Release Notes

v2.31.0 Latest

May 15, 2026

โœจ New Features

๐Ÿ”€ Per-Operation Response Schemas (schema_create_out, schema_update_out, schema_delete_out)

ninja_aio/views/api.py

Three new APIViewSet class attributes allow developers to configure a distinct response schema for each mutating CRUD endpoint, independently of the global schema_out.

Attribute Endpoint Default
schema_create_out POST / (201) Falls back to schema_out
schema_update_out PATCH /{pk}/ (200) Falls back to schema_out
schema_delete_out DELETE /{pk}/ None โ†’ 204 No Content

Lightweight create/update responses:

class ArticleCreatedOut(Schema):
    id: int
    title: str          # Only return what matters on create

class ArticleUpdatedOut(Schema):
    id: int
    updated_at: str     # Return the updated timestamp on PATCH

@api.viewset(model=Article)
class ArticleViewSet(APIViewSet):
    schema_in = ArticleIn
    schema_out = ArticleFullOut
    schema_create_out = ArticleCreatedOut   # POST  โ†’ 201 with minimal shape
    schema_update_out = ArticleUpdatedOut   # PATCH โ†’ 200 with update-specific shape
    # schema_delete_out not set โ†’ DELETE stays 204 No Content

Delete that returns the deleted object:

class ArticleDeletedOut(Schema):
    id: int
    title: str

@api.viewset(model=Article)
class ArticleViewSet(APIViewSet):
    schema_delete_out = ArticleDeletedOut   # DELETE โ†’ 200 with deleted object

When schema_delete_out is set, the delete endpoint fetches and serializes the object before deleting it, then returns 200 with the serialized data. If not set, behaviour is unchanged (204 No Content).

All three attributes are fully backwards compatible โ€” existing ViewSets without them behave exactly as before.


๐Ÿ“š Documentation

  • docs/api/views/api_view_set.md โ€” updated endpoints table, core attributes table, schema generation section, and new Per-Operation Response Schemas subsection with annotated examples
  • docs/tutorial/crud.md โ€” updated endpoints table, learning objectives, and new Per-Operation Response Schemas tutorial section

๐ŸŽฏ Summary

v2.31.0 introduces fine-grained control over CRUD response shapes. Previously all mutating endpoints (POST, PATCH, DELETE) shared schema_out for their response. With this release each operation can define its own output schema, enabling cleaner API contracts and more intentional response payloads.

Key benefits:
- ๐Ÿ”€ Return a different shape on create vs update vs list without changing schema_out
- ๐Ÿ—‘๏ธ Optionally return the deleted object from DELETE with a 200 response
- โœ… Fully backwards compatible โ€” omitting the new attributes preserves existing behaviour
- ๐Ÿ“– Full OpenAPI docs reflect the per-operation schemas automatically