Debian Codegraph @

docs/examples/parameters/path_parameters_3.py

raw
1 import dataclasses
2 from typing import Any, Dict
3
4 from typing_extensions import Annotated
5
6 from litestar import Litestar, get
7 from litestar.openapi.spec.example import Example
8 from litestar.openapi.spec.external_documentation import ExternalDocumentation
9 from litestar.params import PathParameter
10
11
12 @dataclasses.dataclass
13 class Version:
14 id: int
15 specs: Dict[str, Any]
16
17
18 VERSIONS = {1: Version(id=1, specs={"some": "value"})}
19
20
21 @get(path="/versions/{version:int}", sync_to_thread=False)
22 def get_product_version(
23 version: Annotated[
24 int,
25 PathParameter(
26 title="Available Product Versions",
27 description="Get a specific version spec from the available specs",
28 examples=[Example(value=1)],
29 external_docs=ExternalDocumentation(
30 url="https://mywebsite.com/documentation/product#versions", # type: ignore[arg-type]
31 ),
32 ),
33 ],
34 ) -> Version:
35 return VERSIONS[version]
36
37
38 app = Litestar(route_handlers=[get_product_version])