class RailsToolViews::Schema
Validates a bounded, closed JSON contract.
Constants
- COMBINATORS
- KEYWORDS
- TYPES
Attributes
Public Class Methods
Source
# File lib/rails_tool_views/core.rb, line 129 def initialize(schema) @json = Data.bounded(schema) inspect_schema!(@json) raise Error.new("INVALID_SCHEMA") unless @json["type"] == "object" && @json["additionalProperties"] == false @validator = JSONSchemer.schema(@json, ref_resolver: ->(_uri) { raise Error.new("INVALID_SCHEMA") }) raise Error.new("INVALID_SCHEMA") unless @validator.valid_schema? Data.freeze_deep(@json) rescue JSONSchemer::UnknownRef, ArgumentError raise Error.new("INVALID_SCHEMA") end
Builds a closed schema; rejects unsupported or unbounded nested contracts.
Public Instance Methods
# File lib/rails_tool_views/core.rb, line 140 def validate!(value, code: "INVALID_PROPS") data = Data.bounded(value) raise Error.new(code) unless @validator.valid?(data) data end
Returns normalized validated data, or raises Error with the supplied code.