Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
### Changed
- Restructured the API methods and modules to be more efficient and intuitive ([261](https://github.com/opensearch-project/opensearch-ruby/pull/261))
- Moved ignore-404-on-deletion feature into the client options ([#277](https://github.com/opensearch-project/opensearch-ruby/pull/277))
- Changed the default json serializer from `multi_json` to the `json` gem ([#290](https://github.com/opensearch-project/opensearch-ruby/pull/290))
### Removed
- Removed support for Ruby 2.x ([261](https://github.com/opensearch-project/opensearch-ruby/pull/261))
- Removed the ability to ignore any error code by passing the `ignore: Array<error_code>` to each API method invocation ([#277](https://github.com/opensearch-project/opensearch-ruby/pull/277))
Expand Down
1 change: 1 addition & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Major versions of OpenSearch introduce breaking changes that require careful upg
- The lesser-known ability to ignore any error code by passing the `ignore: Array<error_code>` to each API method invocation is deemed unnecessary and dangerous. This feature has been removed in OpenSearch Ruby 4.
- The ability to pass an `opaque_id` parameter into an API method invocation to set the value of the `X-Opaque-Id` header has been removed. The user should now set the `X-Opaque-Id` header as part of the `headers` parameter in the API method invocation directly.
- OpenSearch Ruby 4 received a major refactor to remove middle-man `perform_request` methods. While this does not affect the vast majority of use cases, applications or wrappers that rely on these methods should be updated. For more information, check the `How the perform_request method is invoked` section of this [PR](https://github.com/opensearch-project/opensearch-ruby/pull/261).
- The default serializer was switched from `multi_json` to the `json` gem. If you want to still use `multi_json`, you can easily achieve it by implementing a [custom serializer](guides/transport_options.md#serializer-implementations).
## Upgrade to OpenSearch Ruby 3
In Version 3 of the OpenSearch Ruby client, we have added the `api` and `transport` modules as the core components of the gem, instead of treating them as separate gems that are required by the `opensearch-ruby` gem. This removes the confusions around compatibility between the ruby client, its legacy dependencies, and the OpenSearch cluster.

Expand Down
2 changes: 1 addition & 1 deletion api_generator/lib/templates/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module OpenSearch
{{/global_query_params}}
]).freeze

DEFAULT_SERIALIZER = MultiJson
DEFAULT_SERIALIZER = Transport::Transport::Serializer::JSON.new

def self.serializer
settings[:serializer] || DEFAULT_SERIALIZER
Expand Down
2 changes: 1 addition & 1 deletion guides/transport_options.md
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ You can write your own transport implementation easily, by including the {OpenSe

### Serializer Implementations

By default, the [MultiJSON](http://rubygems.org/gems/multi_json) library is used as the serializer implementation, and it will pick up the "right" adapter based on gems available.
By default, the [json](https://rubygems.org/gems/json) library is used as the serializer implementation.

The serialization component is pluggable, though, so you can write your own by including the {OpenSearch::Transport::Transport::Serializer::Base} module, implementing the required contract, and passing it to the client as the `serializer_class` or `serializer` parameter.

Expand Down
2 changes: 1 addition & 1 deletion lib/opensearch/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module API
'filter_path' # Used to reduce the response. This parameter takes a comma-separated list of filters. It supports using wildcards to match any field or part of a field’s name. You can also exclude fields with "-".
]).freeze

DEFAULT_SERIALIZER = MultiJson
DEFAULT_SERIALIZER = Transport::Transport::Serializer::JSON.new

def self.serializer
settings[:serializer] || DEFAULT_SERIALIZER
Expand Down
4 changes: 2 additions & 2 deletions lib/opensearch/transport.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
require 'uri'
require 'time'
require 'timeout'
require 'multi_json'
require 'json'
require 'faraday'

require 'opensearch/transport/transport/loggable'
require 'opensearch/transport/transport/serializer/multi_json'
require 'opensearch/transport/transport/serializer/json'
require 'opensearch/transport/transport/sniffer'
require 'opensearch/transport/transport/response'
require 'opensearch/transport/transport/errors'
Expand Down
2 changes: 1 addition & 1 deletion lib/opensearch/transport/transport/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module Base
DEFAULT_RELOAD_AFTER = 10_000 # Requests
DEFAULT_RESURRECT_AFTER = 60 # Seconds
DEFAULT_MAX_RETRIES = 3 # Requests
DEFAULT_SERIALIZER_CLASS = Serializer::MultiJson
DEFAULT_SERIALIZER_CLASS = Serializer::JSON
SANITIZED_PASSWORD = '*' * rand(1..14)

attr_reader :hosts, :options, :connections, :counter, :last_request_at, :protocol
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,25 @@ def initialize(transport = nil)
end
end

# A default JSON serializer (using [MultiJSON](http://rubygems.org/gems/multi_json))
# A default JSON serializer (using [json](http://rubygems.org/gems/json))
#
class MultiJson
class JSON
include Base

# De-serialize a Hash from JSON string
#
def load(string, options = {})
::MultiJson.load(string, options)
::JSON.parse(string, options)
end

# Serialize a Hash to JSON string
#
def dump(object, options = {})
::MultiJson.dump(object, options)
if options.delete(:pretty)
::JSON.pretty_generate(object, options)
else
::JSON.generate(object, options)
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/opensearch/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@
# under the License.

module OpenSearch
VERSION = '4.0.0-beta.4'.freeze
VERSION = '4.0.0-beta.5'.freeze
end
1 change: 0 additions & 1 deletion opensearch-ruby.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,4 @@ Gem::Specification.new do |s|

s.add_dependency 'faraday', '>= 1.0', '< 3'
s.add_dependency "logger"
s.add_dependency 'multi_json', '>= 1.0'
end
2 changes: 1 addition & 1 deletion spec/opensearch/api/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
end

it 'has a default serializer' do
expect(OpenSearch::API.serializer).to eq(MultiJson)
expect(OpenSearch::API.serializer).to be_a(OpenSearch::Transport::Transport::Serializer::JSON)
end

context 'when settings are changed' do
Expand Down
4 changes: 2 additions & 2 deletions spec/opensearch/api/utils_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,11 @@
end

let(:header) do
MultiJson.load(lines.first)
JSON.parse(lines.first)
end

let(:data_string) do
MultiJson.load(lines.last)
JSON.parse(lines.last)
end

it 'does not mutate the input' do
Expand Down
10 changes: 5 additions & 5 deletions test/transport/unit/serializer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ class OpenSearch::Transport::Transport::SerializerTest < Minitest::Test

context "Serializer" do

should "use MultiJson by default" do
::MultiJson.expects(:load)
::MultiJson.expects(:dump)
OpenSearch::Transport::Transport::Serializer::MultiJson.new.load('{}')
OpenSearch::Transport::Transport::Serializer::MultiJson.new.dump({})
should "use JSON by default" do
::JSON.expects(:parse)
::JSON.expects(:generate)
OpenSearch::Transport::Transport::Serializer::JSON.new.load('{}')
OpenSearch::Transport::Transport::Serializer::JSON.new.dump({})
end

end
Expand Down