microsoft / microsoft/kiota-ruby

Request body is an empty hash

Open
#122 13 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug Standard GitHub label
Dominant language
Ruby
Stars
5
Forks
8
Avg merge
11h 9m
Merged PRs (30d)
24

Description

When constructing a serialized request body, the body is empty because of these lines here:

https://github.com/microsoft/kiota-abstractions-ruby/blob/v0.14.3/lib/microsoft_kiota_abstractions/request_information.rb#L94-L107

        writer  = request_adapter.get_serialization_writer_factory().get_serialization_writer(content_type)
        @headers.try_add(@@content_type_header, content_type)
        if values != nil && values.kind_of?(Array)
          writer.write_collection_of_object_values(nil, values)
        else
          writer.write_object_value(nil, values);
        end
        this.content = writer.get_serialized_content();

The calls to writer.write_collection_of_object_values and writer.write_object_value with a nil key will return a new writer object, thus this.content = writer.get_serialized_content(); will be empty because it doesn't get written to the original writer.

The new writer objects are constructed here:

https://github.com/microsoft/kiota-serialization-json-ruby/blob/v0.7.0/lib/microsoft_kiota_serialization_json/json_serialization_writer.rb#L162-L165

    def write_object_value(key, value)
      if value
        if !key
          temp = JsonSerializationWriter.new()
          value.serialize(temp)
          return temp
        end
        begin
          temp = JsonSerializationWriter.new()
          value.serialize(temp)
          @writer[key] = temp.writer
        rescue StandardError => e
          raise e.class, "no key or value included in write_boolean_value(key, value)" 
        end
      end
    end

and here:

https://github.com/microsoft/kiota-serialization-json-ruby/blob/v0.7.0/lib/microsoft_kiota_serialization_json/json_serialization_writer.rb#L149-L152

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in lib/microsoft_kiota_abstractions/request_information.rb around lines 94-107, then inspect the referenced write_object_value and write_collection_of_object_values methods in the JSON serialization writer. Reproduce the request-body construction and verify that serialized object and collection values are retained in the final content rather than producing an empty body.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.