@@ -42,12 +42,27 @@ export function parseOpenApiSpec(spec: any, baseUrl?: string): ApiDescriptor {
4242 const topLevelSecurity = ! ! ( spec . security && spec . security . length > 0 ) ;
4343
4444 const paths = spec . paths || { } ;
45- for ( const [ path , methods ] of Object . entries < any > ( paths ) ) {
46- for ( const [ httpMethod , operation ] of Object . entries < any > ( methods ) ) {
47- // Skip non-HTTP-method keys like "parameters"
45+ for ( const [ path , pathItem ] of Object . entries < any > ( paths ) ) {
46+ if ( ! pathItem || typeof pathItem !== 'object' ) {
47+ continue ;
48+ }
49+ const pathServerUrl = Array . isArray ( pathItem . servers ) && pathItem . servers [ 0 ] ?. url
50+ ? String ( pathItem . servers [ 0 ] . url ) . replace ( / \/ $ / , '' )
51+ : undefined ;
52+
53+ for ( const [ httpMethod , operation ] of Object . entries < any > ( pathItem ) ) {
54+ // Skip non-HTTP-method keys like "parameters", "servers"
4855 if ( ! [ 'get' , 'post' , 'put' , 'patch' , 'delete' ] . includes ( httpMethod . toLowerCase ( ) ) ) {
4956 continue ;
5057 }
58+ if ( ! operation || typeof operation !== 'object' ) {
59+ continue ;
60+ }
61+
62+ const opServerUrl = Array . isArray ( operation . servers ) && operation . servers [ 0 ] ?. url
63+ ? String ( operation . servers [ 0 ] . url ) . replace ( / \/ $ / , '' )
64+ : undefined ;
65+ const endpointBaseUrl = opServerUrl || pathServerUrl ;
5166
5267 const name = operation . operationId || generateMethodName ( httpMethod , path ) ;
5368 const isPrivate = operation . security !== undefined
@@ -59,6 +74,7 @@ export function parseOpenApiSpec(spec: any, baseUrl?: string): ApiDescriptor {
5974 path,
6075 isPrivate,
6176 operationId : operation . operationId ,
77+ ...( endpointBaseUrl ? { baseUrl : endpointBaseUrl } : { } ) ,
6278 } ;
6379 }
6480 }
0 commit comments