在 bookmark.yaml 配置文件中,为多个接口路径添加了 '401' 和 '403' 状态码的响应引用, 分别指向 components 中定义的 Unauthorized 和 Forbidden 响应。同时在 components 部分补充了 Forbidden 响应的定义,增强了 API 文档的完整性与规范性。 feat(user_np): 新增用户信息接口与基础错误结构定义 在 user_np.yaml 中新增了 /auth/info 路径下的 GET 和 PUT 接口,用于获取和保存用户信息。 同时,在 components 中定义了 ServerInternalError 响应和 Error 结构体,统一错误返回格式, 提升接口一致性与可维护性。 feat(vfs): 调整内容类型为 text/plain 并增强节点名称校验逻辑 将 vfs.yaml 中涉及二进制流传输的内容类型由 application/octet-stream 修改为 text/plain, 简化数据处理方式。同时在 vfs.go 模型中新增 CheckNameValid 方法,用于校验节点名称合法性, 防止非法字符(如斜杠)造成路径问题。 refactor(bookmark): 优化 API Key 验证逻辑并暴露更新时间字段 重构 BookMarksImpl 的 validateApiKey 函数,简化认证判断流程,并将 adminToken 从指针改为字符串常量。 此外,在 bookmarkModel2Res 函数中新增 UpdatedAt 字段,使书签响应包含更新时间信息。 feat(user_np): 实现用户信息相关接口占位函数 在 UserNPImpl 中新增 GetUserInfo 和 SaveUserInfo 两个方法的占位实现,为后续业务逻辑开发做好准备。 refactor(vfs): 使用文本请求体并加强服务节点操作校验 修改 vfs_impl.go 中读取请求体的方式,由 io.Reader 改为直接解引用文本内容,提升处理效率。 更新 CreateVFSNode、GetVFSNode 和 UpdateVFSNode 方法中对请求体和响应体的处理逻辑, 统一使用文本格式,增强代码一致性与健壮性。 feat(vfs): 为书签代理服务添加认证 Token 支持 在 vfs_bookmark.go 中为 VfsBookMarkService 结构体增加 token 字段,并在调用 bookmark 服务各接口时, 通过 HTTP 请求头设置 X-BookMark-Token,确保服务间通信的安全性与权限控制。
352 lines
9.6 KiB
YAML
352 lines
9.6 KiB
YAML
openapi: '3.0.3'
|
|
info:
|
|
title: zzyxyz_vfs_api
|
|
description: 虚拟文件系统API服务
|
|
version: '1.0'
|
|
servers:
|
|
- url: http://localhost:8080/api
|
|
description: 开发环境
|
|
- url: https://api.zzyxyz.com/api
|
|
description: 生产环境
|
|
tags:
|
|
- name: vfs
|
|
description: 虚拟文件系统相关操作
|
|
- name: user
|
|
description: 用户相关操作
|
|
security:
|
|
- ApiKeyAuth: []
|
|
|
|
paths:
|
|
/vfs/v1/users/{username}:
|
|
parameters:
|
|
- name: username
|
|
in: path
|
|
example: user
|
|
required: true
|
|
schema:
|
|
type: string
|
|
|
|
post:
|
|
summary: 创建用户
|
|
description: 创建一个用户
|
|
operationId: createUser
|
|
tags: [user]
|
|
responses:
|
|
'201':
|
|
description: 创建成功
|
|
headers:
|
|
X-VFS-Token:
|
|
schema:
|
|
type: string
|
|
description: 认证令牌
|
|
'400':
|
|
$ref: '#/components/responses/ParameterError'
|
|
'401':
|
|
$ref: '#/components/responses/UnauthorizedError'
|
|
'403':
|
|
$ref: '#/components/responses/ForbiddenError'
|
|
'500':
|
|
$ref: '#/components/responses/ServerInternalError'
|
|
|
|
delete:
|
|
summary: 删除用户
|
|
description: 删除一个用户
|
|
operationId: deleteUser
|
|
tags: [user]
|
|
responses:
|
|
'204':
|
|
description: 删除成功
|
|
'404':
|
|
description: 用户不存在
|
|
content:
|
|
application/json:
|
|
schema:
|
|
$ref: '#/components/schemas/Error'
|
|
'400':
|
|
$ref: '#/components/responses/ParameterError'
|
|
'401':
|
|
$ref: '#/components/responses/UnauthorizedError'
|
|
'403':
|
|
$ref: '#/components/responses/ForbiddenError'
|
|
'500':
|
|
$ref: '#/components/responses/ServerInternalError'
|
|
|
|
/vfs/v1/files:
|
|
parameters:
|
|
- name: path
|
|
in: query
|
|
required: true
|
|
description: 文件系统路径,例如 "documents/readme.txt" 或 "services/mysql.service" 或 "folder/"
|
|
schema:
|
|
type: string
|
|
example: "readme.txt"
|
|
|
|
get:
|
|
summary: 读取文件或列出目录
|
|
description: 获取指定路径的文件内容或目录列表
|
|
operationId: getVFSNode
|
|
tags: [vfs]
|
|
parameters:
|
|
- name: op
|
|
in: query
|
|
required: false
|
|
description: 操作类型, list表示列出目录内容, 不指定则读取文件内容
|
|
schema:
|
|
type: string
|
|
enum: [list]
|
|
responses:
|
|
'200':
|
|
description: 文件内容或目录列表
|
|
content:
|
|
application/json:
|
|
schema:
|
|
description: 目录条目列表
|
|
type: array
|
|
items:
|
|
$ref: '#/components/schemas/VFSDirectoryEntry'
|
|
text/plain:
|
|
schema:
|
|
type: string
|
|
'400':
|
|
$ref: '#/components/responses/ParameterError'
|
|
'401':
|
|
$ref: '#/components/responses/UnauthorizedError'
|
|
'403':
|
|
$ref: '#/components/responses/ForbiddenError'
|
|
'404':
|
|
$ref: '#/components/responses/PathNotFoundError'
|
|
'500':
|
|
$ref: '#/components/responses/ServerInternalError'
|
|
|
|
post:
|
|
summary: 创建文件或目录
|
|
description: 创建文件或目录
|
|
operationId: createVFSNode
|
|
tags: [vfs]
|
|
requestBody:
|
|
required: false
|
|
content:
|
|
text/plain:
|
|
schema:
|
|
type: string
|
|
responses:
|
|
'201':
|
|
description: 创建成功
|
|
content:
|
|
text/plain:
|
|
schema:
|
|
type: string
|
|
application/json:
|
|
schema:
|
|
$ref: '#/components/schemas/VFSNodeResponse'
|
|
'400':
|
|
$ref: '#/components/responses/ParameterError'
|
|
'401':
|
|
$ref: '#/components/responses/UnauthorizedError'
|
|
'403':
|
|
$ref: '#/components/responses/ForbiddenError'
|
|
'404':
|
|
$ref: '#/components/responses/PathNotFoundError'
|
|
'500':
|
|
$ref: '#/components/responses/ServerInternalError'
|
|
|
|
patch:
|
|
summary: 修改文件或修改目录
|
|
description: 修改/移动/重命名/复制 已存在的 文件/目录
|
|
operationId: updateVFSNode
|
|
tags: [vfs]
|
|
parameters:
|
|
- name: op
|
|
in: query
|
|
description: 操作模式
|
|
required: true
|
|
schema:
|
|
type: string
|
|
enum: [move, rename, change, copy]
|
|
requestBody:
|
|
required: true
|
|
content:
|
|
application/json:
|
|
schema:
|
|
type: string
|
|
description: 目的文件夹路径 / 文件名路径
|
|
example: "/home/"
|
|
text/plain:
|
|
schema:
|
|
type: string
|
|
responses:
|
|
'200':
|
|
description: 操作成功
|
|
content:
|
|
application/json:
|
|
schema:
|
|
$ref: '#/components/schemas/VFSNodeResponse'
|
|
'400':
|
|
$ref: '#/components/responses/ParameterError'
|
|
'401':
|
|
$ref: '#/components/responses/UnauthorizedError'
|
|
'403':
|
|
$ref: '#/components/responses/ForbiddenError'
|
|
'404':
|
|
$ref: '#/components/responses/PathNotFoundError'
|
|
'500':
|
|
$ref: '#/components/responses/ServerInternalError'
|
|
|
|
delete:
|
|
summary: 删除文件或目录
|
|
description: 删除指定路径的文件或目录
|
|
operationId: deleteVFSNode
|
|
tags: [vfs]
|
|
responses:
|
|
'204':
|
|
description: 删除成功
|
|
'400':
|
|
$ref: '#/components/responses/ParameterError'
|
|
'401':
|
|
$ref: '#/components/responses/UnauthorizedError'
|
|
'403':
|
|
$ref: '#/components/responses/ForbiddenError'
|
|
'404':
|
|
$ref: '#/components/responses/PathNotFoundError'
|
|
'500':
|
|
$ref: '#/components/responses/ServerInternalError'
|
|
|
|
components:
|
|
securitySchemes:
|
|
ApiKeyAuth:
|
|
type: apiKey
|
|
in: header
|
|
name: X-VFS-Token
|
|
|
|
responses:
|
|
ServerInternalError:
|
|
description: 服务器内部错误
|
|
content:
|
|
application/json:
|
|
schema:
|
|
$ref: '#/components/schemas/Error'
|
|
example:
|
|
errtype: "InternalServerError"
|
|
message: "服务器内部错误"
|
|
|
|
UnauthorizedError:
|
|
description: 未授权
|
|
content:
|
|
application/json:
|
|
schema:
|
|
$ref: '#/components/schemas/Error'
|
|
example:
|
|
errtype: "Unauthorized"
|
|
message: "访问被拒绝,缺少有效的认证令牌"
|
|
|
|
ForbiddenError:
|
|
description: 禁止
|
|
content:
|
|
application/json:
|
|
schema:
|
|
$ref: '#/components/schemas/Error'
|
|
example:
|
|
errtype: "Forbidden"
|
|
message: "访问被拒绝,您没有权限访问此资源"
|
|
|
|
PathNotFoundError:
|
|
description: 路径不存在
|
|
content:
|
|
application/json:
|
|
schema:
|
|
$ref: '#/components/schemas/Error'
|
|
example:
|
|
errtype: "PathNotFound"
|
|
message: "指定的路径不存在"
|
|
|
|
ParameterError:
|
|
description: 请求参数错误
|
|
content:
|
|
application/json:
|
|
schema:
|
|
$ref: '#/components/schemas/Error'
|
|
example:
|
|
errtype: "ParameterError"
|
|
message: "请求参数无效或缺失"
|
|
|
|
schemas:
|
|
VFSNodeType:
|
|
type: string
|
|
description: 节点类型
|
|
enum: [file, directory, service]
|
|
|
|
VFSNodeResponse:
|
|
type: object
|
|
properties:
|
|
name:
|
|
type: string
|
|
description: 节点名称
|
|
type:
|
|
$ref: '#/components/schemas/VFSNodeType'
|
|
created_at:
|
|
type: string
|
|
format: date-time
|
|
description: 创建时间
|
|
updated_at:
|
|
type: string
|
|
format: date-time
|
|
description: 更新时间
|
|
required:
|
|
- name
|
|
- type
|
|
- created_at
|
|
- updated_at
|
|
|
|
VFSDirectoryEntry:
|
|
type: object
|
|
properties:
|
|
name:
|
|
type: string
|
|
description: 条目名称
|
|
type:
|
|
$ref: '#/components/schemas/VFSNodeType'
|
|
permissions:
|
|
type: string
|
|
description: 权限信息,如 "rw"
|
|
required:
|
|
- name
|
|
- type
|
|
- modified
|
|
|
|
Error:
|
|
type: object
|
|
description: 错误信息
|
|
properties:
|
|
errtype:
|
|
type: string
|
|
description: |
|
|
错误类型,可能的值包括:
|
|
- "InternalServerError": 服务器内部错误
|
|
- "Unauthorized": 客户端需要提供正确格式权限
|
|
- "Forbidden": 无权限访问
|
|
- "PathNotFound": 路径不存在
|
|
- "ParameterError": 请求参数错误
|
|
- "ConflictError": 资源冲突
|
|
- "DatabaseError": 数据库操作错误
|
|
- "NotFoundError": 资源未找到
|
|
- "AccessDenied": 访问被拒绝
|
|
- "ServiceProxyError": 代理服务错误
|
|
example: "InternalServerError"
|
|
enum:
|
|
- "InternalServerError"
|
|
- "Unauthorized"
|
|
- "Forbidden"
|
|
- "PathNotFound"
|
|
- "ParameterError"
|
|
- "ConflictError"
|
|
- "DatabaseError"
|
|
- "NotFoundError"
|
|
- "AccessDenied"
|
|
- "ServiceProxyError"
|
|
message:
|
|
type: string
|
|
description: 详细的错误信息
|
|
example: "传递的第一个参数错误"
|
|
required:
|
|
- errtype
|
|
- message |