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

18 statements  

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

1"""Module for defining the page JSON:API resource.""" 

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 PageResourceIdentifier, 

13) 

14 

15 

16class PageApplicationAttributes(BaseModel): 

17 """Attributes of a page application JSON:API resource.""" 

18 

19 name: str 

20 title: str 

21 

22 

23class PageApplicationResource(ApplicationResourceIdentifier): 

24 """A JSON:API resource for a page application.""" 

25 

26 attributes: PageApplicationAttributes 

27 

28 

29class PageApplicationDocument(BaseModel): 

30 """A JSON:API document for a page application.""" 

31 

32 data: PageApplicationResource 

33 

34 

35class BasePageText(BaseModel): 

36 """Basic schema for the text of a page.""" 

37 

38 locale: str 

39 title: str 

40 summary: str 

41 content: str | None 

42 

43 

44class PageText(BasePageText): 

45 """Schema for the text of a page.""" 

46 

47 format: str 

48 original_summary: str 

49 original_content: str | None 

50 

51 

52class BasePageAttributes(BaseModel): 

53 """Basic attributes of a JSON:API page resource.""" 

54 

55 priority: int 

56 texts: list[PageText] 

57 

58 

59class PageAttributes(BasePageAttributes): 

60 """Attributes of a page JSON:API resource.""" 

61 

62 enabled: bool 

63 remark: str 

64 

65 

66class PageRelationships(BaseModel): 

67 """Relationships of a page JSON:API resource.""" 

68 

69 application: Relationship[ApplicationResourceIdentifier] 

70 

71 

72class PageResource(PageResourceIdentifier): 

73 """A JSON:API resource for a page.""" 

74 

75 meta: ResourceMeta | None = None 

76 attributes: PageAttributes 

77 relationships: PageRelationships 

78 

79 

80class PageDocument(BaseModel): 

81 """A JSON:API document for one page.""" 

82 

83 data: PageResource 

84 included: set[PageApplicationResource] = Field(default_factory=set) 

85 

86 

87class PagesDocument(BaseModel): 

88 """A JSON:API document for multiple pages.""" 

89 

90 meta: Meta 

91 data: list[PageResource] = Field(default_factory=list) 

92 included: set[PageApplicationResource] = Field(default_factory=set)