@@ -53,17 +53,41 @@ export class SchemaModifier {
5353 }
5454 }
5555
56- // Converts `oneOf` schemas with `const` values to boolean types.
57- // Example: oneof: [ {type: 'string', const: 'a'} ] to type: 'boolean' with title: 'schemaName_a'
56+ // Converts `oneOf` schemas with `const` values to enum types.
57+ // Example: oneof: [ {type: 'string', const: 'a'}, {type: 'string', const: 'b'} ] to enum: ['a', 'b']
58+ // For non-string types, uses the type as enum value
5859 handleOneOfConst ( schema : OpenAPIV3 . SchemaObject , schemaName : string ) : void {
5960 if ( schema . oneOf ) {
61+ const enumValues : string [ ] = [ ] ;
62+ let hasStringWithConst = false ;
63+
64+ // check if have string with const
6065 for ( const item of schema . oneOf ) {
6166 if ( item && ! ( '$ref' in item ) && item . type === 'string' && 'const' in item ) {
62- item . type = 'boolean' ;
63- item . title = compressMultipleUnderscores ( `${ schemaName } _${ item . const } ` ) ;
64- delete item . const ;
67+ hasStringWithConst = true ;
68+ break ;
6569 }
6670 }
71+
72+ // if found string+const, collect all values
73+ if ( hasStringWithConst ) {
74+ for ( const item of schema . oneOf ) {
75+ if ( item && ! ( '$ref' in item ) ) {
76+ if ( item . type === 'string' && 'const' in item ) {
77+ // use const value as enum value
78+ enumValues . push ( item . const as string ) ;
79+ } else if ( item . type ) {
80+ // use type name as enum value
81+ enumValues . push ( item . type ) ;
82+ }
83+ }
84+ }
85+
86+ // Convert to enum
87+ delete schema . oneOf ;
88+ schema . type = 'string' ;
89+ schema . enum = enumValues ;
90+ }
6791 }
6892 }
6993
0 commit comments