You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
1.9 KiB

11 months ago
10 months ago
11 months ago
10 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
10 months ago
11 months ago
10 months ago
11 months ago
10 months ago
11 months ago
11 months ago
10 months ago
11 months ago
10 months ago
  1. from pydantic import BaseModel,Field
  2. from typing import Annotated
  3. # Token相关的模型
  4. class Token(BaseModel):
  5. access_token: str
  6. token_type: str
  7. class TokenData(BaseModel):
  8. username: str = None
  9. # User相关的模型
  10. class User(BaseModel):
  11. username: Annotated[str,Field(
  12. title="用户",
  13. examples=["admin"],
  14. pattern=r'^.{4,20}$',
  15. description="允许4-20的字符"
  16. )]
  17. email: Annotated[str,Field(
  18. examples=["examples@example.com"],
  19. max_length=50,
  20. pattern=r'^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$',
  21. description="邮箱需要满足正则标准"
  22. )]
  23. full_name: Annotated[str,Field(
  24. examples=["admin"],
  25. pattern=r'^.{2,20}$',
  26. description="允许2-20个字符"
  27. )]
  28. disabled: bool = True
  29. class UserInDB(User):
  30. hashed_password: str = None
  31. class Blog(BaseModel):
  32. blogtitle:Annotated[str,Field(
  33. title="博客标题",
  34. pattern=r'^.{4,20}$',
  35. examples=[""],
  36. description="允许6-20个字符"
  37. )]
  38. blogcontent:Annotated[str,Field(
  39. title="博客内容",
  40. min_length=1,
  41. description="最少1个字符"
  42. )]
  43. typeid:Annotated[int,Field(
  44. title="类型id",
  45. default=None,
  46. description="类型id允许为空"
  47. )]
  48. descr:Annotated[str,Field(
  49. title="备注",
  50. default=None,
  51. description="备注允许为空"
  52. )]
  53. class TypeList(BaseModel):
  54. blogid:Annotated[int,Field(
  55. title="博客id",
  56. default=None,
  57. description="博客id可以为空"
  58. )]
  59. typename:Annotated[str,Field(
  60. title="类型名称",
  61. examples=['typename'],
  62. pattern=r'^.{2,50}$',
  63. description="允许2-50个字符"
  64. )]
  65. descr:Annotated[str,Field(
  66. title="备注",
  67. default=None,
  68. description="博客类型允许为空"
  69. )]