Skip to content

Commit

Permalink
✨ feat: support parse openapi schema
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinxx committed Dec 11, 2023
1 parent 23c58a9 commit 90c66de
Show file tree
Hide file tree
Showing 7 changed files with 1,703 additions and 18 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
"nanoid": "^5",
"next": "^14.0.2",
"openai": "^4.17.3",
"openapi-jsonschema-parameters": "^12.1.3",
"polished": "^4",
"posthog-js": "^1",
"query-string": "^8",
Expand All @@ -112,6 +113,7 @@
"remark-html": "^15",
"semver": "^7",
"sharp": "^0.33",
"swagger-client": "^3.24.5",
"swr": "^2",
"systemjs": "^6",
"ts-md5": "^1",
Expand Down
3 changes: 2 additions & 1 deletion src/locales/default/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ export default {
error: {
fetchError: '请求该 manifest 链接失败,请确保链接的有效性,并检查链接是否允许跨域访问',
installError: '插件 {{name}} 安装失败',
manifestInvalid: ' manifest 不符合规范,校验结果: \n\n {{error}}',
manifestInvalid: 'manifest 不符合规范,校验结果: \n\n {{error}}',
noManifest: '描述文件不存在',
openAPIInvalid: 'OpenAPI 解析失败,错误: \n\n {{error}}',
reinstallError: '插件 {{name}} 刷新失败',
urlError: '该链接没有返回 JSON 格式的内容, 请确保是有效的链接',
},
Expand Down
347 changes: 347 additions & 0 deletions src/services/__tests__/__snapshots__/plugin.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,347 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`PluginService > convertOpenAPIToPluginSchema > can convert OpenAPI v2 MJ openAPI 1`] = `
[
{
"description": "查询所有账号",
"name": "listUsingGET",
"parameters": {
"properties": {},
"type": "object",
},
},
{
"description": "指定ID获取账号",
"name": "fetchUsingGET",
"parameters": {
"properties": {
"id": {
"description": "账号ID",
"type": "string",
},
},
"required": [],
"type": "object",
},
},
{
"description": "提交Blend任务",
"name": "blendUsingPOST",
"parameters": {
"$$ref": "http://localhost:3000/#/definitions/Blend提交参数",
"properties": {
"base64Array": {
"description": "图片base64数组",
"example": [
"data:image/png;base64,xxx1",
"data:image/png;base64,xxx2",
],
"items": {
"type": "string",
},
"refType": "string",
"type": "array",
},
"dimensions": {
"description": "比例: PORTRAIT(2:3); SQUARE(1:1); LANDSCAPE(3:2)",
"enum": [
"PORTRAIT",
"SQUARE",
"LANDSCAPE",
],
"example": "SQUARE",
"refType": null,
"type": "string",
},
"notifyHook": {
"description": "回调地址, 为空时使用全局notifyHook",
"refType": null,
"type": "string",
},
"state": {
"description": "自定义参数",
"refType": null,
"type": "string",
},
},
"required": [
"base64Array",
],
"title": "Blend提交参数",
"type": "object",
},
},
{
"description": "绘图变化",
"name": "changeUsingPOST",
"parameters": {
"$$ref": "http://localhost:3000/#/definitions/变化任务提交参数",
"properties": {
"action": {
"description": "UPSCALE(放大); VARIATION(变换); REROLL(重新生成)",
"enum": [
"UPSCALE",
"VARIATION",
"REROLL",
],
"example": "UPSCALE",
"type": "string",
},
"index": {
"description": "序号(1~4), action为UPSCALE,VARIATION时必传",
"example": 1,
"exclusiveMaximum": false,
"exclusiveMinimum": false,
"format": "int32",
"maximum": 4,
"minimum": 1,
"type": "integer",
},
"notifyHook": {
"description": "回调地址, 为空时使用全局notifyHook",
"type": "string",
},
"state": {
"description": "自定义参数",
"type": "string",
},
"taskId": {
"description": "任务ID",
"example": "1320098173412546",
"type": "string",
},
},
"required": [
"action",
"taskId",
],
"title": "变化任务提交参数",
"type": "object",
},
},
{
"description": "提交Describe任务",
"name": "describeUsingPOST",
"parameters": {
"$$ref": "http://localhost:3000/#/definitions/Describe提交参数",
"properties": {
"base64": {
"description": "图片base64",
"example": "data:image/png;base64,xxx",
"type": "string",
},
"notifyHook": {
"description": "回调地址, 为空时使用全局notifyHook",
"type": "string",
},
"state": {
"description": "自定义参数",
"type": "string",
},
},
"required": [
"base64",
],
"title": "Describe提交参数",
"type": "object",
},
},
{
"description": "提交Imagine任务",
"name": "imagineUsingPOST",
"parameters": {
"$$ref": "http://localhost:3000/#/definitions/Imagine提交参数",
"properties": {
"base64Array": {
"description": "垫图base64数组",
"items": {
"type": "string",
},
"type": "array",
},
"notifyHook": {
"description": "回调地址, 为空时使用全局notifyHook",
"type": "string",
},
"prompt": {
"description": "提示词",
"example": "Cat",
"type": "string",
},
"state": {
"description": "自定义参数",
"type": "string",
},
},
"required": [
"prompt",
],
"title": "Imagine提交参数",
"type": "object",
},
},
{
"description": "绘图变化-simple",
"name": "simpleChangeUsingPOST",
"parameters": {
"$$ref": "http://localhost:3000/#/definitions/变化任务提交参数-simple",
"properties": {
"content": {
"description": "变化描述: ID $action$index",
"example": "1320098173412546 U2",
"type": "string",
},
"notifyHook": {
"description": "回调地址, 为空时使用全局notifyHook",
"type": "string",
},
"state": {
"description": "自定义参数",
"type": "string",
},
},
"required": [
"content",
],
"title": "变化任务提交参数-simple",
"type": "object",
},
},
{
"description": "查询所有任务",
"name": "listUsingGET_1",
"parameters": {
"properties": {},
"type": "object",
},
},
{
"description": "根据ID列表查询任务",
"name": "listByIdsUsingPOST",
"parameters": {
"$$ref": "http://localhost:3000/#/definitions/任务查询参数",
"properties": {
"ids": {
"items": {
"type": "string",
},
"type": "array",
},
},
"title": "任务查询参数",
"type": "object",
},
},
{
"description": "查询任务队列",
"name": "queueUsingGET",
"parameters": {
"properties": {},
"type": "object",
},
},
{
"description": "指定ID获取任务",
"name": "fetchUsingGET_1",
"parameters": {
"properties": {
"id": {
"description": "任务ID",
"type": "string",
},
},
"required": [],
"type": "object",
},
},
]
`;

