Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ repos:
- id: trailing-whitespace
- id: requirements-txt-fixer
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.13.2
rev: v0.14.5
hooks:
- id: ruff
args:
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "jetpack"
version = "0.2.0"
version = "0.2.1"
description = "Project Utilities to kickstart a micro-service."
readme = "README.md"
authors = [
Expand All @@ -10,6 +10,7 @@ authors = [
requires-python = ">=3.13"
dependencies = [
"asgi-correlation-id>=4.3.4",
"orjson>=3.11.4",
"pydantic>=2.10.3",
"pydantic-settings>=2.7.0",
"whenever>=0.6.15",
Expand Down
Empty file added src/jetpack/utils/__init__.py
Empty file.
30 changes: 30 additions & 0 deletions src/jetpack/utils/parse_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from typing import Annotated, Any, Callable

from fastapi.params import Query
import orjson


class _ParamsDecoder:
def __call__(
self,
model: Callable = dict,
description: str = "Stringified JSON",
default: Any = None,
) -> Callable:
json_schema_extra = {} if model == dict else model.model_json_schema() # noqa

def param_decoder(
params: Annotated[
str, Query(json_schema_extra=json_schema_extra, description=description)
] = default,
) -> Any:
if not params:
return default
return model(**orjson.loads(params.strip("'\\").encode()))

return param_decoder


ParamsDecoder = _ParamsDecoder()

__all__ = ["ParamsDecoder"]
Loading
Loading