Skip to content

Commit

Permalink
Remove rpc prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
Cito committed Aug 1, 2024
1 parent b6f0bbb commit 466b846
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 36 deletions.
10 changes: 7 additions & 3 deletions .readme_generation/description.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
The Metadata Artifact Search Service uses search parameters to look for metadata.

### Quick Overview of API
There are two available API endpoints that follow the RPC pattern (not REST):
One endpoint ("GET /rpc/search-options") will return an overview of all metadata classes that can be targeted
by a search. The actual search endpoint ("POST /rpc/search") can be used to search for these target classes using keywords. Hits will be reported in the context of the selected target class.
The API provides two not strictly RESTful endpoints:

One endpoint ("GET /search-options") will return an overview of all metadata classes
that can be targeted by a search.

The actual search endpoint ("GET /search") can be used to search for these target classes
using keywords. Hits will be reported in the context of the selected target class.
This means that target classes will be reported that match the specified search query,
however, the target class might contain embedded other classes and the match might
occur in these embedded classes, too.
Expand Down
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ Metadata Artifact Search Service - A service for searching metadata artifacts a
The Metadata Artifact Search Service uses search parameters to look for metadata.

### Quick Overview of API
There are two available API endpoints that follow the RPC pattern (not REST):
One endpoint ("GET /rpc/search-options") will return an overview of all metadata classes that can be targeted
by a search. The actual search endpoint ("POST /rpc/search") can be used to search for these target classes using keywords. Hits will be reported in the context of the selected target class.
The API provides two not strictly RESTful endpoints:

One endpoint ("GET /search-options") will return an overview of all metadata classes
that can be targeted by a search.

The actual search endpoint ("GET /search") can be used to search for these target classes
using keywords. Hits will be reported in the context of the selected target class.
This means that target classes will be reported that match the specified search query,
however, the target class might contain embedded other classes and the match might
occur in these embedded classes, too.
Expand Down
29 changes: 16 additions & 13 deletions openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,10 @@ paths:
schema: {}
description: Successful Response
summary: health
/rpc/search:
/search:
get:
description: Perform search query
operationId: search_rpc_search_get
operationId: search_search_get
parameters:
- description: The class name to search
in: query
Expand Down Expand Up @@ -293,31 +293,34 @@ paths:
$ref: '#/components/schemas/HTTPValidationError'
description: Validation Error
summary: Perform a search using query string and filter parameters
/rpc/search-options:
/search-options:
get:
description: 'Returns the configured searchable classes. This describes which
resource classes
description: 'Return the configured searchable classes.
are accounted for in the system, as well as their facetable and selected fields.
The returned object describes which resource classes are accounted for in
the system,
as well as their facetable and selected fields.
The facetable fields represent specific data fields that will be aggregated
alongside
alongside the search hits for further search refinement. The selected fields
are
the search hits for further search refinement.
those that will appear in the search results. They contain a key, which is
used by
The selected fields are those that will appear in the search results.
the system, and a name, which is more user-friendly.'
operationId: search_options_rpc_search_options_get
They contain a key, which is used by the system, and a name, which is more
user-friendly.'
operationId: search_options_search_options_get
responses:
'200':
content:
application/json:
schema:
additionalProperties:
$ref: '#/components/schemas/SearchableClass'
title: Response Search Options Rpc Search Options Get
title: Response Search Options Search Options Get
type: object
description: Successful Response
summary: Retrieve all configured resource classes with their facetable and selected
Expand Down
20 changes: 11 additions & 9 deletions src/mass/adapters/inbound/fastapi_/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,27 @@ async def health():


