Module: Prmd::Verification
- Defined in:
- lib/prmd/commands/verify.rb
Overview
Schema Verification
Constant Summary collapse
- SCHEMAS =
These schemas are listed manually and in order because they reference each other.
[ 'schema.json', 'hyper-schema.json', 'interagent-hyper-schema.json' ]
Class Method Summary collapse
- .add_schema(store, file) ⇒ Object
- .document_store ⇒ JsonSchema::DocumentStore
- .init_document_store ⇒ JsonSchema::DocumentStore
-
.verify(schema_data, custom_schema: nil) ⇒ Array<String>
Verfies that a given schema is valid.
-
.verify_meta_schema(meta_schema, schema_data) ⇒ Array<String>
Errors from failed verfication.
-
.verify_parsable(schema_data) ⇒ Array<String>
Errors from failed verfication.
-
.verify_schema(schema_data) ⇒ Array<String>
Errors from failed verfication.
Class Method Details
.add_schema(store, file) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/prmd/commands/verify.rb', line 27 def self.add_schema(store, file) data = JSON.parse(File.read(file)) schema = JsonSchema::Parser.new.parse!(data) schema.(store: store) store.add_schema(schema) end |
.document_store ⇒ JsonSchema::DocumentStore
35 36 37 |
# File 'lib/prmd/commands/verify.rb', line 35 def self.document_store @document_store ||= init_document_store end |
.init_document_store ⇒ JsonSchema::DocumentStore
17 18 19 20 21 22 23 24 25 |
# File 'lib/prmd/commands/verify.rb', line 17 def self.init_document_store store = JsonSchema::DocumentStore.new SCHEMAS.each do |file| file = File.("../../../../schemas/#{file}", __FILE__) add_schema(store, file) end add_schema(store, @custom_schema) unless @custom_schema.nil? store end |
.verify(schema_data, custom_schema: nil) ⇒ Array<String>
Verfies that a given schema is valid
78 79 80 81 82 83 84 85 |
# File 'lib/prmd/commands/verify.rb', line 78 def self.verify(schema_data, custom_schema: nil) @custom_schema = custom_schema a = verify_schema(schema_data) return a unless a.empty? b = verify_parsable(schema_data) return b unless b.empty? [] end |
.verify_meta_schema(meta_schema, schema_data) ⇒ Array<String>
Returns errors from failed verfication.
55 56 57 58 59 60 |
# File 'lib/prmd/commands/verify.rb', line 55 def self.(, schema_data) valid, errors = .validate(schema_data) return JsonSchema::SchemaError.aggregate(errors) unless valid [] end |
.verify_parsable(schema_data) ⇒ Array<String>
Returns errors from failed verfication.
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/prmd/commands/verify.rb', line 41 def self.verify_parsable(schema_data) # for good measure, make sure that the schema parses and that its # references can be expanded schema, errors = JsonSchema.parse!(schema_data) return JsonSchema::SchemaError.aggregate(errors) unless schema valid, errors = schema.(store: document_store) return JsonSchema::SchemaError.aggregate(errors) unless valid [] end |
.verify_schema(schema_data) ⇒ Array<String>
Returns errors from failed verfication.
64 65 66 67 68 69 70 71 72 |
# File 'lib/prmd/commands/verify.rb', line 64 def self.verify_schema(schema_data) schema_uri = schema_data['$schema'] return ['Missing $schema key.'] unless schema_uri = document_store.lookup_schema(schema_uri) return ["Unknown $schema: #{schema_uri}."] unless (, schema_data) end |