parameters.py 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. from drf_spectacular.plumbing import build_array_type, build_basic_type
  2. from drf_spectacular.types import OpenApiTypes
  3. from drf_spectacular.utils import OpenApiParameter, inline_serializer
  4. from rest_framework import serializers
  5. # NOTE: Please add new params by path vs query, then in alphabetical order
  6. # drf-spectacular doesn't support a list type in it's OpenApiTypes, so we manually build
  7. # a typed list using this workaround
  8. def build_typed_list(type: OpenApiTypes):
  9. return build_array_type(build_basic_type(type))
  10. class GlobalParams:
  11. ORG_SLUG = OpenApiParameter(
  12. name="organization_slug",
  13. description="The slug of the organization the resource belongs to.",
  14. required=True,
  15. type=str,
  16. location="path",
  17. )
  18. PROJECT_SLUG = OpenApiParameter(
  19. name="project_slug",
  20. description="The slug of the project the resource belongs to.",
  21. required=True,
  22. type=str,
  23. location="path",
  24. )
  25. TEAM_SLUG = OpenApiParameter(
  26. name="team_slug",
  27. description="The slug of the team the resource belongs to.",
  28. required=True,
  29. type=str,
  30. location="path",
  31. )
  32. STATS_PERIOD = OpenApiParameter(
  33. name="statsPeriod",
  34. location="query",
  35. required=False,
  36. type=str,
  37. description="""The period of time for the query, will override the start & end parameters, a number followed by one of:
  38. - `d` for days
  39. - `h` for hours
  40. - `m` for minutes
  41. - `s` for seconds
  42. - `w` for weeks
  43. For example `24h`, to mean query data starting from 24 hours ago to now.""",
  44. )
  45. START = OpenApiParameter(
  46. name="start",
  47. location="query",
  48. required=False,
  49. type=OpenApiTypes.DATETIME,
  50. description="The start of the period of time for the query, expected in ISO-8601 format. For example `2001-12-14T12:34:56.7890`.",
  51. )
  52. END = OpenApiParameter(
  53. name="end",
  54. location="query",
  55. required=False,
  56. type=OpenApiTypes.DATETIME,
  57. description="The end of the period of time for the query, expected in ISO-8601 format. For example `2001-12-14T12:34:56.7890`.",
  58. )
  59. PROJECT = OpenApiParameter(
  60. name="project",
  61. location="query",
  62. required=False,
  63. many=True,
  64. type=int,
  65. description="The ids of projects to filter by. `-1` means all available projects. If this parameter is omitted, the request will default to using 'My Projects'.",
  66. )
  67. ENVIRONMENT = OpenApiParameter(
  68. name="environment",
  69. location="query",
  70. required=False,
  71. many=True,
  72. type=str,
  73. description="The name of environments to filter by.",
  74. )
  75. @staticmethod
  76. def name(description: str, required: bool = False) -> OpenApiParameter:
  77. return OpenApiParameter(
  78. name="name",
  79. location="query",
  80. required=required,
  81. type=str,
  82. description=description,
  83. )
  84. @staticmethod
  85. def slug(description: str, required: bool = False) -> OpenApiParameter:
  86. return OpenApiParameter(
  87. name="slug",
  88. location="query",
  89. required=required,
  90. type=str,
  91. description=description,
  92. )
  93. class SCIMParams:
  94. MEMBER_ID = OpenApiParameter(
  95. name="member_id",
  96. location="path",
  97. required=True,
  98. type=int,
  99. description="The id of the member you'd like to query.",
  100. )
  101. TEAM_ID = OpenApiParameter(
  102. name="team_id",
  103. location="path",
  104. required=True,
  105. type=int,
  106. description="The id of the team you'd like to query / update.",
  107. )
  108. class IssueAlertParams:
  109. ISSUE_RULE_ID = OpenApiParameter(
  110. name="rule_id",
  111. location="path",
  112. required=True,
  113. type=int,
  114. description="The id of the rule you'd like to query.",
  115. )
  116. class VisibilityParams:
  117. QUERY = OpenApiParameter(
  118. name="query",
  119. location="query",
  120. required=False,
  121. type=str,
  122. description="""The search filter for your query, read more about query syntax [here](https://docs.sentry.io/product/sentry-basics/search/).
  123. example: `query=(transaction:foo AND release:abc) OR (transaction:[bar,baz] AND release:def)`
  124. """,
  125. )
  126. FIELD = OpenApiParameter(
  127. name="field",
  128. location="query",
  129. required=True,
  130. type=str,
  131. many=True,
  132. description="""The fields, functions, or equations to request for the query. At most 20 fields can be selected per request. Each field can be one of the following types:
  133. - A built-in key field. See possible fields in the [properties table](/product/sentry-basics/search/searchable-properties/#properties-table), under any field that is an event property.
  134. - example: `field=transaction`
  135. - A tag. Tags should use the `tag[]` formatting to avoid ambiguity with any fields
  136. - example: `field=tag[isEnterprise]`
  137. - A function which will be in the format of `function_name(parameters,...)`. See possible functions in the [query builder documentation](/product/discover-queries/query-builder/#stacking-functions).
  138. - when a function is included, Discover will group by any tags or fields
  139. - example: `field=count_if(transaction.duration,greater,300)`
  140. - An equation when prefixed with `equation|`. Read more about [equations here](https://docs.sentry.io/product/discover-queries/query-builder/query-equations/).
  141. - example: `field=equation|count_if(transaction.duration,greater,300) / count() * 100`
  142. """,
  143. )
  144. SORT = OpenApiParameter(
  145. name="sort",
  146. location="query",
  147. required=False,
  148. type=str,
  149. description="What to order the results of the query by. Must be something in the `field` list, excluding equations.",
  150. )
  151. PER_PAGE = OpenApiParameter(
  152. name="per_page",
  153. location="query",
  154. required=False,
  155. type=int,
  156. description="Limit the number of rows to return in the result. Default and maximum allowed is 100.",
  157. )
  158. class CursorQueryParam(serializers.Serializer):
  159. cursor = serializers.CharField(
  160. help_text="A pointer to the last object fetched and its sort order; used to retrieve the next or previous results.",
  161. required=False,
  162. )
  163. class MonitorParams:
  164. MONITOR_SLUG = OpenApiParameter(
  165. name="monitor_slug",
  166. location="path",
  167. required=True,
  168. type=str,
  169. description="The slug of the monitor.",
  170. )
  171. CHECKIN_ID = OpenApiParameter(
  172. name="checkin_id",
  173. location="path",
  174. required=True,
  175. type=OpenApiTypes.UUID,
  176. description="The id of the check-in.",
  177. )
  178. class EventParams:
  179. EVENT_ID = OpenApiParameter(
  180. name="event_id",
  181. location="path",
  182. required=True,
  183. type=OpenApiTypes.UUID,
  184. description="The id of the event.",
  185. )
  186. FRAME_IDX = OpenApiParameter(
  187. name="frame_idx",
  188. location="query",
  189. required=True, # TODO: make not required
  190. type=int,
  191. description="Index of the frame that should be used for source map resolution.",
  192. )
  193. EXCEPTION_IDX = OpenApiParameter(
  194. name="exception_idx",
  195. location="query",
  196. required=True,
  197. type=int,
  198. description="Index of the exception that should be used for source map resolution.",
  199. )
  200. class ProjectParams:
  201. FILTER_ID = OpenApiParameter(
  202. name="filter_id",
  203. location="path",
  204. required=True,
  205. type=str,
  206. description="""The type of filter toggle to update. The options are:
  207. - `browser-extensions`: Filter out errors known to be caused by browser extensions.
  208. - `localhost`: Filter out events coming from localhost. This applies to both IPv4 (``127.0.0.1``)
  209. and IPv6 (``::1``) addresses.
  210. - `web-crawlers`: Filter out known web crawlers. Some crawlers may execute pages in incompatible
  211. ways which then cause errors that are unlikely to be seen by a normal user.
  212. - `legacy-browser`: Filter out known errors from legacy browsers. Older browsers often give less
  213. accurate information, and while they may report valid issues, the context to understand them is
  214. incorrect or missing.
  215. - `filtered-transaction`: Filter out transactions for healthcheck and ping endpoints.
  216. """,
  217. )
  218. ACTIVE = OpenApiParameter(
  219. name="active",
  220. location="query",
  221. required=False,
  222. type=bool,
  223. description="Toggle the browser-extensions, localhost, web-crawlers, or filtered-transaction filter on or off.",
  224. )
  225. BROWSER_SDK_VERSION = OpenApiParameter(
  226. name="browserSdkVersion",
  227. location="query",
  228. required=False,
  229. type=str,
  230. description="""
  231. The Sentry Javascript SDK version to use. The currently supported options are:
  232. - `7.x`
  233. - `latest`
  234. """,
  235. )
  236. DEFAULT_RULES = OpenApiParameter(
  237. name="default_rules",
  238. location="query",
  239. required=False,
  240. type=bool,
  241. description="Defaults to true where the behavior is to alert the user on every new issue. Setting this to false will turn this off and the user must create their own alerts to be notified of new issues.",
  242. )
  243. DYNAMIC_SDK_LOADER_OPTIONS = OpenApiParameter(
  244. name="dynamicSdkLoaderOptions",
  245. location="query",
  246. required=False,
  247. type=inline_serializer(
  248. name="DynamicSDKLoaderOptionsSerializer",
  249. fields={
  250. "hasReplay": serializers.BooleanField(required=False),
  251. "hasPerformance": serializers.BooleanField(required=False),
  252. "hasDebug": serializers.BooleanField(required=False),
  253. },
  254. ),
  255. description="""
  256. Configures multiple options for the Javascript Loader Script.
  257. - `Performance Monitoring`
  258. - `Debug Bundles & Logging`
  259. - `Session Replay`: Note that the loader will load the ES6 bundle instead of the ES5 bundle.
  260. ```json
  261. {
  262. "dynamicSdkLoaderOptions": {
  263. "hasReplay": true,
  264. "hasPerformance": true,
  265. "hasDebug": true
  266. }
  267. }
  268. ```
  269. """,
  270. )
  271. IS_ACTIVE = OpenApiParameter(
  272. name="isActive",
  273. location="query",
  274. required=False,
  275. type=bool,
  276. description="Activate or deactivate the client key.",
  277. )
  278. RATE_LIMIT = OpenApiParameter(
  279. name="rateLimit",
  280. location="query",
  281. required=False,
  282. type=inline_serializer(
  283. name="RateLimitParameterSerializer",
  284. fields={
  285. "window": serializers.IntegerField(required=False),
  286. "count": serializers.IntegerField(required=False),
  287. },
  288. ),
  289. description="""
  290. Applies a rate limit to cap the number of errors accepted during a given time window. To
  291. disable entirely set `rateLimit` to null.
  292. ```json
  293. {
  294. "rateLimit": {
  295. "window": 7200, // time in seconds
  296. "count": 1000 // error cap
  297. }
  298. }
  299. ```
  300. """,
  301. )
  302. SUB_FILTERS = OpenApiParameter(
  303. name="subfilters",
  304. location="query",
  305. required=False,
  306. type=build_typed_list(OpenApiTypes.STR),
  307. description="""
  308. A list specifying which legacy browser filters should be active. Anything excluded from the list
  309. will be turned off. The options are:
  310. - `ie_pre_9`: Internet Explorer Version 8 and lower
  311. - `ie9`: Internet Explorer Version 9
  312. - `ie10`: Internet Explorer Version 10
  313. - `ie11`: Internet Explorer Version 11
  314. - `safari_pre_6`: Safari Version 5 and lower
  315. - `opera_pre_15`: Opera Version 14 and lower
  316. - `opera_mini_pre_8`: Opera Mini Version 8 and lower
  317. - `android_pre_4`: Android Version 3 and lower
  318. """,
  319. )
  320. @staticmethod
  321. def key_id(description: str) -> OpenApiParameter:
  322. return OpenApiParameter(
  323. name="key_id",
  324. location="path",
  325. required=True,
  326. type=str,
  327. description=description,
  328. )
  329. @staticmethod
  330. def platform(description: str) -> OpenApiParameter:
  331. return OpenApiParameter(
  332. name="platform",
  333. location="query",
  334. required=False,
  335. type=str,
  336. description=description,
  337. )
  338. class TeamParams:
  339. DETAILED = OpenApiParameter(
  340. name="detailed",
  341. location="query",
  342. required=False,
  343. type=str,
  344. description="""
  345. Specify `"0"` to return team details that do not include projects.
  346. """,
  347. )