11import { describe , it , expect } from 'bun:test'
2- import { getPossiblePath } from '../src/openapi'
2+ import { Kind } from '@sinclair/typebox'
3+ import { convertEnumToOpenApi , getPossiblePath } from '../src/openapi'
34
45describe ( 'OpenAPI utilities' , ( ) => {
56 it ( 'getPossiblePath' , ( ) => {
@@ -12,3 +13,62 @@ describe('OpenAPI utilities', () => {
1213 ] )
1314 } )
1415} )
16+
17+ describe ( 'convertEnumToOpenApi' , ( ) => {
18+ it ( 'should convert enum schema to OpenAPI enum format' , ( ) => {
19+ const expectedSchema = {
20+ [ Kind ] : 'Union' ,
21+ anyOf : [
22+ { const : 'male' } ,
23+ { const : 'female' }
24+ ]
25+ }
26+
27+ const result = convertEnumToOpenApi ( expectedSchema )
28+
29+ expect ( result ) . toEqual ( {
30+ type : 'string' ,
31+ enum : [ 'male' , 'female' ]
32+ } )
33+ } )
34+
35+ it ( 'should convert nested enums in object properties' , ( ) => {
36+ const expectedSchema = {
37+ type : 'object' ,
38+ properties : {
39+ name : { type : 'string' } ,
40+ gender : {
41+ [ Kind ] : 'Union' ,
42+ anyOf : [
43+ { const : 'male' } ,
44+ { const : 'female' }
45+ ]
46+ }
47+ }
48+ }
49+
50+ const result = convertEnumToOpenApi ( expectedSchema )
51+
52+ expect ( result ) . toEqual ( {
53+ type : 'object' ,
54+ properties : {
55+ name : { type : 'string' } ,
56+ gender : {
57+ type : 'string' ,
58+ enum : [ 'male' , 'female' ]
59+ }
60+ }
61+ } )
62+ } )
63+
64+ it ( 'should return original schema if not enum' , ( ) => {
65+ const expectedSchema = {
66+ type : 'string' ,
67+ description : 'Regular string field'
68+ }
69+
70+ const result = convertEnumToOpenApi ( expectedSchema )
71+
72+ expect ( result ) . toEqual ( expectedSchema )
73+ } )
74+ } )
0 commit comments