55
66from stapi_fastapi .backends .root_backend import RootBackend
77from stapi_fastapi .constants import TYPE_GEOJSON , TYPE_JSON
8+ from stapi_fastapi .models .conformance import CORE , Conformance
89from stapi_fastapi .models .order import Order , OrderCollection
910from stapi_fastapi .models .product import Product , ProductsCollection
1011from stapi_fastapi .models .root import RootResponse
@@ -17,15 +18,17 @@ class RootRouter(APIRouter):
1718 def __init__ (
1819 self ,
1920 backend : RootBackend ,
21+ conformances : list [str ] = [CORE ],
2022 name : str = "root" ,
21- openapi_endpoint_name = "openapi" ,
22- docs_endpoint_name = "swagger_ui_html" ,
23+ openapi_endpoint_name : str = "openapi" ,
24+ docs_endpoint_name : str = "swagger_ui_html" ,
2325 * args ,
2426 ** kwargs ,
2527 ) -> None :
2628 super ().__init__ (* args , ** kwargs )
2729 self .backend = backend
2830 self .name = name
31+ self .conformances = conformances
2932 self .openapi_endpoint_name = openapi_endpoint_name
3033 self .docs_endpoint_name = docs_endpoint_name
3134
@@ -43,6 +46,14 @@ def __init__(
4346 tags = ["Root" ],
4447 )
4548
49+ self .add_api_route (
50+ "/conformance" ,
51+ self .get_conformance ,
52+ methods = ["GET" ],
53+ name = f"{ self .name } :conformance" ,
54+ tags = ["Conformance" ],
55+ )
56+
4657 self .add_api_route (
4758 "/products" ,
4859 self .get_products ,
@@ -71,12 +82,19 @@ def __init__(
7182
7283 def get_root (self , request : Request ) -> RootResponse :
7384 return RootResponse (
85+ id = "STAPI API" ,
86+ conformsTo = self .conformances ,
7487 links = [
7588 Link (
7689 href = str (request .url_for (f"{ self .name } :root" )),
7790 rel = "self" ,
7891 type = TYPE_JSON ,
7992 ),
93+ Link (
94+ href = str (request .url_for (f"{ self .name } :conformance" )),
95+ rel = "conformance" ,
96+ type = TYPE_JSON ,
97+ ),
8098 Link (
8199 href = str (request .url_for (f"{ self .name } :list-products" )),
82100 rel = "products" ,
@@ -97,9 +115,12 @@ def get_root(self, request: Request) -> RootResponse:
97115 rel = "service-docs" ,
98116 type = "text/html" ,
99117 ),
100- ]
118+ ],
101119 )
102120
121+ def get_conformance (self , request : Request ) -> Conformance :
122+ return Conformance (conforms_to = self .conformances )
123+
103124 def get_products (self , request : Request ) -> ProductsCollection :
104125 return ProductsCollection (
105126 products = [pr .get_product (request ) for pr in self .product_routers .values ()],
0 commit comments