11import type { Symbol } from '@hey-api/codegen-core' ;
2- import { refs } from '@hey-api/codegen-core' ;
3- import type { IR } from '@hey-api/shared' ;
4- import type { SchemaWithType } from '@hey-api/shared' ;
5- import { applyNaming } from '@hey-api/shared' ;
6- import { deduplicateSchema } from '@hey-api/shared' ;
2+ import { fromRef , refs } from '@hey-api/codegen-core' ;
3+ import type { IR , SchemaWithType } from '@hey-api/shared' ;
4+ import { applyNaming , deduplicateSchema , pathToJsonPointer } from '@hey-api/shared' ;
75
86import type { MaybeTsDsl , TypeTsDsl } from '../../../../ts-dsl' ;
97import { $ } from '../../../../ts-dsl' ;
@@ -18,10 +16,23 @@ import { irSchemaWithTypeToAst } from './toAst';
1816export function irSchemaToAst ( {
1917 plugin,
2018 schema,
19+ schemaExtractor,
2120 state,
2221} : IrSchemaToAstOptions & {
2322 schema : IR . SchemaObject ;
2423} ) : MaybeTsDsl < TypeTsDsl > {
24+ if ( schemaExtractor && ! schema . $ref ) {
25+ const extracted = schemaExtractor ( {
26+ meta : {
27+ resource : 'definition' ,
28+ resourceId : pathToJsonPointer ( fromRef ( state . path ) ) ,
29+ } ,
30+ path : fromRef ( state . path ) ,
31+ schema,
32+ } ) ;
33+ if ( extracted !== schema ) schema = extracted ;
34+ }
35+
2536 if ( schema . symbolRef ) {
2637 const baseType = $ . type ( schema . symbolRef ) ;
2738 if ( schema . omit && schema . omit . length > 0 ) {
0 commit comments