Skip to content

Commit

Permalink
# Fixed: Accessing param default values
Browse files Browse the repository at this point in the history
  • Loading branch information
nhtruong committed Dec 19, 2024
1 parent fc3f775 commit 1e438fa
Show file tree
Hide file tree
Showing 46 changed files with 94 additions and 92 deletions.
2 changes: 1 addition & 1 deletion api_generator/lib/components/argument.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def self.from_parameters(params, opts_count)
description: param.description || schema.description,
required: params.filter(&:required).size >= opts_count,
schema: schema,
default: param.default || schema.default,
default: param['default'] || schema['default'],
deprecated: param.deprecated || schema.deprecated,
deprecation_message: param['x-deprecation-message'] || schema['x-deprecation-message'],
location: params.any? { |p| p.in == 'path' } ? 'path' : 'query')
Expand Down
20 changes: 11 additions & 9 deletions api_generator/lib/spec_hash.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
# SPDX-License-Identifier: Apache-2.0
#
# The OpenSearch Contributors require contributions made to
# this file be licensed under the Apache-2.0 license or a
# compatible open source license.

# frozen_string_literal: true

require 'yaml'
require_relative 'components/namespace'
require_relative 'components/argument'

# Spec class for parsing OpenAPI spec
# It's basically a wrapper around a Hash that allows for accessing hash values as object attributes
# and resolving of $refs
class SpecHash
def self.load_file(file_path)
@raw = YAML.load_file(file_path)
Expand All @@ -26,6 +23,8 @@ class << self; attr_reader :parsed; end

attr_reader :hash

delegate :to_s, to: :hash

# @param [Hash] hash
def initialize(hash = {}, parsed: true)
@hash = parsed ? hash : parse(hash)
Expand All @@ -35,12 +34,15 @@ def [](key)
parse(@hash[key])
end

def respond_to_missing?(name, include_private = false)
@hash.key?(name.to_s) || @hash.respond_to?(name) || super
def respond_to_missing?(name)
@hash.key?(name.to_s) || {}.respond_to?(name) || super
end

def method_missing(name, ...)
return @hash.send(name, ...) if @hash.respond_to?(name)
if {}.respond_to?(name)
warn "Accessing Hash attribute `#{name}` which is also a key of the SpecHash instance." if @hash.key?(name.to_s)
return @hash.send(name, ...)
end
parse(@hash[name.to_s])
end

