@@ -94,6 +94,15 @@ def _is_excluded(file_path: Path, root: Path, exclude_patterns: list[str]) -> bo
9494 return False
9595
9696
97+ def _get_glob_pattern (pat : str , recursive : bool ) -> str :
98+ """Get the glob pattern based on recursive flag."""
99+ if recursive and not pat .startswith ("**/" ):
100+ return f"**/{ pat } "
101+ if not recursive and pat .startswith ("**/" ):
102+ return pat [3 :] # Strip **/ prefix
103+ return pat
104+
105+
97106def _discover_resolver_files (
98107 path : str | Path ,
99108 pattern : str | list [str ],
@@ -110,18 +119,14 @@ def _discover_resolver_files(
110119 found_files : set [Path ] = set ()
111120
112121 for pat in patterns :
113- # Handle recursive flag: add **/ prefix if recursive, strip **/ if not
114- if recursive and not pat .startswith ("**/" ):
115- glob_pattern = f"**/{ pat } "
116- elif not recursive and pat .startswith ("**/" ):
117- glob_pattern = pat [3 :] # Strip **/ prefix
118- else :
119- glob_pattern = pat
120-
122+ glob_pattern = _get_glob_pattern (pat , recursive )
121123 for file_path in root .glob (glob_pattern ):
122- if file_path .is_file () and not _is_excluded (file_path , root , exclude ):
123- if _file_has_resolver (file_path , resolver_name ):
124- found_files .add (file_path )
124+ if (
125+ file_path .is_file ()
126+ and not _is_excluded (file_path , root , exclude )
127+ and _file_has_resolver (file_path , resolver_name )
128+ ):
129+ found_files .add (file_path )
125130
126131 return sorted (found_files )
127132
@@ -442,22 +447,7 @@ def _merge_schemas(self) -> dict[str, Any]:
442447 }
443448
444449 # Add optional info fields
445- if cfg .summary :
446- merged ["info" ]["summary" ] = cfg .summary
447- if cfg .description :
448- merged ["info" ]["description" ] = cfg .description
449- if cfg .terms_of_service :
450- merged ["info" ]["termsOfService" ] = cfg .terms_of_service
451- if cfg .contact :
452- merged ["info" ]["contact" ] = _model_to_dict (cfg .contact )
453- if cfg .license_info :
454- merged ["info" ]["license" ] = _model_to_dict (cfg .license_info )
455- if cfg .security :
456- merged ["security" ] = cfg .security
457- if cfg .external_documentation :
458- merged ["externalDocs" ] = _model_to_dict (cfg .external_documentation )
459- if cfg .openapi_extensions :
460- merged .update (cfg .openapi_extensions )
450+ self ._add_optional_info_fields (merged , cfg )
461451
462452 # Merge paths and components
463453 merged_paths : dict [str , Any ] = {}
@@ -477,12 +467,30 @@ def _merge_schemas(self) -> dict[str, Any]:
477467 merged ["components" ] = merged_components
478468
479469 # Merge tags
480- merged_tags = self ._merge_tags ()
481- if merged_tags :
470+ if merged_tags := self ._merge_tags ():
482471 merged ["tags" ] = merged_tags
483472
484473 return merged
485474
475+ def _add_optional_info_fields (self , merged : dict [str , Any ], cfg : OpenAPIConfig ) -> None :
476+ """Add optional fields from config to the merged schema."""
477+ if cfg .summary :
478+ merged ["info" ]["summary" ] = cfg .summary
479+ if cfg .description :
480+ merged ["info" ]["description" ] = cfg .description
481+ if cfg .terms_of_service :
482+ merged ["info" ]["termsOfService" ] = cfg .terms_of_service
483+ if cfg .contact :
484+ merged ["info" ]["contact" ] = _model_to_dict (cfg .contact )
485+ if cfg .license_info :
486+ merged ["info" ]["license" ] = _model_to_dict (cfg .license_info )
487+ if cfg .security :
488+ merged ["security" ] = cfg .security
489+ if cfg .external_documentation :
490+ merged ["externalDocs" ] = _model_to_dict (cfg .external_documentation )
491+ if cfg .openapi_extensions :
492+ merged .update (cfg .openapi_extensions )
493+
486494 def _merge_paths (self , source_paths : dict [str , Any ], target : dict [str , Any ]) -> None :
487495 """Merge paths from source into target."""
488496 for path , path_item in source_paths .items ():
0 commit comments