-
-
Notifications
You must be signed in to change notification settings - Fork 6
Description
Hi there
Thanks for all the work on this package I really like it over alternatives like Django-Ninja or FastApi
I followed a PR
#25
and I saw this post

I really want to structure my "URL Handler" files like this
ViewHandlerToGetMyBook.py
from django.urls import path
from djapy import Schema
from djapy import djapify
class GetMyBookInput(Schema):
id: str
class GetMyBookOutput(Schema):
id: str
title: str
yearPublished: int
def GetMyBookHandler(request, data: GetMyBookInput) -> GetMyBookOutput:
"""
returns a specific book
"""
result = GetMyBookOutput(
id=data.id,
title="MyFirstBook",
yearPublished=2025,
)
return result
GetAllBooksUrlPath = path(
"getMyBook",
GetMyBookHandler,
"get-my-book",
)
i.e. every handler file has
- an
xyzInputSchemawhich subclassesSchema - an
xyzOutputSchemawhich subclassesSchema - an
xyzHandlerwhich does the logic and takes in the Input and returns the Output - a path where the url details are stored. This can then be placed in a DjangoApps/Projects url
I kow it isn't the standard way but I like it because everything to do with a url/handler is in one file and I can easily tweak an input schema if for instance i wanted to request via name and ID.
from the picture I posted above it would seem like this is possible
however when I do this in vscode I get redlines/the following errors
when I hover over path
No overloads for "path" match the provided argumentsPylance
when I hover over the function
No overloads for "path" match the provided argumentsPylance[reportCallIssue](https://github.com/microsoft/pylance-release/blob/main/docs/diagnostics/reportCallIssue.md)
conf.pyi(36, 5): Overload 4 is the closest match
Argument of type "(request: Unknown, data: GetMyBookInput) -> GetMyBookOutput" cannot be assigned to parameter "view" of type "tuple[list[URLResolver | URLPattern], str, str]" in function "path"
"FunctionType" is not assignable to "tuple[list[URLResolver | URLPattern], str, str]"Pylance[reportArgumentType](https://github.com/microsoft/pylance-release/blob/main/docs/diagnostics/reportArgumentType.md)
(even if these are just type errors that would be ignored by the intepreter, I still think we probably wouldn't want it to highlight red)
Do you know where I could be going wrong?