Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SpecInsert] Fixed missing default values in param tables #8975

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions spec-insert/lib/api/parameter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down
2 changes: 1 addition & 1 deletion spec-insert/lib/renderers/parameter_table_renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions spec-insert/lib/spec_hash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions spec-insert/spec/_fixtures/expected_output/param_tables.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
nhtruong marked this conversation as resolved.
Show resolved Hide resolved
| 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` <br> _DEPRECATED_ | _(Deprecated since 3.0: Use the `format` parameter instead.)_ Whether to return human readable values for statistics. | | |
| Boolean | `human` <br> _DEPRECATED_ | _(Deprecated since 3.0: Use the `format` parameter instead.)_ Whether to return human readable values for statistics. | | true |
<!-- spec_insert_end -->

Query Parameters Example with only Parameter and Description Columns
Expand All @@ -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.
<!-- spec_insert_end -->
Loading