exports[`PluginService > convertOpenAPIToPluginSchema > can convert OpenAPI v3.1 to lobe apis 1`] = `
[
{
"description": "Read Course Segments",
"name": "read_course_segments_course_segments__get",
"parameters": {
"properties": {},
"type": "object",
},
},
{
"description": "Read Problem Set Item",
"name": "read_problem_set_item_problem_set__problem_set_id___question_number__get",
"parameters": {
"properties": {
"problem_set_id": {
"title": "Problem Set Id",
"type": "integer",
},
"question_number": {
"title": "Question Number",
"type": "integer",
},
},
"required": [
"problem_set_id",
"question_number",
],
"type": "object",
},
},
{
"description": "Read Random Problem Set Items",
"name": "read_random_problem_set_items_problem_set_random__problem_set_id___n_items__get",
"parameters": {
"properties": {
"n_items": {
"title": "N Items",
"type": "integer",
},
"problem_set_id": {
"title": "Problem Set Id",
"type": "integer",
},
},
"required": [
"problem_set_id",
"n_items",
],
"type": "object",
},
},
{
"description": "Read Range Of Problem Set Items",
"name": "read_range_of_problem_set_items_problem_set_range__problem_set_id___start___end__get",
"parameters": {
"properties": {
"end": {
"title": "End",
"type": "integer",
},
"problem_set_id": {
"title": "Problem Set Id",
"type": "integer",
},
"start": {
"title": "Start",
"type": "integer",
},
},
"required": [
"problem_set_id",
"start",
"end",
],
"type": "object",
},
},
{
"description": "Read User Id",
"name": "read_user_id_user__get",
"parameters": {
"properties": {},
"type": "object",
},
},
]
`;

0 comments on commit 90c66de

Please sign in to comment.