Skip to content

Commit

Permalink
🐛 fix: fix openapi export entry
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinxx committed Dec 15, 2023
1 parent 9b9c1f6 commit b383cfc
Show file tree
Hide file tree
Showing 4 changed files with 336 additions and 2 deletions.
332 changes: 332 additions & 0 deletions tests/__snapshots__/openapi.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,248 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`OpenAPIConvertor > 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",
},
},
"type": "object",
},
},
{
"description": "提交Blend任务",
"name": "blendUsingPOST",
"parameters": {
"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",
],
"type": "object",
},
},
{
"description": "绘图变化",
"name": "changeUsingPOST",
"parameters": {
"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",
],
"type": "object",
},
},
{
"description": "提交Describe任务",
"name": "describeUsingPOST",
"parameters": {
"properties": {
"base64": {
"description": "图片base64",
"example": "data:image/png;base64,xxx",
"type": "string",
},
"notifyHook": {
"description": "回调地址, 为空时使用全局notifyHook",
"type": "string",
},
"state": {
"description": "自定义参数",
"type": "string",
},
},
"required": [
"base64",
],
"type": "object",
},
},
{
"description": "提交Imagine任务",
"name": "imagineUsingPOST",
"parameters": {
"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",
],
"type": "object",
},
},
{
"description": "绘图变化-simple",
"name": "simpleChangeUsingPOST",
"parameters": {
"properties": {
"content": {
"description": "变化描述: ID $action$index",
"example": "1320098173412546 U2",
"type": "string",
},
"notifyHook": {
"description": "回调地址, 为空时使用全局notifyHook",
"type": "string",
},
"state": {
"description": "自定义参数",
"type": "string",
},
},
"required": [
"content",
],
"type": "object",
},
},
{
"description": "查询所有任务",
"name": "listUsingGET_1",
"parameters": {
"properties": {},
"type": "object",
},
},
{
"description": "根据ID列表查询任务",
"name": "listByIdsUsingPOST",
"parameters": {
"properties": {
"ids": {
"items": {
"type": "string",
},
"type": "array",
},
},
"type": "object",
},
},
{
"description": "查询任务队列",
"name": "queueUsingGET",
"parameters": {
"properties": {},
"type": "object",
},
},
{
"description": "指定ID获取任务",
"name": "fetchUsingGET_1",
"parameters": {
"properties": {
"id": {
"description": "任务ID",
"type": "string",
},
},
"type": "object",
},
},
]
`;

exports[`OpenAPIConvertor > convertOpenAPIToPluginSchema > can convert OpenAPI v3.0.2 openAPI 1`] = `
[
{
Expand Down Expand Up @@ -47,3 +290,92 @@ exports[`OpenAPIConvertor > convertOpenAPIToPluginSchema > can convert OpenAPI v
},
]
`;

exports[`OpenAPIConvertor > 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",
},
},
]
`;
2 changes: 1 addition & 1 deletion tests/openapi.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { OpenAPIConvertor } from '@lobehub/chat-plugin-sdk';
import { OpenAPIConvertor } from '@lobehub/chat-plugin-sdk/openapi';
import { describe, expect, it } from 'vitest';

import OpenAPI_Auth_API_Key from './fixtures/OpenAPI_Auth_API_Key.json';
Expand Down
3 changes: 2 additions & 1 deletion tests/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"paths": {
"@/*": [".src/*"],
"@lobehub/chat-plugin-sdk": ["./src"],
"@lobehub/chat-plugin-sdk/client": ["./src/client"]
"@lobehub/chat-plugin-sdk/client": ["./src/client"],
"@lobehub/chat-plugin-sdk/openapi": ["./src/openapi"]
},
"types": ["vitest/globals"]
},
Expand Down
1 change: 1 addition & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default defineConfig({
'@': path.join(__dirname, './src'),
'@lobehub/chat-plugin-sdk': path.join(__dirname, './src'),
'@lobehub/chat-plugin-sdk/client': path.join(__dirname, './src/client'),
'@lobehub/chat-plugin-sdk/openapi': path.join(__dirname, './src/openapi'),
},
coverage: {
reporter: ['text', 'text-summary', 'json', 'lcov'],
Expand Down

0 comments on commit b383cfc

Please sign in to comment.