Skip to content

Commit 8dd2134

Browse files
authored
quality(apidocs): document shortid lookup using drf spectacular (#94962)
Part of https://www.notion.so/sentry/Remove-legacy-API-docs-JSON-21d8b10e4b5d80958c87ee7d603853ff?source=copy_link (reverted because of a small typing issue found during the PR, fixed here #94829) Note that we update the type of `count` in the group serializer, as it is currently wrong (we return a string, for whatever reason lol).
1 parent c8d63df commit 8dd2134

File tree

7 files changed

+151
-320
lines changed

7 files changed

+151
-320
lines changed

api-docs/openapi.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,6 @@
100100
"/api/0/organizations/{organization_id_or_slug}/repos/{repo_id}/commits/": {
101101
"$ref": "paths/organizations/repo-commits.json"
102102
},
103-
"/api/0/organizations/{organization_id_or_slug}/shortids/{issue_id}/": {
104-
"$ref": "paths/organizations/shortid.json"
105-
},
106103
"/api/0/projects/": {
107104
"$ref": "paths/projects/index.json"
108105
},

api-docs/paths/organizations/shortid.json

Lines changed: 0 additions & 273 deletions
This file was deleted.

src/sentry/api/serializers/models/group.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,10 @@ class GroupProjectResponse(TypedDict):
106106

107107
class BaseGroupResponseOptional(TypedDict, total=False):
108108
isUnhandled: bool
109-
count: int
109+
count: str
110110
userCount: int
111-
firstSeen: datetime
112-
lastSeen: datetime
111+
firstSeen: datetime | None
112+
lastSeen: datetime | None
113113

114114

115115
class BaseGroupSerializerResponse(BaseGroupResponseOptional):
@@ -151,6 +151,13 @@ class SeenStats(TypedDict):
151151
user_count: int
152152

153153

154+
class SeenStatsResponse(TypedDict):
155+
count: str
156+
userCount: int
157+
firstSeen: datetime | None
158+
lastSeen: datetime | None
159+
160+
154161
def is_seen_stats(o: object) -> TypeGuard[SeenStats]:
155162
# not a perfect check, but simulates what was being validated before
156163
return isinstance(o, dict) and "times_seen" in o
@@ -749,7 +756,7 @@ def _get_permalink(attrs, obj: Group):
749756
return None
750757

751758
@staticmethod
752-
def _convert_seen_stats(attrs: SeenStats):
759+
def _convert_seen_stats(attrs: SeenStats) -> SeenStatsResponse:
753760
return {
754761
"count": str(attrs["times_seen"]),
755762
"userCount": attrs["user_count"],

src/sentry/api/serializers/models/group_stream.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -294,10 +294,10 @@ class StreamGroupSerializerSnubaResponse(TypedDict):
294294
annotations: NotRequired[list[GroupAnnotation]]
295295
# from base response optional
296296
isUnhandled: NotRequired[bool]
297-
count: NotRequired[int]
297+
count: NotRequired[str]
298298
userCount: NotRequired[int]
299-
firstSeen: NotRequired[datetime]
300-
lastSeen: NotRequired[datetime]
299+
firstSeen: NotRequired[datetime | None]
300+
lastSeen: NotRequired[datetime | None]
301301

302302
# from the serializer itself
303303
stats: NotRequired[dict[str, Any]]
@@ -505,14 +505,26 @@ def serialize( # type: ignore[override] # intentionally different shape
505505
result["stats"] = {self.stats_period: attrs["stats"]}
506506

507507
if not self._collapse("lifetime"):
508-
result["lifetime"] = self._convert_seen_stats(attrs["lifetime"])
508+
seen_stats = self._convert_seen_stats(attrs["lifetime"])
509+
result["lifetime"] = {
510+
"count": seen_stats["count"],
511+
"userCount": seen_stats["userCount"],
512+
"firstSeen": seen_stats["firstSeen"],
513+
"lastSeen": seen_stats["lastSeen"],
514+
}
509515
if self.stats_period:
510516
# Not needed in current implementation
511517
result["lifetime"]["stats"] = None
512518

513519
if not self._collapse("filtered"):
514520
if self.conditions:
515-
filtered = self._convert_seen_stats(attrs["filtered"])
521+
seen_stats = self._convert_seen_stats(attrs["filtered"])
522+
filtered = {
523+
"count": seen_stats["count"],
524+
"userCount": seen_stats["userCount"],
525+
"firstSeen": seen_stats["firstSeen"],
526+
"lastSeen": seen_stats["lastSeen"],
527+
}
516528
if self.stats_period:
517529
filtered["stats"] = {self.stats_period: attrs["filtered_stats"]}
518530
result["filtered"] = filtered

src/sentry/apidocs/examples/issue_examples.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"experiments": {},
2626
"emails": [],
2727
},
28-
"count": 150,
28+
"count": "150",
2929
"culprit": "raven.scripts.runner in main",
3030
"firstSeen": datetime.fromisoformat("2018-11-06T21:19:55Z"),
3131
"filtered": None,
@@ -85,7 +85,7 @@
8585
},
8686
"platform": "python",
8787
"lifetime": {
88-
"count": 150,
88+
"count": "150",
8989
"userCount": 0,
9090
"firstSeen": datetime.fromisoformat("2018-11-06T21:19:55Z"),
9191
"lastSeen": datetime.fromisoformat("2018-12-06T21:19:55Z"),

0 commit comments

Comments
 (0)