Skip to content

Commit 795b20b

Browse files
committed
Fix empty object separation problem.
1 parent eabbd50 commit 795b20b

File tree

3 files changed

+65
-2
lines changed

3 files changed

+65
-2
lines changed

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@wrtnio/schema",
3-
"version": "3.0.2",
3+
"version": "3.0.3",
44
"description": "JSON and LLM function calling schemas extended for Wrtn Studio Pro",
55
"main": "lib/index.js",
66
"module": "./lib/index.mjs",
@@ -31,7 +31,7 @@
3131
},
3232
"homepage": "https://github.com/wrtnio/schema#readme",
3333
"dependencies": {
34-
"@samchon/openapi": "^2.0.3"
34+
"@samchon/openapi": "^2.0.4"
3535
},
3636
"devDependencies": {
3737
"@nestia/core": "^4.0.0",

src/internal/HttpOpenAiSeparator.ts

+7
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ export namespace HttpOpenAiSeparator {
6060
(
6161
input: IOpenAiSchema.IObject,
6262
): [IOpenAiSchema.IObject | null, IOpenAiSchema.IObject | null] => {
63+
if (
64+
Object.keys(input.properties ?? {}).length === 0 &&
65+
!!input.additionalProperties === false
66+
)
67+
return [input, null];
68+
6369
const llm = {
6470
...input,
6571
properties: {} as Record<string, IOpenAiSchema>,
@@ -68,6 +74,7 @@ export namespace HttpOpenAiSeparator {
6874
...input,
6975
properties: {} as Record<string, IOpenAiSchema>,
7076
} satisfies IOpenAiSchema.IObject;
77+
7178
for (const [key, value] of Object.entries(input.properties ?? {})) {
7279
const [x, y] = schema(predicator)(value);
7380
if (x !== null) llm.properties[key] = x;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { TestValidator } from "@nestia/e2e";
2+
import { OpenApi } from "@samchon/openapi";
3+
import {
4+
HttpOpenAi,
5+
IHttpOpenAiApplication,
6+
IHttpOpenAiFunction,
7+
OpenAiTypeChecker,
8+
} from "@wrtnio/schema";
9+
10+
export const test_http_llm_separate_parameters_of_empty = (): void => {
11+
const document: OpenApi.IDocument = {
12+
openapi: "3.1.0",
13+
"x-samchon-emended": true,
14+
components: {},
15+
paths: {
16+
"/": {
17+
post: {
18+
requestBody: {
19+
content: {
20+
"application/json": {
21+
schema: {
22+
type: "object",
23+
properties: {},
24+
required: [],
25+
},
26+
},
27+
},
28+
},
29+
},
30+
},
31+
},
32+
};
33+
const app: IHttpOpenAiApplication = HttpOpenAi.application({
34+
document,
35+
options: {
36+
separate: (schema) =>
37+
OpenAiTypeChecker.isString(schema) &&
38+
schema["x-wrtn-secret-key"] !== undefined,
39+
},
40+
});
41+
const func: IHttpOpenAiFunction = app.functions[0];
42+
TestValidator.equals("separated")(func.separated)({
43+
llm: [
44+
{
45+
schema: {
46+
type: "object",
47+
properties: {},
48+
required: [],
49+
additionalProperties: false,
50+
},
51+
index: 0,
52+
},
53+
],
54+
human: [],
55+
});
56+
};

0 commit comments

Comments
 (0)