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

param: Consider default_value: nil as valid config #894

Merged
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
2 changes: 1 addition & 1 deletion lib/apipie/generator/swagger/param_description/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def for_required
end

def for_default
return {} if @param_description.options[:default_value].blank?
Copy link
Contributor Author

@davidwessman davidwessman Jul 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we combine this with the allow_nil and allow_blank to only allow

  • default: nil when allow_nil: true and
  • default: "" when allow_blank: true?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I don't think they should be combined.

return {} unless @param_description.options.key?(:default_value)

{
default: @param_description.options[:default_value],
Expand Down
3 changes: 1 addition & 2 deletions spec/lib/apipie/apipies_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@
end

it "succeeds on method details with the default language" do
allow(Apipie.configuration).to receive(:default_locale).and_return("en")
allow(Apipie.configuration).to receive(:languages).and_return([])
allow(Apipie.configuration).to receive_messages(default_locale: "en", languages: [])

get :index, :params => { :version => "2.0", :resource => "architectures", :method => "index.en" }

Expand Down
48 changes: 37 additions & 11 deletions spec/lib/apipie/generator/swagger/param_description/builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,23 +102,49 @@

subject { generated_block }

context 'when is not required' do
let(:base_param_description_options) { { required: false } }
context 'when required is true' do
let(:base_param_description_options) { { required: true } }

it 'does not output an option without default warning' do
expect { subject }.not_to output(
/is optional but default value is not specified/
).to_stderr
end
end

context 'and no default is given' do
before { param_description_options.delete(:default) }
context 'when required is false' do
context 'when default_value is nil' do
let(:base_param_description_options) do
{ required: false, default_value: nil }
end

it 'outputs an option without default warning' do
expect { subject }.to output(/is optional but default value is not specified/).to_stderr
it 'will not warn' do
expect { subject }.not_to output(
/is optional but default value is not specified/
).to_stderr
end
end
end

context 'when is required' do
let(:base_param_description_options) { { required: true } }
context 'when default_value is 123' do
let(:base_param_description_options) do
{ required: false, default_value: 123 }
end

it 'does not output an option without default warning' do
expect { subject }.not_to output(/is optional but default value is not specified/).to_stderr
it 'will not warn' do
expect { subject }.not_to output(
/is optional but default value is not specified/
).to_stderr
end
end

context 'default_value not given' do
let(:base_param_description_options) { { required: false } }

it 'warns' do
expect { subject }.to output(
/is optional but default value is not specified/
).to_stderr
end
end
end
end
Expand Down
Loading