Skip to content

[BUG] - API Endpoints Don't Return Response Models #32

@zdomke

Description

@zdomke

Describe the bug

Majority, if not all, of our api endpoints for the backend (app/api/v1/*.py) do not make use of our Pydantic models for responses (app/schemas/*.py). Instead, they are described as returning a dict. While this works and it isn't inaccurate, we do have the ability to be more specific.

On major benefit we get from using our Pydantic models (that we already have made) is the documentation. FastAPI autogenerates docs for us using OpenAPI and Swagger. These tools use the type-hinted return type to populate the documentation with decent examples of responses for each endpoint.

Expected behavior

We should always be returning a Pydantic model. The only possible exemption would be if we are returning very primitive data.

For example, endpoints that return a count may want to list their return type as ints instead of wrapping it in a response model.
Or maybe not, idk.

Steps to Reproduce

  1. Start up the backend using docker
  2. Navigate to the docs pages
    a. OpenAPI: http://localhost:8080/docs/
    b. Swagger: http://localhost:8080/redoc/
  3. Find an endpoint and read the documentation on it
  4. Notice that the "Response" section does not give a detailed example

Possible solution (optional)

Replace the return type for our endpoints with the response models defined in app/schemas/*.py.

If you don't have a response model, one will be provided for you (or you gotta make them, I don't make the rules ¯\_(ツ)_/¯ ).

My platform

No response

Additional context

Method returns dict

Image

Method returns Pydantic Model

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions