Module: Anthropic::Api::Concerns::Validatable
- Included in:
- Base
- Defined in:
- lib/anthropic/api/concerns/validatable.rb
Overview
Provides helpers for validating params against the API schema
Instance Method Summary collapse
Instance Method Details
#schema ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/anthropic/api/concerns/validatable.rb', line 15 def schema api_schema = version_config['schema'] unless api_schema raise Anthropic::Api::MissingSchemaError, "Missing schema for API version: #{Anthropic.api_version}" end if beta beta_schema = beta_config['schema'] raise Anthropic::Api::InvalidBetaConfigurationError, "Missing beta schema: #{beta}" unless beta_schema api_schema['properties'].merge!(beta_schema) end api_schema end |
#validate!(params) ⇒ Object
9 10 11 12 13 |
# File 'lib/anthropic/api/concerns/validatable.rb', line 9 def validate!(params) JSON::Validator.validate!(schema, params) rescue JSON::Schema::ValidationError => error raise Anthropic::Api::SchemaValidationError, error. end |