@@ -456,7 +456,9 @@ describe('convertV2WithTypes', function() {
456456
457457 it ( 'should resolve extractedTypes into correct schema structure' , function ( done ) {
458458 const expectedExtractedTypes = {
459- 'get/pets' : {
459+ // `GET /pets` overrides the server URL with `http://petstore3.swagger.io/{v3}`, so its
460+ // resolved request path (and therefore its type-data key) carries the `:v3` server segment.
461+ 'get/:v3/pets' : {
460462 'request' : {
461463 'headers' : '[\n {\n "keyName": "variable",\n "properties": {\n "type": "array"\n }\n }\n]' ,
462464 'pathParam' : '[]' ,
@@ -539,6 +541,57 @@ describe('convertV2WithTypes', function() {
539541 ) ;
540542 } ) ;
541543
544+ it ( 'should key extractedTypes by the resolved request path when an operation overrides the server URL with path segments' , function ( done ) {
545+ // An operation-level server URL with path segments (e.g. `/eslsvc/api/v3`) gets resolved
546+ // directly into the request URL, while a top-level server is surfaced via the `{{baseUrl}}`
547+ // host. The extracted-type identifier must mirror the request's resolved path (Url#getPath) in
548+ // both cases so consumers can map the types back to the generated requests.
549+ const openapi = {
550+ openapi : '3.0.0' ,
551+ info : { title : 'Operation level servers' , version : '1.0.0' } ,
552+ servers : [ { url : 'https://top.example.com/v1' } ] ,
553+ paths : {
554+ '/profile-preferences' : {
555+ get : {
556+ servers : [ { url : 'https://apiintqa.hmhs.com/eslsvc/api/v3' } ] ,
557+ responses : {
558+ 200 : {
559+ description : 'ok' ,
560+ content : { 'application/json' : { schema : { type : 'object' , properties : { a : { type : 'string' } } } } }
561+ }
562+ }
563+ }
564+ } ,
565+ '/pets' : {
566+ get : {
567+ responses : {
568+ 200 : {
569+ description : 'ok' ,
570+ content : { 'application/json' : { schema : { type : 'object' , properties : { id : { type : 'integer' } } } } }
571+ }
572+ }
573+ }
574+ }
575+ }
576+ } ,
577+ options = { folderStrategy : 'Paths' , schemaFaker : true } ;
578+
579+ Converter . convertV2WithTypes ( { type : 'json' , data : openapi } , options , ( err , conversionResult ) => {
580+ expect ( err ) . to . be . null ;
581+ expect ( conversionResult . extractedTypes ) . to . be . an ( 'object' ) . that . is . not . empty ;
582+
583+ const typeKeys = Object . keys ( conversionResult . extractedTypes ) ;
584+
585+ // Operation-level server path segments are part of the key (matches the request's getPath).
586+ expect ( typeKeys ) . to . include ( 'get/eslsvc/api/v3/profile-preferences' ) ;
587+ // Top-level server stays behind {{baseUrl}}, so its key is just the spec path.
588+ expect ( typeKeys ) . to . include ( 'get/pets' ) ;
589+ expect ( typeKeys ) . to . not . include ( 'get/profile-preferences' ) ;
590+
591+ done ( ) ;
592+ } ) ;
593+ } ) ;
594+
542595 describe ( 'composite schema support (anyOf, oneOf, allOf)' , function ( ) {
543596 it ( 'should extract anyOf schemas in request body' , function ( done ) {
544597 const openApiWithAnyOf = {
0 commit comments