Coverage for apps/kwai-api/src/kwai_api/v1/portal/news/schemas.py: 100%

15 statements  

« prev     ^ index     » next       coverage.py v7.11.0, created at 2024-01-01 00:00 +0000

1"""Module that defines schemas for the portal/news endpoint.""" 

2 

3from kwai_core.json_api import ( 

4 Meta, 

5 Relationship, 

6 ResourceMeta, 

7) 

8from pydantic import BaseModel, Field 

9 

10from kwai_api.schemas.resources import ( 

11 ApplicationResourceIdentifier, 

12 NewsItemResourceIdentifier, 

13) 

14 

15 

16class NewsApplicationAttributes(BaseModel): 

17 """Attributes of an application JSON:API resource of a news item.""" 

18 

19 name: str 

20 title: str 

21 

22 

23class NewsApplicationResource(ApplicationResourceIdentifier): 

24 """A JSON:API resource for an application of a news item.""" 

25 

26 attributes: NewsApplicationAttributes 

27 

28 

29class NewsItemText(BaseModel): 

30 """Schema for the text of a news item.""" 

31 

32 locale: str 

33 title: str 

34 summary: str 

35 content: str | None = None 

36 

37 

38class NewsItemAttributes(BaseModel): 

39 """Attributes of a news item JSON:API resource.""" 

40 

41 publish_date: str 

42 texts: list[NewsItemText] 

43 priority: int 

44 

45 

46class NewsItemRelationships(BaseModel): 

47 """Relationships of a news item JSON:API resource.""" 

48 

49 application: Relationship[ApplicationResourceIdentifier] 

50 

51 

52class NewsItemResource(NewsItemResourceIdentifier): 

53 """A JSON:API resource for a news item.""" 

54 

55 meta: ResourceMeta 

56 attributes: NewsItemAttributes 

57 relationships: NewsItemRelationships 

58 

59 

60class NewsItemDocument(BaseModel): 

61 """A document for one JSON:API news item resource.""" 

62 

63 data: NewsItemResource 

64 included: set[NewsApplicationResource] = Field(default_factory=set) 

65 

66 

67class NewsItemsDocument(BaseModel): 

68 """A document for multiple JSON:API news item resources.""" 

69 

70 meta: Meta 

71 data: list[NewsItemResource] = Field(default_factory=list) 

72 included: set[NewsApplicationResource] = Field(default_factory=set)