Class: DiscoveryV1::Validation::ResolveSchemaRef Private
- Inherits:
-
Object
- Object
- DiscoveryV1::Validation::ResolveSchemaRef
- Defined in:
- lib/discovery_v1/validation/resolve_schema_ref.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Resolve a JSON schema reference to a Google Discovery V1 API schema
This class uses the Google Discovery V1 API to get the schemas. Any schema reference
in the form { "$ref": "schema_name" }
will be resolved by looking up the schema
name in the Google Discovery V1 API and returning the schema object (as a Hash).
This means that { "$ref": "cell_data" }
is resolved by returning
DiscoveryV1::Validation::LoadSchemas.new(logger:).call['cell_data']
.
An RuntimeError is raised if DiscoveryV1::Validation::LoadSchemas.new.call
does not have a key matching the schema name.
Instance Attribute Summary collapse
-
#logger ⇒ Logger
readonly
private
The logger to use internally.
-
#rest_description ⇒ Google::Apis::DiscoveryV1::RestDescription
readonly
private
The Google Discovery V1 API description to load schemas from.
Instance Method Summary collapse
-
#call(ref) ⇒ Hash
private
Resolve a JSON schema reference.
-
#initialize(rest_description:, logger: Logger.new(nil)) ⇒ ResolveSchemaRef
constructor
private
Create a new schema resolver.
Constructor Details
#initialize(rest_description:, logger: Logger.new(nil)) ⇒ ResolveSchemaRef
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Create a new schema resolver
41 42 43 44 |
# File 'lib/discovery_v1/validation/resolve_schema_ref.rb', line 41 def initialize(rest_description:, logger: Logger.new(nil)) @rest_description = rest_description @logger = logger end |
Instance Attribute Details
#logger ⇒ Logger (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The logger to use internally
Currently, only debug messages are logged.
65 66 67 |
# File 'lib/discovery_v1/validation/resolve_schema_ref.rb', line 65 def logger @logger end |
#rest_description ⇒ Google::Apis::DiscoveryV1::RestDescription (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The Google Discovery V1 API description to load schemas from
55 56 57 |
# File 'lib/discovery_v1/validation/resolve_schema_ref.rb', line 55 def rest_description @rest_description end |
Instance Method Details
#call(ref) ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Resolve a JSON schema reference
75 76 77 78 79 80 81 82 |
# File 'lib/discovery_v1/validation/resolve_schema_ref.rb', line 75 def call(ref) schema_name = ref.path[1..] logger.debug { "Reading schema #{schema_name}" } schemas = DiscoveryV1::Validation::LoadSchemas.new(rest_description:, logger:).call schemas[schema_name].tap do |schema_object| raise "Schema for #{ref} not found" unless schema_object end end |