v2-terms.yaml 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. # 由 openapi/scripts/generate.php 生成,请勿手改;补充写到 overrides/v2-terms.yaml
  2. get:
  3. summary: '列出术语(dhamma term)'
  4. tags:
  5. - terms
  6. operationId: get_api_v2_terms
  7. description: |-
  8. 按 view 指定的口径返回术语列表。studio、channel、user 三个口径需要登录;
  9. studio 要求 name 指向的 studio 属于当前用户,否则 403;channel 要求当前用户是
  10. channel owner 或协作者(ShareApi 权限值非 0),否则 403。
  11. create-by-channel、show、hot-meaning 三个口径直接返回各自的数据结构,
  12. 不走后面的搜索/排序/分页;其余口径统一返回 {rows, count}。
  13. hot-meaning 结果会按 config('mint.cache.expire') 缓存在 term/hot_meaning 键下。
  14. 未指定 view(或给了无法识别的值)时没有任何基础查询,会直接报错,调用方必须传 view。
  15. 实现:`DhammaTermController@index`
  16. parameters:
  17. -
  18. name: view
  19. in: query
  20. schema:
  21. type: string
  22. enum:
  23. - create-by-channel
  24. - studio
  25. - channel
  26. - show
  27. - user
  28. - word
  29. - tag
  30. - hot-meaning
  31. description: 查询口径
  32. required: true
  33. -
  34. name: channel
  35. in: query
  36. schema:
  37. type: string
  38. description: 'view=create-by-channel 时必填,目标 channel 的 uid, 用于确定语言、同 studio 的 channel 列表与 studio 信息'
  39. -
  40. name: word
  41. in: query
  42. schema:
  43. type: string
  44. description: 'view=create-by-channel 时为要新建的术语词形; view=word 时为逗号分隔的词或义项列表,按 word 或 meaning 命中'
  45. -
  46. name: name
  47. in: query
  48. schema:
  49. type: string
  50. description: 'view=studio 时必填,studio 名称,须与当前用户的 studio 一致'
  51. -
  52. name: id
  53. in: query
  54. schema:
  55. type: string
  56. description: 'view=channel 时为 channel id(uid);view=show 时为术语主键 id'
  57. -
  58. name: search
  59. in: query
  60. schema:
  61. type: string
  62. description: '关键字,按 word、word_en 前缀匹配或 meaning 模糊匹配'
  63. -
  64. name: tag
  65. in: query
  66. schema:
  67. type: string
  68. description: 'view=tag 时必填,逗号分隔的 tag 列表'
  69. -
  70. name: language
  71. in: query
  72. schema:
  73. type: string
  74. description: 'view=hot-meaning 时必填,统计该语言下每个词出现次数最多的义项'
  75. -
  76. name: order
  77. in: query
  78. schema:
  79. type: string
  80. default: updated_at
  81. description: 排序字段
  82. -
  83. name: dir
  84. in: query
  85. schema:
  86. type: string
  87. enum:
  88. - asc
  89. - desc
  90. default: desc
  91. description: 排序方向
  92. -
  93. name: offset
  94. in: query
  95. schema:
  96. type: integer
  97. default: 0
  98. description: 分页偏移量
  99. -
  100. name: limit
  101. in: query
  102. schema:
  103. type: integer
  104. default: 1000
  105. description: 每页条数
  106. -
  107. name: mode
  108. in: query
  109. schema:
  110. type: string
  111. default: read
  112. description: '渲染 note/summary 的模式,透传给 Markdown 渲染器'
  113. -
  114. name: format
  115. in: query
  116. schema:
  117. type: string
  118. enum:
  119. - react
  120. - html
  121. - text
  122. default: react
  123. description: 'note 的渲染输出格式'
  124. -
  125. name: community_summary
  126. in: query
  127. schema:
  128. type: boolean
  129. description: '传入该参数时,自身没有 note 的术语会回落到社区 channel 的解释作为 summary'
  130. -
  131. name: exp
  132. in: query
  133. schema:
  134. type: boolean
  135. description: 传入该参数时附带编辑者截至本条更新时间的累计经验值(秒)
  136. responses:
  137. 200:
  138. description: '成功。业务失败时 HTTP 仍可能为 200,以 ok 字段为准。'
  139. content:
  140. application/json:
  141. schema:
  142. type: object
  143. properties:
  144. ok:
  145. type: boolean
  146. message:
  147. type: string
  148. data:
  149. type: object
  150. properties:
  151. rows:
  152. type: array
  153. items:
  154. type: object
  155. properties: { id: { type: integer }, guid: { type: string }, word: { type: string }, word_en: { type: string }, meaning: { type: string }, other_meaning: { type: string }, tag: { type: string }, note: { type: string }, language: { type: string }, channel_id: { type: integer }, channal: { type: string }, studio: { type: string }, editor: { type: string }, created_at: { type: string }, updated_at: { type: string }, mode: { type: string }, format: { type: string }, studioId: { type: string }, channel: { type: string }, html: { type: string }, summary_is_community: { type: string }, summary: { type: string }, role: { type: string }, exp: { type: string } }
  156. count:
  157. type: integer
  158. 401:
  159. $ref: '../../main.yaml#/components/responses/Unauthorized'
  160. 422:
  161. $ref: '../../main.yaml#/components/responses/ValidationError'
  162. post:
  163. summary: 新建术语
  164. tags:
  165. - terms
  166. operationId: post_api_v2_terms
  167. description: |-
  168. 需要登录。传了 channel 则建 channel 级术语,owner 取该 channel 所属 studio、
  169. language 取该 channel 的语言(请求里的 language 被覆盖),并要求当前身份对该
  170. channel 有编辑权(owner / 协作者 / channel access token),否则 403。
  171. 不传 channel 则建 studio 级术语,只允许 studio 本人创建(studioId 必须等于当前
  172. 用户 uid,否则 403);AI 模型身份一律禁止(403),因为 access token 只能代持
  173. channel 级权限。
  174. 唯一性:channel 级按 channel+word+tag 查重,studio 级按 owner+word+tag+language
  175. 且 channal 为空查重;重复时返回 'word existed',HTTP 状态仍是 200。
  176. 写入成功后清除该词的 term 缓存并重建 OpenSearch 索引(索引失败只记日志)。
  177. 实现:`DhammaTermController@store`
  178. requestBody:
  179. required: true
  180. content:
  181. application/json:
  182. schema:
  183. type: object
  184. properties:
  185. word:
  186. type: string
  187. description: '术语词形,同时用于生成 word_en'
  188. meaning:
  189. type: string
  190. description: 主要义项
  191. tag:
  192. type: string
  193. description: 标签,参与查重
  194. channel:
  195. type: string
  196. description: 'channel uid。给出则建 channel 级术语,否则建 studio 级术语'
  197. language:
  198. type: string
  199. description: '语言。仅 studio 级术语生效,channel 级会被 channel 语言覆盖'
  200. other_meaning:
  201. type: string
  202. description: 其他义项,逗号分隔
  203. note:
  204. type: string
  205. description: 术语解释,Markdown
  206. access_token:
  207. type: string
  208. description: 'channel access token,供 AI 模型等非 owner 身份验证 channel 编辑权'
  209. studioId:
  210. type: string
  211. description: 'studio 的 uuid,不传 channel 时必填(或改用 studioName)'
  212. studioName:
  213. type: string
  214. description: 'studio 名称,未给 studioId 时用它换取 studioId'
  215. required:
  216. - word
  217. - meaning
  218. responses:
  219. 200:
  220. description: '成功。业务失败时 HTTP 仍可能为 200,以 ok 字段为准。'
  221. content:
  222. application/json:
  223. schema:
  224. type: object
  225. properties:
  226. ok:
  227. type: boolean
  228. message:
  229. type: string
  230. data:
  231. type: object
  232. properties:
  233. id:
  234. type: integer
  235. guid:
  236. type: string
  237. word:
  238. type: string
  239. word_en:
  240. type: string
  241. meaning:
  242. type: string
  243. other_meaning:
  244. type: string
  245. tag:
  246. type: string
  247. note:
  248. type: string
  249. language:
  250. type: string
  251. channel_id:
  252. type: integer
  253. channal:
  254. type: string
  255. studio:
  256. type: string
  257. editor:
  258. type: string
  259. created_at:
  260. type: string
  261. updated_at:
  262. type: string
  263. mode:
  264. type: string
  265. format:
  266. type: string
  267. studioId:
  268. type: string
  269. channel:
  270. type: string
  271. html:
  272. type: string
  273. summary_is_community:
  274. type: string
  275. summary:
  276. type: string
  277. role:
  278. type: string
  279. exp:
  280. type: string
  281. 401:
  282. $ref: '../../main.yaml#/components/responses/Unauthorized'
  283. 422:
  284. $ref: '../../main.yaml#/components/responses/ValidationError'