2828 GetOrders ,
2929 GetOrderStatuses ,
3030)
31- from stapi_fastapi .conformance import ASYNC_OPPORTUNITIES , CORE
31+ from stapi_fastapi .conformance import API as API_CONFORMANCE
3232from stapi_fastapi .constants import TYPE_GEOJSON , TYPE_JSON
3333from stapi_fastapi .errors import NotFoundError
3434from stapi_fastapi .models .product import Product
@@ -54,11 +54,11 @@ def __init__(
5454 self ,
5555 get_orders : GetOrders ,
5656 get_order : GetOrder ,
57- get_order_statuses : GetOrderStatuses , # type: ignore
57+ get_order_statuses : GetOrderStatuses | None = None , # type: ignore
5858 get_opportunity_search_records : GetOpportunitySearchRecords | None = None ,
5959 get_opportunity_search_record : GetOpportunitySearchRecord | None = None ,
6060 get_opportunity_search_record_statuses : GetOpportunitySearchRecordStatuses | None = None ,
61- conformances : list [str ] = [CORE ],
61+ conformances : list [str ] = [API_CONFORMANCE . core ],
6262 name : str = "root" ,
6363 openapi_endpoint_name : str = "openapi" ,
6464 docs_endpoint_name : str = "swagger_ui_html" ,
@@ -67,21 +67,14 @@ def __init__(
6767 ) -> None :
6868 super ().__init__ (* args , ** kwargs )
6969
70- if ASYNC_OPPORTUNITIES in conformances and (
71- not get_opportunity_search_records or not get_opportunity_search_record
72- ):
73- raise ValueError (
74- "`get_opportunity_search_records` and `get_opportunity_search_record` "
75- "are required when advertising async opportunity search conformance"
76- )
70+ _conformances = set (conformances )
7771
7872 self ._get_orders = get_orders
7973 self ._get_order = get_order
80- self ._get_order_statuses = get_order_statuses
74+ self .__get_order_statuses = get_order_statuses
8175 self .__get_opportunity_search_records = get_opportunity_search_records
8276 self .__get_opportunity_search_record = get_opportunity_search_record
8377 self .__get_opportunity_search_record_statuses = get_opportunity_search_record_statuses
84- self .conformances = conformances
8578 self .name = name
8679 self .openapi_endpoint_name = openapi_endpoint_name
8780 self .docs_endpoint_name = docs_endpoint_name
@@ -135,15 +128,18 @@ def __init__(
135128 tags = ["Orders" ],
136129 )
137130
138- self .add_api_route (
139- "/orders/{order_id}/statuses" ,
140- self .get_order_statuses ,
141- methods = ["GET" ],
142- name = f"{ self .name } :{ LIST_ORDER_STATUSES } " ,
143- tags = ["Orders" ],
144- )
131+ if self .get_order_statuses is not None :
132+ _conformances .add (API_CONFORMANCE .order_statuses )
133+ self .add_api_route (
134+ "/orders/{order_id}/statuses" ,
135+ self .get_order_statuses ,
136+ methods = ["GET" ],
137+ name = f"{ self .name } :{ LIST_ORDER_STATUSES } " ,
138+ tags = ["Orders" ],
139+ )
145140
146- if ASYNC_OPPORTUNITIES in conformances :
141+ if self .supports_async_opportunity_search :
142+ _conformances .add (API_CONFORMANCE .searches_opportunity )
147143 self .add_api_route (
148144 "/searches/opportunities" ,
149145 self .get_opportunity_search_records ,
@@ -162,6 +158,8 @@ def __init__(
162158 tags = ["Opportunities" ],
163159 )
164160
161+ if self .__get_opportunity_search_record_statuses is not None :
162+ _conformances .add (API_CONFORMANCE .searches_opportunity_statuses )
165163 self .add_api_route (
166164 "/searches/opportunities/{search_record_id}/statuses" ,
167165 self .get_opportunity_search_record_statuses ,
@@ -171,6 +169,8 @@ def __init__(
171169 tags = ["Opportunities" ],
172170 )
173171
172+ self .conformances = list (_conformances )
173+
174174 def get_root (self , request : Request ) -> RootResponse :
175175 links = [
176176 Link (
@@ -468,6 +468,12 @@ def opportunity_search_record_self_link(
468468 type = TYPE_JSON ,
469469 )
470470
471+ @property
472+ def _get_order_statuses (self ) -> GetOrderStatuses : # type: ignore
473+ if not self .__get_order_statuses :
474+ raise AttributeError ("Root router does not support order status history" )
475+ return self .__get_order_statuses
476+
471477 @property
472478 def _get_opportunity_search_records (self ) -> GetOpportunitySearchRecords :
473479 if not self .__get_opportunity_search_records :
@@ -483,13 +489,9 @@ def _get_opportunity_search_record(self) -> GetOpportunitySearchRecord:
483489 @property
484490 def _get_opportunity_search_record_statuses (self ) -> GetOpportunitySearchRecordStatuses :
485491 if not self .__get_opportunity_search_record_statuses :
486- raise AttributeError ("Root router does not support async opportunity search" )
492+ raise AttributeError ("Root router does not support async opportunity search status history " )
487493 return self .__get_opportunity_search_record_statuses
488494
489495 @property
490496 def supports_async_opportunity_search (self ) -> bool :
491- return (
492- ASYNC_OPPORTUNITIES in self .conformances
493- and self ._get_opportunity_search_records is not None
494- and self ._get_opportunity_search_record is not None
495- )
497+ return self .__get_opportunity_search_records is not None and self .__get_opportunity_search_record is not None
0 commit comments