Skip to content

Commit

Permalink
Fixes the constraint spec for posting to the compare endpoint (#412)
Browse files Browse the repository at this point in the history
I used Query to add some constraints to the compare by post endpoint,
but that moved the subject & object lists to query string. Using a
pydantic class as the argument to the post solves this.
  • Loading branch information
kevinschaper authored Oct 17, 2023
1 parent 5e17ad8 commit 5ad7014
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
9 changes: 8 additions & 1 deletion backend/src/monarch_py/api/additional_models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from typing import List

from fastapi import Query, Request
from pydantic import BaseModel
from pydantic import BaseModel, Field


class PaginationParams(BaseModel):
Expand All @@ -9,3 +11,8 @@ class PaginationParams(BaseModel):

class Config:
arbitrary_types_allowed = True


class CompareRequest(BaseModel):
subjects: List[str] = Field(..., title="List of subjects for comparison")
objects: List[str] = Field(..., title="List of objects for comparison")
9 changes: 4 additions & 5 deletions backend/src/monarch_py/api/semsim.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from typing import List

from fastapi import APIRouter, Path, Query

from monarch_py.api.additional_models import CompareRequest
from monarch_py.api.config import oak

router = APIRouter(tags=["semsim"], responses={404: {"description": "Not Found"}})
Expand Down Expand Up @@ -35,10 +37,7 @@ def _compare(


@router.post("/compare")
def _post_compare(
subjects: List[str] = Query(...,title="List of subjects for comparison"),
objects: List[str] = Query(...,title="List of objects for comparison")
):
def _post_compare(request: CompareRequest):
"""
Pairwise similarity between two sets of terms <br>
<br>
Expand All @@ -50,4 +49,4 @@ def _post_compare(
}
</pre>
"""
return oak().compare(subjects, objects)
return oak().compare(request.subjects, request.objects)

0 comments on commit 5ad7014

Please sign in to comment.