Skip to content

Data

openapi_first.templates.model_app.data

In-memory data store using Pydantic models.

This module is NOT thread-safe and is intended for demos and scaffolds only. This module provides a minimal, process-local data store for the model-based CRUD example application. It stores and returns domain objects defined using Pydantic models and is intended solely for demonstration and scaffolding purposes.

The implementation intentionally avoids: - persistence - concurrency guarantees - transactional semantics - validation beyond what Pydantic provides

It is not part of the openapi_first library API surface.

Functions

create_item

create_item(payload: ItemCreate) -> Item

Create a new item in the data store.

A new identifier is assigned automatically. No additional validation is performed beyond Pydantic model validation.

Parameters

payload : ItemCreate Data required to create a new item.

Returns

Item The newly created item.

delete_item

delete_item(item_id: int) -> None

Remove an item from the data store.

Parameters

item_id : int Identifier of the item to delete.

Raises

KeyError If the item does not exist.

get_item

get_item(item_id: int) -> Item

Retrieve a single item by ID.

Parameters

item_id : int Identifier of the item to retrieve.

Returns

Item The requested item.

Raises

KeyError If the item does not exist.

list_items

list_items() -> list[Item]

Return all items in the data store.

Returns

list[Item] A list of item domain objects.

update_item

update_item(item_id: int, payload: ItemCreate) -> Item

Replace an existing item in the data store.

This function performs a full replacement of the stored item. Partial updates are not supported.

Parameters

item_id : int Identifier of the item to update. payload : ItemCreate New item data.

Returns

Item The updated item.

Raises

KeyError If the item does not exist.