@router.get(
path="/rpc/search-options",
path="/search-options",
summary="Retrieve all configured resource classes with their facetable and selected fields",
response_model=dict[str, models.SearchableClass],
)
async def search_options(
config: ConfigDummy,
) -> dict[str, models.SearchableClass]:
"""Returns the configured searchable classes. This describes which resource classes
are accounted for in the system, as well as their facetable and selected fields.
The facetable fields represent specific data fields that will be aggregated
alongside the search hits for further search refinement. The selected fields are
those that will appear in the search results. They contain a key, which is used by
the system, and a name, which is more user-friendly.
"""Return the configured searchable classes.
The returned object describes which resource classes are accounted for in the system,
as well as their facetable and selected fields.
The facetable fields represent specific data fields that will be aggregated alongside
the search hits for further search refinement.
The selected fields are those that will appear in the search results.
They contain a key, which is used by the system, and a name, which is more user-friendly.
"""
return config.searchable_classes


@router.get(
path="/rpc/search",
path="/search",
summary="Perform a search using query string and filter parameters",
response_model=models.QueryResults,
)
Expand Down Expand Up @@ -122,7 +124,7 @@ async def search( # noqa: PLR0913
raise HTTPException(
status_code=422,
detail="The specified class name is invalid."
+ " See /rpc/search-options for a list of valid class names.",
+ " See /search-options for a list of valid class names.",
) from err
except (query_handler.SearchError, query_handler.ValidationError) as err:
raise HTTPException(
Expand Down
4 changes: 2 additions & 2 deletions tests/fixtures/joint.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ async def load_test_data(self) -> None:
)

async def call_search_endpoint(self, params: QueryParams) -> models.QueryResults:
"""Convenience function to call the /rpc/search endpoint"""
response = await self.rest_client.get(url="/rpc/search", params=params)
"""Convenience function to call the /search endpoint"""
response = await self.rest_client.get(url="/search", params=params)
response.raise_for_status()
return models.QueryResults(**response.json())

Expand Down
2 changes: 1 addition & 1 deletion tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ async def test_health_check(joint_fixture: JointFixture):

async def test_search_options(joint_fixture: JointFixture):
"""Verify that we can request the configured resource class information correctly"""
response = await joint_fixture.rest_client.get(url="/rpc/search-options")
response = await joint_fixture.rest_client.get(url="/search-options")

assert response.json() == joint_fixture.config.model_dump()["searchable_classes"]

Expand Down
10 changes: 5 additions & 5 deletions tests/test_sorting.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ async def test_sort_with_invalid_sort_order(joint_fixture: JointFixture, order):
"sort": [order],
}

response = await joint_fixture.rest_client.get(url="/rpc/search", params=params)
response = await joint_fixture.rest_client.get(url="/search", params=params)
assert response.status_code == 422
detail = response.json()["detail"]
assert "Input should be 'ascending', 'descending' or 'relevance'" in str(detail)
Expand All @@ -166,7 +166,7 @@ async def test_sort_with_invalid_field_and_sort_order(joint_fixture: JointFixtur
"sort": ["also_bogus"],
}

response = await joint_fixture.rest_client.get(url="/rpc/search", params=params)
response = await joint_fixture.rest_client.get(url="/search", params=params)
assert response.status_code == 422


Expand All @@ -182,7 +182,7 @@ async def test_sort_with_duplicate_field(joint_fixture: JointFixture):
"sort": [models.SortOrder.ASCENDING.value, models.SortOrder.DESCENDING.value],
}

response = await joint_fixture.rest_client.get(url="/rpc/search", params=params)
response = await joint_fixture.rest_client.get(url="/search", params=params)
assert response.status_code == 422
assert response.json()["detail"] == "Fields to order by must be unique"

Expand All @@ -198,7 +198,7 @@ async def test_sort_with_missing_sort(joint_fixture: JointFixture):
"order_by": ["field"],
}

response = await joint_fixture.rest_client.get(url="/rpc/search", params=params)
response = await joint_fixture.rest_client.get(url="/search", params=params)
assert response.status_code == 422
details = response.json()["detail"]
assert details == "Number of fields to order by must match number of sort options"
Expand All @@ -216,7 +216,7 @@ async def test_sort_with_superfluous_sort(joint_fixture: JointFixture):
"sort": [models.SortOrder.ASCENDING.value, models.SortOrder.DESCENDING.value],
}

response = await joint_fixture.rest_client.get(url="/rpc/search", params=params)
response = await joint_fixture.rest_client.get(url="/search", params=params)
assert response.status_code == 422
details = response.json()["detail"]
assert details == "Number of fields to order by must match number of sort options"

0 comments on commit 466b846

Please sign in to comment.