Module: Ghostcrawl::KiotaWriterFix Private
- Defined in:
- lib/ghostcrawl/client.rb
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Class Method Summary collapse
-
.jsonable(value) ⇒ Object
private
Recursively converts a value into a JSON-native structure (Hash/Array of plain scalars), so it round-trips through @writer.to_json intact.
Instance Method Summary collapse
-
#write_any_value(key, value) ⇒ Object
private
Fix 1c: the pinned Kiota writer's write_any_value (used by write_additional_data, i.e. EVERY field AdditionalDataBody sends) has no case for a plain Hash and mis-handles an Array of Hashes: * a Hash hits the
value.is_a? Objectbranch ->return value.to_s, which returns a string but NEVER assigns @writer -> the whole nested object is SILENTLY DROPPED from the request body. -
#write_collection_of_object_values(key, values) ⇒ Object
private
Fix 1b: the pinned Kiota writer's write_collection_of_object_values calls
self.write_object_value(nil, v).writeron each element — it relies on write_object_value(nil, ...) returning a writer object that responds to.writer. - #write_object_value(key, value) ⇒ Object private
Class Method Details
.jsonable(value) ⇒ Object
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.
Recursively converts a value into a JSON-native structure (Hash/Array of plain scalars), so it round-trips through @writer.to_json intact.
120 121 122 123 124 125 126 |
# File 'lib/ghostcrawl/client.rb', line 120 def self.jsonable(value) case value when Hash then value.each_with_object({}) { |(k, v), h| h[k.to_s] = jsonable(v) } when Array then value.map { |v| jsonable(v) } else value end end |
Instance Method Details
#write_any_value(key, value) ⇒ Object
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.
Fix 1c: the pinned Kiota writer's write_any_value (used by write_additional_data, i.e. EVERY field AdditionalDataBody sends) has no case for a plain Hash and mis-handles an Array of Hashes:
* a Hash hits the `value.is_a? Object` branch -> `return value.to_s`,
which returns a string but NEVER assigns @writer[key] -> the whole
nested object is SILENTLY DROPPED from the request body.
* an Array is sent to write_collection_of_primitive_values, which mangles
any non-primitive (Hash) element.
This drops/mangles every nested field the facade sends: scrape(extract_schema), extract(schema), crawl/crawl_runs opts, datasets.append(rows: [ .. ]), schedules.create(job_params: ..) — the last of which the API REQUIRES, so the request 422s ("job_params required") even though the caller supplied it.
Fix: intercept Hash and Array here and write a fully-recursed, JSON-native structure straight into @writer. The writer emits @writer.to_json at the end, so plain nested Hash/Array values serialize correctly. Everything else falls through to the upstream primitive handling.
108 109 110 111 112 113 114 115 |
# File 'lib/ghostcrawl/client.rb', line 108 def write_any_value(key, value) if value.is_a?(Hash) || value.is_a?(Array) return super unless key # nil-key arrays keep upstream behavior writer[key] = KiotaWriterFix.jsonable(value) return end super end |
#write_collection_of_object_values(key, values) ⇒ Object
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.
Fix 1b: the pinned Kiota writer's write_collection_of_object_values calls
self.write_object_value(nil, v).writer on each element — it relies on
write_object_value(nil, ...) returning a writer object that responds to
.writer. Our write_object_value override above (Fix 1) changes that
nil-key contract to serialize-into-self and return the serialize result
(a Hash / nil), so the upstream .writer call raises
NoMethodError: undefined method 'writer' for {}:Hash. That aborts
serialize for ANY response model carrying a collection of typed objects
(WebhookListResponse#items, etc.), which ResponseHelper.serialize_parsable
then swallows -> the facade returns {} and silently drops the whole list.
Fix: serialize each element into its OWN fresh writer and collect the raw
per-element hashes directly, never depending on the write_object_value
return contract. Mirrors the non-nil upstream branch (line 154) without the
broken .writer deref.
77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/ghostcrawl/client.rb', line 77 def write_collection_of_object_values(key, values) return unless values hashes = values.map do |v| temp = MicrosoftKiotaSerializationJson::JsonSerializationWriter.new v.serialize(temp) temp.writer end if key.nil? hashes else writer[key] = hashes end end |
#write_object_value(key, value) ⇒ Object
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.
52 53 54 55 56 57 58 59 60 |
# File 'lib/ghostcrawl/client.rb', line 52 def write_object_value(key, value) return unless value if key.nil? # Fix: serialize into self, not a temp. Merges all fields into @writer. value.serialize(self) else super end end |