@@ -95,6 +95,76 @@ const noContentSuccessOpenApiFixture = JSON.stringify({
9595 } ,
9696} ) ;
9797
98+ const sharedRefOpenApiFixture = JSON . stringify ( {
99+ openapi : "3.1.0" ,
100+ info : {
101+ title : "Shared Ref API" ,
102+ version : "1.0.0" ,
103+ } ,
104+ servers : [
105+ {
106+ url : "https://api.example.test" ,
107+ } ,
108+ ] ,
109+ paths : {
110+ "/widgets/{widgetId}" : {
111+ get : {
112+ operationId : "getWidget" ,
113+ parameters : [
114+ {
115+ name : "widgetId" ,
116+ in : "path" ,
117+ required : true ,
118+ schema : {
119+ type : "string" ,
120+ } ,
121+ } ,
122+ ] ,
123+ responses : {
124+ "200" : {
125+ description : "Widget response" ,
126+ content : {
127+ "application/json" : {
128+ schema : {
129+ $ref : "#/components/schemas/Widget" ,
130+ } ,
131+ } ,
132+ } ,
133+ } ,
134+ } ,
135+ } ,
136+ } ,
137+ } ,
138+ components : {
139+ schemas : {
140+ Widget : {
141+ type : "object" ,
142+ required : [ "id" , "name" , "owner" ] ,
143+ properties : {
144+ id : {
145+ type : "string" ,
146+ } ,
147+ name : {
148+ type : "string" ,
149+ } ,
150+ owner : {
151+ $ref : "#/components/schemas/Owner" ,
152+ } ,
153+ } ,
154+ } ,
155+ Owner : {
156+ type : "object" ,
157+ required : [ "email" ] ,
158+ properties : {
159+ email : {
160+ type : "string" ,
161+ } ,
162+ } ,
163+ } ,
164+ } ,
165+ } ,
166+ } ) ;
167+
98168const makeSource = ( input : {
99169 id ?: string ;
100170 name ?: string ;
@@ -290,4 +360,57 @@ describe("openapi type contracts", () => {
290360 expect ( contract . output . typeDeclaration ) . not . toContain ( "data: unknown" ) ;
291361 expect ( contract . output . typePreview ) . toContain ( "data: null" ) ;
292362 } ) . pipe ( Effect . provide ( NodeFileSystem . layer ) ) ) ;
363+
364+ it . effect ( "preserves local component refs in IR and keeps executable bindings runtime-minimal" , ( ) =>
365+ Effect . gen ( function * ( ) {
366+ const source = makeSource ( {
367+ id : "source_shared_ref_api" ,
368+ name : "Shared Ref API" ,
369+ namespace : "shared-ref-api" ,
370+ } ) ;
371+ const manifest = yield * extractOpenApiManifest (
372+ source . name ,
373+ sharedRefOpenApiFixture ,
374+ ) ;
375+ const operations = compileOpenApiToolDefinitions ( manifest ) . map (
376+ openApiCatalogOperationFromDefinition ,
377+ ) ;
378+ const fragment = createOpenApiCatalogFragment ( {
379+ source,
380+ documents : [
381+ {
382+ documentKind : "openapi" ,
383+ documentKey : "https://example.com/shared-ref-openapi.json" ,
384+ fetchedAt : 0 ,
385+ contentText : sharedRefOpenApiFixture ,
386+ } ,
387+ ] ,
388+ operations,
389+ } ) ;
390+ const snapshot = snapshotFromSourceCatalogSyncResult (
391+ createSourceCatalogSyncResult ( {
392+ fragment,
393+ importMetadata : createCatalogImportMetadata ( {
394+ source,
395+ pluginKey : "openapi" ,
396+ } ) ,
397+ sourceHash : manifest . sourceHash ,
398+ } ) ,
399+ ) ;
400+
401+ const refShapes = Object . values ( snapshot . catalog . symbols ) . filter (
402+ ( symbol ) => symbol . kind === "shape" && symbol . node . type === "ref" ,
403+ ) ;
404+ expect ( refShapes . length ) . toBeGreaterThan ( 0 ) ;
405+
406+ const executable = Object . values ( snapshot . catalog . executables ) [ 0 ] ;
407+ expect ( executable ) . toBeDefined ( ) ;
408+ expect ( executable ?. binding ) . toMatchObject ( {
409+ kind : "openapi" ,
410+ toolId : "widgets.getWidget" ,
411+ } ) ;
412+ expect ( ( executable ?. binding as Record < string , unknown > ) . responses ) . toBeUndefined ( ) ;
413+ expect ( ( executable ?. binding as Record < string , unknown > ) . documentation ) . toBeUndefined ( ) ;
414+ expect ( JSON . stringify ( executable ?. binding ) . length ) . toBeLessThan ( 2_000 ) ;
415+ } ) ) ;
293416} ) ;
0 commit comments