Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VertexModel incompatibility with FastAPI's endpoint function definitions #17

Open
eHorn96 opened this issue Oct 8, 2024 · 3 comments
Open

Comments

@eHorn96
Copy link

eHorn96 commented Oct 8, 2024

Hi there,

Thanks for the library, first and foremost. It makes developing the business logic with ArangoDB easy af.

An issue I encountered is the incompatibility with FastAPI's endpoint function definitions.

async def create_process(
    current_user: Annotated[User, Depends(get_current_user)],
    process_data: Annotated[Process, Body(...)]): # This fails

Serializing to json just makes it look super ugly in swagger.

I forked your repo to help you on this tho. Surely there's a way to fix this.

Cheers!

Erik

@nadobando
Copy link
Owner

Hi Erik, thanks for your appreciation,
can you share the part of the swagger/openapi so I can reproduce it?

I'm creating another library FuriousAPI which is an extension for FastAPI
and there are submodules for working with:

  1. SQLModel FuriousAPI-SQLModel - ✅ done
  2. Beanie/mongo FuriousAPI-Beanie - ✅ done
  3. PydangORM - FuriousAPI-pydango - 🔁 need to create the implementation

Regards, @nadobando

@eHorn96
Copy link
Author

eHorn96 commented Oct 21, 2024

Hi @nadobando , I am currently a little busy right now, so I won't have time for the next few weeks I'm afraid. Sorry for the unclear description of the issue. Usually in FastAPI you can declare the class as-is in the signature and its model will be displayed in the Swagger docs. The Process class above has been declared as a subclass according to your documentation.

class Process(VertexModel):
    name: str | None = None
    process_type: str | None = None
    status: Literal["Waiting", "Running", "Done", "Failed"] | None = None
    uses: Annotated[list[NodeAttribute], Relation[Uses]] = "test"

    class Collection(VertexCollectionConfig):
        name = "process"
        indexes = [
            PersistentIndex(fields=["name"], unique=True),
        ] 

However I tried to make it work, it just didn't. Process.model_dump() won't work, and (sorry I worded it wrongly) Process.model_schema_json() resulted in the whole serialized JSON to be displayed in Swagger. Hope it helps.

Cheers!

@nadobando-vinesight
Copy link

@eHorn96 I will try to look at this, I want to start working on the upgrade of pydantic, which will also add circular graphs feature

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

No branches or pull requests

3 participants