From 0b6bb350d6bf7e821a4ad8a7e754a68cc564a8c6 Mon Sep 17 00:00:00 2001 From: Theo Truong Date: Thu, 19 Dec 2024 12:30:09 -0700 Subject: [PATCH 1/3] [SpecInsert] Fixed missing default values in param tables Signed-off-by: Theo Truong --- spec-insert/lib/api/parameter.rb | 4 ++-- spec-insert/lib/renderers/parameter_table_renderer.rb | 2 +- spec-insert/lib/spec_hash.rb | 9 ++++++--- .../spec/_fixtures/expected_output/param_tables.md | 6 +++--- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/spec-insert/lib/api/parameter.rb b/spec-insert/lib/api/parameter.rb index 1bbe92c4ee..f946c31acb 100644 --- a/spec-insert/lib/api/parameter.rb +++ b/spec-insert/lib/api/parameter.rb @@ -80,12 +80,12 @@ def self.from_operations(operations) # @return [Parameter] Single parameter distilled from the list def self.from_parameters(params, opts_count) param = params.first || SpecHash.new - schema = param&.schema || SpecHash.new + schema = param.schema || SpecHash.new Parameter.new(name: param.name, description: param.description || schema.description, required: params.filter(&:required).size >= opts_count, 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'], version_deprecated: param['x-version-deprecated'] || schema['x-version-deprecated'], diff --git a/spec-insert/lib/renderers/parameter_table_renderer.rb b/spec-insert/lib/renderers/parameter_table_renderer.rb index 23312962d8..39790eca33 100644 --- a/spec-insert/lib/renderers/parameter_table_renderer.rb +++ b/spec-insert/lib/renderers/parameter_table_renderer.rb @@ -37,7 +37,7 @@ def description(param) deprecation = deprecation(param) required = param.required && @columns.exclude?('Required') ? '**(Required)** ' : '' description = param.description.gsub("\n", ' ') - default = param.default.nil? || @columns.includes('Default') ? '' : " _(Default: #{param.default})_" + default = param.default.nil? || @columns.include?('Default') ? '' : " _(Default: #{param.default})_" "#{deprecation}#{required}#{description}#{default}" end diff --git a/spec-insert/lib/spec_hash.rb b/spec-insert/lib/spec_hash.rb index 0720250306..4f34500a0a 100644 --- a/spec-insert/lib/spec_hash.rb +++ b/spec-insert/lib/spec_hash.rb @@ -34,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 diff --git a/spec-insert/spec/_fixtures/expected_output/param_tables.md b/spec-insert/spec/_fixtures/expected_output/param_tables.md index 5e4c05164e..2c6a7f4f64 100644 --- a/spec-insert/spec/_fixtures/expected_output/param_tables.md +++ b/spec-insert/spec/_fixtures/expected_output/param_tables.md @@ -22,10 +22,10 @@ columns: Type, Parameter, Description, Required, Default ## Query parameters | Type | Parameter | Description | Required | Default | |:--------|:--------------------------|:-----------------------------------------------------------------------------------------------------------------------------------|:---------|:--------| -| Boolean | `analyze_wildcard` | If true, wildcard and prefix queries are analyzed. This parameter can only be used when the q query string parameter is specified. | Required | | +| Boolean | `analyze_wildcard` | If true, wildcard and prefix queries are analyzed. This parameter can only be used when the q query string parameter is specified. | Required | false | | String | `analyzer` | Analyzer to use for the query string. This parameter can only be used when the q query string parameter is specified. | | | | Boolean | `pretty` | Whether to pretty format the returned JSON response. | | | -| Boolean | `human`
_DEPRECATED_ | _(Deprecated since 3.0: Use the `format` parameter instead.)_ Whether to return human readable values for statistics. | | | +| Boolean | `human`
_DEPRECATED_ | _(Deprecated since 3.0: Use the `format` parameter instead.)_ Whether to return human readable values for statistics. | | true | Query Parameters Example with only Parameter and Description Columns @@ -38,6 +38,6 @@ omit_header: true --> Parameter | Description :--- | :--- -`analyze_wildcard` | **(Required)** If true, wildcard and prefix queries are analyzed. This parameter can only be used when the q query string parameter is specified. +`analyze_wildcard` | **(Required)** If true, wildcard and prefix queries are analyzed. This parameter can only be used when the q query string parameter is specified. _(Default: false)_ `analyzer` | Analyzer to use for the query string. This parameter can only be used when the q query string parameter is specified. From 1f3d75440af85be2e1726a04541f1f388ef1a092 Mon Sep 17 00:00:00 2001 From: Theo Truong Date: Thu, 19 Dec 2024 13:37:33 -0700 Subject: [PATCH 2/3] # wrapped default values in backticks Signed-off-by: Theo Truong --- spec-insert/lib/renderers/parameter_table_renderer.rb | 4 ++-- spec-insert/spec/_fixtures/expected_output/param_tables.md | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/spec-insert/lib/renderers/parameter_table_renderer.rb b/spec-insert/lib/renderers/parameter_table_renderer.rb index 39790eca33..e13c4d1149 100644 --- a/spec-insert/lib/renderers/parameter_table_renderer.rb +++ b/spec-insert/lib/renderers/parameter_table_renderer.rb @@ -29,7 +29,7 @@ def row(param) 'Description' => description(param), 'Required' => param.required ? 'Required' : nil, 'Type' => param.doc_type, - 'Default' => param.default + 'Default' => param.default.nil? ? nil : "`#{param.default}`" } end @@ -37,7 +37,7 @@ def description(param) deprecation = deprecation(param) required = param.required && @columns.exclude?('Required') ? '**(Required)** ' : '' description = param.description.gsub("\n", ' ') - default = param.default.nil? || @columns.include?('Default') ? '' : " _(Default: #{param.default})_" + default = param.default.nil? || @columns.include?('Default') ? '' : " _(Default: `#{param.default}`)_" "#{deprecation}#{required}#{description}#{default}" end diff --git a/spec-insert/spec/_fixtures/expected_output/param_tables.md b/spec-insert/spec/_fixtures/expected_output/param_tables.md index 2c6a7f4f64..96bbcd363b 100644 --- a/spec-insert/spec/_fixtures/expected_output/param_tables.md +++ b/spec-insert/spec/_fixtures/expected_output/param_tables.md @@ -22,10 +22,10 @@ columns: Type, Parameter, Description, Required, Default ## Query parameters | Type | Parameter | Description | Required | Default | |:--------|:--------------------------|:-----------------------------------------------------------------------------------------------------------------------------------|:---------|:--------| -| Boolean | `analyze_wildcard` | If true, wildcard and prefix queries are analyzed. This parameter can only be used when the q query string parameter is specified. | Required | false | +| Boolean | `analyze_wildcard` | If true, wildcard and prefix queries are analyzed. This parameter can only be used when the q query string parameter is specified. | Required | `false` | | String | `analyzer` | Analyzer to use for the query string. This parameter can only be used when the q query string parameter is specified. | | | | Boolean | `pretty` | Whether to pretty format the returned JSON response. | | | -| Boolean | `human`
_DEPRECATED_ | _(Deprecated since 3.0: Use the `format` parameter instead.)_ Whether to return human readable values for statistics. | | true | +| Boolean | `human`
_DEPRECATED_ | _(Deprecated since 3.0: Use the `format` parameter instead.)_ Whether to return human readable values for statistics. | | `true` | Query Parameters Example with only Parameter and Description Columns @@ -38,6 +38,6 @@ omit_header: true --> Parameter | Description :--- | :--- -`analyze_wildcard` | **(Required)** If true, wildcard and prefix queries are analyzed. This parameter can only be used when the q query string parameter is specified. _(Default: false)_ +`analyze_wildcard` | **(Required)** If true, wildcard and prefix queries are analyzed. This parameter can only be used when the q query string parameter is specified. _(Default: `false`)_ `analyzer` | Analyzer to use for the query string. This parameter can only be used when the q query string parameter is specified. From a81be8fb199948bde47010f438239a41e29e6df1 Mon Sep 17 00:00:00 2001 From: "Theo N. Truong" Date: Thu, 19 Dec 2024 13:47:10 -0700 Subject: [PATCH 3/3] Update spec-insert/lib/renderers/parameter_table_renderer.rb Co-authored-by: Naarcha-AWS <97990722+Naarcha-AWS@users.noreply.github.com> Signed-off-by: Theo N. Truong --- spec-insert/lib/renderers/parameter_table_renderer.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec-insert/lib/renderers/parameter_table_renderer.rb b/spec-insert/lib/renderers/parameter_table_renderer.rb index e13c4d1149..0deefaa9ba 100644 --- a/spec-insert/lib/renderers/parameter_table_renderer.rb +++ b/spec-insert/lib/renderers/parameter_table_renderer.rb @@ -29,7 +29,7 @@ def row(param) 'Description' => description(param), 'Required' => param.required ? 'Required' : nil, 'Type' => param.doc_type, - 'Default' => param.default.nil? ? nil : "`#{param.default}`" + 'Default' => param.default.nil? ? nil : "`#{param.default}`" } end