Skip to content
This repository was archived by the owner on Jan 6, 2025. It is now read-only.

Commit d3ef8ed

Browse files
authored
Merge pull request #20 from wrtnio/feature/strict
Add `strict` property on function schema.
2 parents 356d853 + 3bb8587 commit d3ef8ed

File tree

6 files changed

+70
-9
lines changed

6 files changed

+70
-9
lines changed

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@wrtnio/openai-function-schema",
3-
"version": "0.2.3",
3+
"version": "0.2.4",
44
"description": "OpenAI LLM function schema from OpenAPI (Swagger) document",
55
"main": "lib/index.js",
66
"typings": "lib/index.d.ts",
@@ -37,16 +37,16 @@
3737
"author": "",
3838
"license": "ISC",
3939
"dependencies": {
40-
"@nestia/fetcher": "^3.8.0",
41-
"@samchon/openapi": "^0.4.2",
40+
"@nestia/fetcher": "^3.10.0",
41+
"@samchon/openapi": "^0.4.3",
4242
"commander": "^10.0.0",
4343
"inquirer": "^8.2.5",
44-
"typia": "^6.5.4"
44+
"typia": "^6.7.2"
4545
},
4646
"devDependencies": {
47-
"@nestia/core": "^3.8.0",
47+
"@nestia/core": "^3.10.0",
4848
"@nestia/e2e": "^0.7.0",
49-
"@nestia/sdk": "^3.8.0",
49+
"@nestia/sdk": "^3.10.0",
5050
"@nestjs/common": "^10.3.10",
5151
"@nestjs/core": "^10.3.10",
5252
"@nestjs/platform-express": "^10.3.10",

src/OpenAiComposer.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ export namespace OpenAiComposer {
165165
const downgraded: IOpenAiSchema = OpenApiV3Downgrader.downgradeSchema({
166166
original: {},
167167
downgraded: {},
168-
})(escaped);
168+
})(escaped) as IOpenAiSchema;
169169
OpenAiTypeChecker.visit(downgraded, (schema) => {
170170
if (
171171
OpenAiTypeChecker.isOneOf(schema) &&
@@ -240,6 +240,7 @@ export namespace OpenAiComposer {
240240
method: route.method as "get",
241241
path: route.path,
242242
name: route.accessor.join("_"),
243+
strict: true,
243244
parameters,
244245
separated: options.separate
245246
? OpenAiSchemaSeparator.parameters({
@@ -248,10 +249,10 @@ export namespace OpenAiComposer {
248249
})
249250
: undefined,
250251
output: output
251-
? OpenApiV3Downgrader.downgradeSchema({
252+
? (OpenApiV3Downgrader.downgradeSchema({
252253
original: {},
253254
downgraded: {},
254-
})(output)
255+
})(output) as IOpenAiSchema)
255256
: undefined,
256257
description: (() => {
257258
if (operation.summary && operation.description) {

src/structures/IOpenAiFunction.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,15 @@ export interface IOpenAiFunction {
6666
*/
6767
name: string;
6868

69+
/**
70+
* Whether the function schema types are strict or not.
71+
*
72+
* Newly added specification at 2024-08-07.
73+
*
74+
* @reference https://openai.com/index/introducing-structured-outputs-in-the-api/
75+
*/
76+
strict: true;
77+
6978
/**
7079
* List of parameter schemas.
7180
*/

test/keyword.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"method": "post",
66
"path": "/bbs/articles",
77
"name": "bbs_articles_post",
8+
"strict": true,
89
"parameters": [
910
{
1011
"type": "object",
@@ -299,6 +300,7 @@
299300
"method": "patch",
300301
"path": "/bbs/articles",
301302
"name": "bbs_articles_patch",
303+
"strict": true,
302304
"parameters": [
303305
{
304306
"type": "object",
@@ -445,6 +447,7 @@
445447
"method": "patch",
446448
"path": "/bbs/articles/abridges",
447449
"name": "bbs_articles_abridges_patch",
450+
"strict": true,
448451
"parameters": [
449452
{
450453
"type": "object",
@@ -728,6 +731,7 @@
728731
"method": "get",
729732
"path": "/bbs/articles/{id}",
730733
"name": "bbs_articles_getById",
734+
"strict": true,
731735
"parameters": [
732736
{
733737
"type": "object",
@@ -878,6 +882,7 @@
878882
"method": "put",
879883
"path": "/bbs/articles/{id}",
880884
"name": "bbs_articles_putById",
885+
"strict": true,
881886
"parameters": [
882887
{
883888
"type": "object",
@@ -1137,6 +1142,7 @@
11371142
"method": "delete",
11381143
"path": "/bbs/articles/{id}",
11391144
"name": "bbs_articles_eraseById",
1145+
"strict": true,
11401146
"parameters": [
11411147
{
11421148
"type": "object",
@@ -1195,6 +1201,7 @@
11951201
"method": "post",
11961202
"path": "/membership/join",
11971203
"name": "membership_join_post",
1204+
"strict": true,
11981205
"parameters": [
11991206
{
12001207
"type": "object",
@@ -1361,6 +1368,7 @@
13611368
"method": "patch",
13621369
"path": "/membership/login",
13631370
"name": "membership_login_patch",
1371+
"strict": true,
13641372
"parameters": [
13651373
{
13661374
"type": "object",
@@ -1480,6 +1488,7 @@
14801488
"method": "get",
14811489
"path": "/membership/{secret}",
14821490
"name": "membership_getBySecret",
1491+
"strict": true,
14831492
"parameters": [
14841493
{
14851494
"type": "object",
@@ -1554,6 +1563,7 @@
15541563
"method": "patch",
15551564
"path": "/membership/change",
15561565
"name": "membership_change_patch",
1566+
"strict": true,
15571567
"parameters": [
15581568
{
15591569
"type": "object",
@@ -1746,6 +1756,7 @@
17461756
"method": "patch",
17471757
"path": "/membership/{secret}/change",
17481758
"name": "membership_change_patchBySecret",
1759+
"strict": true,
17491760
"parameters": [
17501761
{
17511762
"type": "object",
@@ -1922,6 +1933,7 @@
19221933
"method": "post",
19231934
"path": "/multipart",
19241935
"name": "multipart_post",
1936+
"strict": true,
19251937
"parameters": [
19261938
{
19271939
"type": "object",
@@ -2090,6 +2102,7 @@
20902102
"method": "get",
20912103
"path": "/query/typed",
20922104
"name": "query_typed_get",
2105+
"strict": true,
20932106
"parameters": [
20942107
{
20952108
"type": "object",
@@ -2199,6 +2212,7 @@
21992212
"method": "get",
22002213
"path": "/query/nest",
22012214
"name": "query_nest_get",
2215+
"strict": true,
22022216
"parameters": [
22032217
{
22042218
"type": "object",
@@ -2316,6 +2330,7 @@
23162330
"method": "get",
23172331
"path": "/query/individual",
23182332
"name": "query_individual_get",
2333+
"strict": true,
23192334
"parameters": [
23202335
{
23212336
"type": "object",
@@ -2368,6 +2383,7 @@
23682383
"method": "get",
23692384
"path": "/query/composite/{id}",
23702385
"name": "query_composite_getById",
2386+
"strict": true,
23712387
"parameters": [
23722388
{
23732389
"type": "object",
@@ -2483,6 +2499,7 @@
24832499
"method": "post",
24842500
"path": "/query/body",
24852501
"name": "query_body_post",
2502+
"strict": true,
24862503
"parameters": [
24872504
{
24882505
"type": "object",

test/plain.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"method": "post",
66
"path": "/bbs/articles",
77
"name": "bbs_articles_post",
8+
"strict": true,
89
"parameters": [
910
{
1011
"type": "object",
@@ -204,6 +205,7 @@
204205
"method": "patch",
205206
"path": "/bbs/articles",
206207
"name": "bbs_articles_patch",
208+
"strict": true,
207209
"parameters": [
208210
{
209211
"type": "object",
@@ -316,6 +318,7 @@
316318
"method": "patch",
317319
"path": "/bbs/articles/abridges",
318320
"name": "bbs_articles_abridges_patch",
321+
"strict": true,
319322
"parameters": [
320323
{
321324
"type": "object",
@@ -522,6 +525,7 @@
522525
"method": "get",
523526
"path": "/bbs/articles/{id}",
524527
"name": "bbs_articles_getById",
528+
"strict": true,
525529
"parameters": [
526530
{
527531
"type": "string",
@@ -649,6 +653,7 @@
649653
"method": "put",
650654
"path": "/bbs/articles/{id}",
651655
"name": "bbs_articles_putById",
656+
"strict": true,
652657
"parameters": [
653658
{
654659
"type": "string",
@@ -813,6 +818,7 @@
813818
"method": "delete",
814819
"path": "/bbs/articles/{id}",
815820
"name": "bbs_articles_eraseById",
821+
"strict": true,
816822
"parameters": [
817823
{
818824
"type": "string",
@@ -837,6 +843,7 @@
837843
"method": "post",
838844
"path": "/membership/join",
839845
"name": "membership_join_post",
846+
"strict": true,
840847
"parameters": [
841848
{
842849
"type": "object",
@@ -926,6 +933,7 @@
926933
"method": "patch",
927934
"path": "/membership/login",
928935
"name": "membership_login_patch",
936+
"strict": true,
929937
"parameters": [
930938
{
931939
"type": "object",
@@ -992,6 +1000,7 @@
9921000
"method": "get",
9931001
"path": "/membership/{secret}",
9941002
"name": "membership_getBySecret",
1003+
"strict": true,
9951004
"parameters": [
9961005
{
9971006
"type": "string",
@@ -1043,6 +1052,7 @@
10431052
"method": "patch",
10441053
"path": "/membership/change",
10451054
"name": "membership_change_patch",
1055+
"strict": true,
10461056
"parameters": [
10471057
{
10481058
"type": "object",
@@ -1145,6 +1155,7 @@
11451155
"method": "patch",
11461156
"path": "/membership/{secret}/change",
11471157
"name": "membership_change_patchBySecret",
1158+
"strict": true,
11481159
"parameters": [
11491160
{
11501161
"type": "string",
@@ -1239,6 +1250,7 @@
12391250
"method": "post",
12401251
"path": "/multipart",
12411252
"name": "multipart_post",
1253+
"strict": true,
12421254
"parameters": [
12431255
{
12441256
"type": "object",
@@ -1333,6 +1345,7 @@
13331345
"method": "get",
13341346
"path": "/query/typed",
13351347
"name": "query_typed_get",
1348+
"strict": true,
13361349
"parameters": [
13371350
{
13381351
"type": "object",
@@ -1396,6 +1409,7 @@
13961409
"method": "get",
13971410
"path": "/query/nest",
13981411
"name": "query_nest_get",
1412+
"strict": true,
13991413
"parameters": [
14001414
{
14011415
"type": "object",
@@ -1463,6 +1477,7 @@
14631477
"method": "get",
14641478
"path": "/query/individual",
14651479
"name": "query_individual_get",
1480+
"strict": true,
14661481
"parameters": [
14671482
{
14681483
"type": "object",
@@ -1485,6 +1500,7 @@
14851500
"method": "get",
14861501
"path": "/query/composite/{id}",
14871502
"name": "query_composite_getById",
1503+
"strict": true,
14881504
"parameters": [
14891505
{
14901506
"type": "string",
@@ -1551,6 +1567,7 @@
15511567
"method": "post",
15521568
"path": "/query/body",
15531569
"name": "query_body_post",
1570+
"strict": true,
15541571
"parameters": [
15551572
{
15561573
"type": "object",

0 commit comments

Comments
 (0)