Expand Down
2 changes: 1 addition & 1 deletion lib/opensearch/api/actions/cat/health.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module Actions
# @option args [Boolean] :help Return help information.
# @option args [Enumerable<String>] :s Comma-separated list of column names or column aliases to sort by.
# @option args [String] :time The unit used to display time values.
# @option args [Boolean] :ts If `true`, returns `HH:MM:SS` and Unix epoch timestamps.
# @option args [Boolean] :ts (default: true) If `true`, returns `HH:MM:SS` and Unix epoch timestamps.
# @option args [Boolean] :v Verbose mode. Display column headers.
def health(args = {})
args = Utils.normalize_arguments(args)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module Cluster
module Actions
# Clears cluster voting config exclusions.
#
# @option args [Boolean] :wait_for_removal Specifies whether to wait for all excluded nodes to be removed from the cluster before clearing the voting configuration exclusions list. Defaults to true, meaning that all excluded nodes must be removed from the cluster before this API takes any action. If set to `false` then the voting configuration exclusions list is cleared even if some excluded nodes are still in the cluster.
# @option args [Boolean] :wait_for_removal (default: true) Specifies whether to wait for all excluded nodes to be removed from the cluster before clearing the voting configuration exclusions list. Defaults to true, meaning that all excluded nodes must be removed from the cluster before this API takes any action. If set to `false` then the voting configuration exclusions list is cleared even if some excluded nodes are still in the cluster.
# @option args [List] :ignore set to [404] to ignore server's NOT FOUND error for this request
def delete_voting_config_exclusions(args = {})
args = Utils.normalize_arguments(args)
Expand Down
2 changes: 1 addition & 1 deletion lib/opensearch/api/actions/count.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module Actions
# @option args [Boolean] :ignore_unavailable If `false`, the request returns an error if it targets a missing or closed index.
# @option args [Boolean] :lenient If `true`, format-based query failures (such as providing text to a numeric field) in the query string will be ignored.
# @option args [Float] :min_score Sets the minimum `_score` value that documents must have to be included in the result.
# @option args [String] :preference Specifies the node or shard the operation should be performed on. Random by default.
# @option args [String] :preference (default: random) Specifies the node or shard the operation should be performed on. Random by default.
# @option args [String] :q Query in the Lucene query string syntax.
# @option args [Enumerable<String>, String] :routing Custom value used to route operations to a specific shard.
# @option args [Integer] :terminate_after Maximum number of documents to collect for each shard. If a query reaches this limit, OpenSearch terminates the query early. OpenSearch collects documents before sorting.
Expand Down
2 changes: 1 addition & 1 deletion lib/opensearch/api/actions/create_pit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module Actions
# @option args [Boolean] :allow_partial_pit_creation Allow if point in time can be created with partial failures.
# @option args [Enumerable<String>, String] :expand_wildcards Whether to expand wildcard expression to concrete indexes that are open, closed or both.
# @option args [String] :keep_alive Specify the keep alive for point in time.
# @option args [String] :preference Specify the node or shard the operation should be performed on.
# @option args [String] :preference (default: random) Specify the node or shard the operation should be performed on.
# @option args [Enumerable<String>, String] :routing Comma-separated list of specific routing values.
def create_pit(args = {})
args = Utils.normalize_arguments(args)
Expand Down
10 changes: 5 additions & 5 deletions lib/opensearch/api/actions/delete_by_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ module Actions
# @option args [String] :default_operator The default operator for query string query: `AND` or `OR`.
# @option args [String] :df Field to use as default where no field prefix is given in the query string.
# @option args [Enumerable<String>, String] :expand_wildcards Type of index that wildcard patterns can match. If the request can target data streams, this argument determines whether wildcard expressions match hidden data streams. Supports comma-separated values, such as `open,hidden`. Valid values are: `all`, `open`, `closed`, `hidden`, `none`.
# @option args [Integer] :from Starting offset.
# @option args [Integer] :from (default: 0) Starting offset.
# @option args [Boolean] :ignore_unavailable If `false`, the request returns an error if it targets a missing or closed index.
# @option args [Boolean] :lenient If `true`, format-based query failures (such as providing text to a numeric field) in the query string will be ignored.
# @option args [Integer] :max_docs Maximum number of documents to process. Defaults to all documents.
# @option args [String] :preference Specifies the node or shard the operation should be performed on. Random by default.
# @option args [String] :preference (default: random) Specifies the node or shard the operation should be performed on. Random by default.
# @option args [String] :q Query in the Lucene query string syntax.
# @option args [Boolean, String] :refresh If `true`, OpenSearch refreshes all shards involved in the delete by query after the request completes.
# @option args [Boolean] :request_cache If `true`, the request cache is used for this request. Defaults to the index-level setting.
# @option args [Float] :requests_per_second The throttle for this request in sub-requests per second.
# @option args [Float] :requests_per_second (default: 0) The throttle for this request in sub-requests per second.
# @option args [Enumerable<String>, String] :routing Custom value used to route operations to a specific shard.
# @option args [String] :scroll Period to retain the search context for scrolling.
# @option args [Integer] :scroll_size Size of the scroll request that powers the operation.
# @option args [Integer] :scroll_size (default: 100) Size of the scroll request that powers the operation.
# @option args [String] :search_timeout Explicit timeout for each search request. Defaults to no timeout.
# @option args [String] :search_type The type of the search operation. Available options: `query_then_fetch`, `dfs_query_then_fetch`.
# @option args [Integer] :size Deprecated, use `max_docs` instead.
Expand All @@ -48,7 +48,7 @@ module Actions
# @option args [String] :timeout Period each deletion request waits for active shards.
# @option args [Boolean] :version If `true`, returns the document version as part of a hit.
# @option args [Integer, String] :wait_for_active_shards The number of shard copies that must be active before proceeding with the operation. Set to all or any positive integer up to the total number of shards in the index (`number_of_replicas+1`).
# @option args [Boolean] :wait_for_completion If `true`, the request blocks until the operation is complete.
# @option args [Boolean] :wait_for_completion (default: true) If `true`, the request blocks until the operation is complete.
# @option args [Hash] :body *Required* The search definition using the Query DSL
def delete_by_query(args = {})
args = Utils.normalize_arguments(args)
Expand Down
2 changes: 1 addition & 1 deletion lib/opensearch/api/actions/exists.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module Actions
# @option args [Boolean, Enumerable<String>, String] :_source `true` or `false` to return the `_source` field or not, or a list of fields to return.
# @option args [Enumerable<String>, String] :_source_excludes A comma-separated list of source fields to exclude in the response.
# @option args [Enumerable<String>, String] :_source_includes A comma-separated list of source fields to include in the response.
# @option args [String] :preference Specifies the node or shard the operation should be performed on. Random by default.
# @option args [String] :preference (default: random) Specifies the node or shard the operation should be performed on. Random by default.
# @option args [Boolean] :realtime If `true`, the request is real-time as opposed to near-real-time.
# @option args [Boolean, String] :refresh If `true`, OpenSearch refreshes all shards involved in the delete by query after the request completes.
# @option args [Enumerable<String>, String] :routing Target the specified primary shard.
Expand Down
2 changes: 1 addition & 1 deletion lib/opensearch/api/actions/exists_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module Actions
# @option args [Boolean, Enumerable<String>, String] :_source `true` or `false` to return the `_source` field or not, or a list of fields to return.
# @option args [Enumerable<String>, String] :_source_excludes A comma-separated list of source fields to exclude in the response.
# @option args [Enumerable<String>, String] :_source_includes A comma-separated list of source fields to include in the response.
# @option args [String] :preference Specifies the node or shard the operation should be performed on. Random by default.
# @option args [String] :preference (default: random) Specifies the node or shard the operation should be performed on. Random by default.
# @option args [Boolean] :realtime If `true`, the request is real-time as opposed to near-real-time.
# @option args [Boolean, String] :refresh If `true`, OpenSearch refreshes all shards involved in the delete by query after the request completes.
# @option args [Enumerable<String>, String] :routing Target the specified primary shard.
Expand Down
4 changes: 2 additions & 2 deletions lib/opensearch/api/actions/explain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ module Actions
# @option args [Boolean] :analyze_wildcard If `true`, wildcard and prefix queries are analyzed.
# @option args [String] :analyzer Analyzer to use for the query string. This parameter can only be used when the `q` query string parameter is specified.
# @option args [String] :default_operator The default operator for query string query: `AND` or `OR`.
# @option args [String] :df Field to use as default where no field prefix is given in the query string.
# @option args [String] :df (default: _all) Field to use as default where no field prefix is given in the query string.
# @option args [Boolean] :lenient If `true`, format-based query failures (such as providing text to a numeric field) in the query string will be ignored.
# @option args [String] :preference Specifies the node or shard the operation should be performed on. Random by default.
# @option args [String] :preference (default: random) Specifies the node or shard the operation should be performed on. Random by default.
# @option args [String] :q Query in the Lucene query string syntax.
# @option args [Enumerable<String>, String] :routing Custom value used to route operations to a specific shard.
# @option args [Enumerable<String>, String] :stored_fields A comma-separated list of stored fields to return in the response.
Expand Down
2 changes: 1 addition & 1 deletion lib/opensearch/api/actions/flow_framework/create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module Actions
# @option args [Boolean] :reprovision
# @option args [Boolean] :update_fields Update only the fields included in the request body.
# @option args [String] :use_case To use a workflow template, specify it in the `use_case` query parameter when creating a workflow.
# @option args [String] :validation Validate the workflow. Valid values are all (validate the template) and none (do not validate the template). Default is all.
# @option args [String] :validation (default: all) Validate the workflow. Valid values are all (validate the template) and none (do not validate the template). Default is all.
# @option args [Hash] :body
def create(args = {})
args = Utils.normalize_arguments(args)
Expand Down
2 changes: 1 addition & 1 deletion lib/opensearch/api/actions/flow_framework/update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module Actions
# @option args [Boolean] :reprovision
# @option args [Boolean] :update_fields Update only the fields included in the request body.
# @option args [String] :use_case To use a workflow template, specify it in the `use_case` query parameter when creating a workflow.
# @option args [String] :validation Validate the workflow. Valid values are all (validate the template) and none (do not validate the template). Default is all.
# @option args [String] :validation (default: all) Validate the workflow. Valid values are all (validate the template) and none (do not validate the template). Default is all.
# @option args [Hash] :body
def update(args = {})
args = Utils.normalize_arguments(args)
Expand Down
2 changes: 1 addition & 1 deletion lib/opensearch/api/actions/get.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module Actions
# @option args [Boolean, Enumerable<String>, String] :_source Set to `true` or `false` to return the `_source` field or not, or a list of fields to return.
# @option args [Enumerable<String>, String] :_source_excludes A comma-separated list of source fields to exclude in the response.
# @option args [Enumerable<String>, String] :_source_includes A comma-separated list of source fields to include in the response.
# @option args [String] :preference Specifies the node or shard the operation should be performed on. Random by default.
# @option args [String] :preference (default: random) Specifies the node or shard the operation should be performed on. Random by default.
# @option args [Boolean] :realtime If `true`, the request is real-time as opposed to near-real-time.
# @option args [Boolean, String] :refresh If `true`, OpenSearch refreshes the affected shards to make this operation visible to search. If `false`, do nothing with refreshes.
# @option args [Enumerable<String>, String] :routing Target the specified primary shard.
Expand Down
2 changes: 1 addition & 1 deletion lib/opensearch/api/actions/get_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module Actions
# @option args [Boolean, Enumerable<String>, String] :_source Set to `true` or `false` to return the `_source` field or not, or a list of fields to return.
# @option args [Enumerable<String>, String] :_source_excludes A comma-separated list of source fields to exclude in the response.
# @option args [Enumerable<String>, String] :_source_includes A comma-separated list of source fields to include in the response.
# @option args [String] :preference Specifies the node or shard the operation should be performed on. Random by default.
# @option args [String] :preference (default: random) Specifies the node or shard the operation should be performed on. Random by default.
# @option args [Boolean] :realtime Boolean) If `true`, the request is real-time as opposed to near-real-time.
# @option args [Boolean, String] :refresh If `true`, OpenSearch refreshes the affected shards to make this operation visible to search. If `false`, do nothing with refreshes.
# @option args [Enumerable<String>, String] :routing Target the specified primary shard.
Expand Down
2 changes: 1 addition & 1 deletion lib/opensearch/api/actions/indices/clone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module Actions
# @option args [String] :task_execution_timeout Explicit task execution timeout, only useful when `wait_for_completion` is false, defaults to `1h`.
# @option args [String] :timeout Period to wait for a response. If no response is received before the timeout expires, the request fails and returns an error.
# @option args [Integer, String] :wait_for_active_shards The number of shard copies that must be active before proceeding with the operation. Set to `all` or any positive integer up to the total number of shards in the index (`number_of_replicas+1`).
# @option args [Boolean] :wait_for_completion Should this request wait until the operation has completed before returning.
# @option args [Boolean] :wait_for_completion (default: true) Should this request wait until the operation has completed before returning.
# @option args [Hash] :body The configuration for the target index (`settings` and `aliases`)
def clone(args = {})
args = Utils.normalize_arguments(args)
Expand Down
2 changes: 1 addition & 1 deletion lib/opensearch/api/actions/indices/flush.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module Actions
# @option args [Enumerable<String>, String] :expand_wildcards Type of index that wildcard patterns can match. If the request can target data streams, this argument determines whether wildcard expressions match hidden data streams. Supports comma-separated values, such as `open,hidden`. Valid values are: `all`, `open`, `closed`, `hidden`, `none`.
# @option args [Boolean] :force If `true`, the request forces a flush even if there are no changes to commit to the index.
# @option args [Boolean] :ignore_unavailable If `false`, the request returns an error if it targets a missing or closed index.
# @option args [Boolean] :wait_if_ongoing If `true`, the flush operation blocks until execution when another flush operation is running. If `false`, OpenSearch returns an error if you request a flush when another flush operation is running.
# @option args [Boolean] :wait_if_ongoing (default: true) If `true`, the flush operation blocks until execution when another flush operation is running. If `false`, OpenSearch returns an error if you request a flush when another flush operation is running.
# @option args [Enumerable<String>, String] :index Comma-separated list of data streams, indexes, and aliases to flush. Supports wildcards (`*`). To flush all data streams and indexes, omit this parameter or use `*` or `_all`.
def flush(args = {})
args = Utils.normalize_arguments(args)
Expand Down
Loading

0 comments on commit 1e438fa

Please sign in to comment.