@@ -137,18 +137,23 @@ function transformSchemaObjectWithComposition(
137137 ( v ) => typeof v === 'string' || typeof v === 'number'
138138 )
139139 ) {
140- let enumValuesVariableName = parseRef ( options . path ?? '' ) . pointer . join (
141- '/'
142- ) ;
140+ const parsed = parseRef ( options . path ?? '' ) ;
141+ let enumValuesVariableName = parsed . pointer . join ( '/' ) ;
143142 enumValuesVariableName = enumValuesVariableName . replace (
144143 'components/schemas' ,
145144 ''
146145 ) ;
147146 enumValuesVariableName = `${ enumValuesVariableName } Values` ;
147+ const { cleanedRefPath, extractProperties } = createEnumValuesRefOptions (
148+ parsed . pointer
149+ ) ;
148150
149151 const enumValuesArray = tsArrayLiteralExpression (
150152 enumValuesVariableName ,
151- oapiRef ( options . path ?? '' ) ,
153+ oapiRef ( cleanedRefPath , undefined , {
154+ deep : true ,
155+ extractProperties,
156+ } ) ,
152157 schemaObject . enum as ( string | number ) [ ] ,
153158 {
154159 export : true ,
@@ -531,3 +536,47 @@ function hasKey<K extends string>(
531536 key in possibleObject
532537 ) ;
533538}
539+
540+ function createEnumValuesRefOptions ( pointer : string [ ] ) : {
541+ cleanedRefPath : string ;
542+ extractProperties : string [ ] ;
543+ } {
544+ // Keep this logic in sync with upstream openapi-typescript enum-values
545+ // handling:
546+ // https://github.com/openapi-ts/openapi-typescript/blob/v7.13.0/packages/openapi-typescript/src/transform/schema-object.ts
547+ const cleanedPointer : string [ ] = [ ] ;
548+ const extractProperties : string [ ] = [ ] ;
549+
550+ for ( let i = 0 ; i < pointer . length ; i ++ ) {
551+ const segment = pointer [ i ] ;
552+
553+ if (
554+ ( segment === 'anyOf' || segment === 'oneOf' ) &&
555+ i < pointer . length - 1
556+ ) {
557+ const next = pointer [ i + 1 ] ;
558+
559+ if ( / ^ \d + $ / . test ( next ) ) {
560+ i ++ ;
561+
562+ // Collect every remaining real property segment after the union index.
563+ // We skip union markers and numeric indices themselves.
564+ const remainingSegments = pointer . slice ( i + 1 ) ;
565+ for ( const seg of remainingSegments ) {
566+ if ( seg !== 'anyOf' && seg !== 'oneOf' && ! / ^ \d + $ / . test ( seg ) ) {
567+ extractProperties . push ( seg ) ;
568+ }
569+ }
570+
571+ continue ;
572+ }
573+ }
574+
575+ cleanedPointer . push ( segment ) ;
576+ }
577+
578+ return {
579+ cleanedRefPath : createRef ( cleanedPointer ) ,
580+ extractProperties,
581+ } ;
582+ }
0 commit comments