Class: AsyncapiCable::Runtime::PayloadValidator
- Inherits:
-
Object
- Object
- AsyncapiCable::Runtime::PayloadValidator
- Defined in:
- lib/asyncapi_cable/runtime/payload_validator.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#validate(payload, schema_name, components) ⇒ Object
Validates
payloadagainst#/components/schemas/<schema_name>of the passed-incomponentshash (sourced from the committed YAML, not the live component registry — see exec-plan D4).
Class Method Details
.instance ⇒ Object
7 8 9 |
# File 'lib/asyncapi_cable/runtime/payload_validator.rb', line 7 def instance @instance ||= new end |
.reset! ⇒ Object
11 12 13 |
# File 'lib/asyncapi_cable/runtime/payload_validator.rb', line 11 def reset! @instance = nil end |
Instance Method Details
#validate(payload, schema_name, components) ⇒ Object
Validates payload against #/components/schemas/<schema_name> of
the passed-in components hash (sourced from the committed YAML, not
the live component registry — see exec-plan D4). The JSONSchemer
document is memoized per components object so repeated broadcasts on
the same contract reuse one compiled schema.
21 22 23 24 25 |
# File 'lib/asyncapi_cable/runtime/payload_validator.rb', line 21 def validate(payload, schema_name, components) normalized = stringify_keys(payload) ref = "#/components/schemas/#{schema_name}" schemer_for(components).ref(ref).validate(normalized).to_a end |