@@ -1373,4 +1373,69 @@ describe("cli", () => {
13731373 expect ( profile ?. customHeaders ) . toEqual ( { "X-Custom-Id" : "abc123" , "X-Tenant" : "myorg" } ) ;
13741374 expect ( profile ?. commandPrefix ) . toBe ( "" ) ;
13751375 } ) ;
1376+
1377+ it . each ( [
1378+ {
1379+ label : "swagger 2.0 host" ,
1380+ spec : { swagger : "2.0" , host : "gitlab.com" , basePath : "/api/v4" , schemes : [ "https" ] , paths : { "/version" : { get : { summary : "v" } } } } ,
1381+ cmd : "version" ,
1382+ } ,
1383+ {
1384+ label : "openapi 3.0 root servers" ,
1385+ spec : { openapi : "3.0.0" , servers : [ { url : "https://public.example.com/api" } ] , paths : { "/status" : { get : { summary : "s" } } } } ,
1386+ cmd : "status" ,
1387+ } ,
1388+ ] ) ( "profile apiBaseUrl takes priority over $label" , async ( { spec, cmd } ) => {
1389+ const localDir = `${ cwd } /.ocli` ;
1390+ const cachePath = `${ localDir } /specs/p.json` ;
1391+ const capturedConfigs : unknown [ ] = [ ] ;
1392+ const fakeHttpClient : HttpClient = {
1393+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1394+ request : async ( config : any ) => {
1395+ capturedConfigs . push ( config ) ;
1396+ return { status : 200 , statusText : "OK" , headers : { } , config, data : { } } ;
1397+ } ,
1398+ } ;
1399+ const { profileStore, openapiLoader } = createCliDeps ( cwd , homeDir , {
1400+ [ `${ localDir } /profiles.ini` ] : [ "[p]" , "api_base_url = https://self-hosted.example.com" , `openapi_spec_cache = ${ cachePath } ` , "" ] . join ( "\n" ) ,
1401+ [ cachePath ] : JSON . stringify ( spec ) ,
1402+ [ `${ localDir } /current` ] : "p" ,
1403+ } ) ;
1404+
1405+ await run ( [ cmd ] , { cwd, profileStore, openapiLoader, httpClient : fakeHttpClient , stdout : ( ) => { } } ) ;
1406+
1407+ const config = capturedConfigs [ 0 ] as { url : string } ;
1408+ expect ( config . url ) . toContain ( "self-hosted.example.com" ) ;
1409+ expect ( config . url ) . not . toContain ( "gitlab.com" ) ;
1410+ expect ( config . url ) . not . toContain ( "public.example.com" ) ;
1411+ } ) ;
1412+
1413+ it ( "path-level servers override profile apiBaseUrl" , async ( ) => {
1414+ const localDir = `${ cwd } /.ocli` ;
1415+ const cachePath = `${ localDir } /specs/ps.json` ;
1416+ const spec = {
1417+ openapi : "3.0.0" ,
1418+ servers : [ { url : "https://root.example.com" } ] ,
1419+ paths : { "/data" : { servers : [ { url : "https://path-override.example.com" } ] , get : { summary : "d" } } } ,
1420+ } ;
1421+
1422+ const capturedConfigs : unknown [ ] = [ ] ;
1423+ const fakeHttpClient : HttpClient = {
1424+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1425+ request : async ( config : any ) => {
1426+ capturedConfigs . push ( config ) ;
1427+ return { status : 200 , statusText : "OK" , headers : { } , config, data : { } } ;
1428+ } ,
1429+ } ;
1430+ const { profileStore, openapiLoader } = createCliDeps ( cwd , homeDir , {
1431+ [ `${ localDir } /profiles.ini` ] : [ "[ps]" , "api_base_url = https://profile.example.com" , `openapi_spec_cache = ${ cachePath } ` , "" ] . join ( "\n" ) ,
1432+ [ cachePath ] : JSON . stringify ( spec ) ,
1433+ [ `${ localDir } /current` ] : "ps" ,
1434+ } ) ;
1435+
1436+ await run ( [ "data" ] , { cwd, profileStore, openapiLoader, httpClient : fakeHttpClient , stdout : ( ) => { } } ) ;
1437+
1438+ const config = capturedConfigs [ 0 ] as { url : string } ;
1439+ expect ( config . url ) . toBe ( "https://path-override.example.com/data" ) ;
1440+ } ) ;
13761441} ) ;
0 commit comments