Class: OpenapiFirst::SchemaValidation
- Inherits:
-
Object
- Object
- OpenapiFirst::SchemaValidation
- Defined in:
- lib/openapi_first/schema_validation.rb
Constant Summary collapse
- SCHEMAS =
{ '3.1' => 'https://spec.openapis.org/oas/3.1/dialect/base', '3.0' => 'json-schemer://openapi30/schema' }.freeze
Instance Attribute Summary collapse
-
#raw_schema ⇒ Object
readonly
Returns the value of attribute raw_schema.
Instance Method Summary collapse
-
#initialize(schema, openapi_version:, write: true) ⇒ SchemaValidation
constructor
A new instance of SchemaValidation.
- #validate(data) ⇒ Object
Constructor Details
#initialize(schema, openapi_version:, write: true) ⇒ SchemaValidation
Returns a new instance of SchemaValidation.
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/openapi_first/schema_validation.rb', line 15 def initialize(schema, openapi_version:, write: true) @raw_schema = schema @schemer = JSONSchemer.schema( schema, access_mode: write ? 'write' : 'read', meta_schema: SCHEMAS.fetch(openapi_version), insert_property_defaults: true, output_format: 'detailed', before_property_validation: method(:before_property_validation) ) end |
Instance Attribute Details
#raw_schema ⇒ Object (readonly)
Returns the value of attribute raw_schema.
8 9 10 |
# File 'lib/openapi_first/schema_validation.rb', line 8 def raw_schema @raw_schema end |
Instance Method Details
#validate(data) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/openapi_first/schema_validation.rb', line 27 def validate(data) ValidationResult.new( output: @schemer.validate(data), schema: raw_schema, data: ) end |