Module: SwaggerMCPTool::Helpers::SwaggerValidator
- Included in:
- ToolGenerator
- Defined in:
- lib/swagger_mcp_tool/helpers/swagger_validator.rb
Overview
Provides validation methods for Swagger (OpenAPI) specification structures. This module includes methods to validate the overall structure of a Swagger spec, ensure required keys are present, and check the structure of the ‘paths’ section. Intended to be included in classes that require Swagger spec validation logic.
Example usage:
include SwaggerValidator
validate_swagger_spec!(swagger_spec_hash)
Raises ArgumentError if the spec or paths are invalid.
Instance Method Summary collapse
- #validate_paths_structure!(paths) ⇒ Object
- #validate_spec_structure!(swagger_spec) ⇒ Object
- #validate_swagger_spec!(swagger_spec) ⇒ Object
Instance Method Details
#validate_paths_structure!(paths) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/swagger_mcp_tool/helpers/swagger_validator.rb', line 33 def validate_paths_structure!(paths) raise ArgumentError, 'Paths must be a Hash' unless paths.is_a?(Hash) return unless paths.empty? @config.logger.warn 'No paths found in Swagger spec' end |
#validate_spec_structure!(swagger_spec) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/swagger_mcp_tool/helpers/swagger_validator.rb', line 25 def validate_spec_structure!(swagger_spec) raise ArgumentError, 'Swagger spec must be a Hash' unless swagger_spec.is_a?(Hash) return if swagger_spec.key?('paths') raise ArgumentError, 'Swagger spec must contain paths' end |
#validate_swagger_spec!(swagger_spec) ⇒ Object
20 21 22 23 |
# File 'lib/swagger_mcp_tool/helpers/swagger_validator.rb', line 20 def validate_swagger_spec!(swagger_spec) validate_spec_structure!(swagger_spec) validate_paths_structure!(swagger_spec['paths']) end |