Skip to content

Commit a51bd39

Browse files
authored
Fix issue where scope is nil when a param_group is accessed nested within response (#774)
* fix validator.rb * add tests * add newlines at end of file * fix indentation
1 parent e604b11 commit a51bd39

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

lib/apipie/validator.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ def params_ordered
337337
@params_ordered ||= _apipie_dsl_data[:params].map do |args|
338338
options = args.find { |arg| arg.is_a? Hash }
339339
options[:parent] = self.param_description
340+
options[:param_group] = @param_group
340341
Apipie::ParamDescription.from_dsl_data(param_description.method_description, args)
341342
end
342343
end
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
require 'spec_helper'
2+
3+
4+
describe IncludedParamGroupController do
5+
6+
let(:dsl_data) { ActionController::Base.send(:_apipie_dsl_data_init) }
7+
8+
it "should not error when there is a param_group that is deeply nested in response description" do
9+
subject = Apipie.get_resource_description(IncludedParamGroupController, Apipie.configuration.default_version)
10+
expect(subject._methods.keys).to include(:show)
11+
end
12+
13+
end
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class IncludedParamGroupController < ApplicationController
2+
include RandomParamGroup
3+
4+
api :GET, '/included-param-group'
5+
returns code:200 do
6+
property :top_level, Array, of: Hash do
7+
param_group :random_param_group
8+
end
9+
property :nested, Hash do
10+
property :random_array, Array, of: Hash do
11+
param_group :random_param_group
12+
end
13+
end
14+
end
15+
def show
16+
end
17+
18+
end
19+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module RandomParamGroup
2+
def self.included(klazz)
3+
klazz.def_param_group :random_param_group do
4+
property :id, Integer
5+
property :name, String
6+
end
7+
end
8+
end

0 commit comments

Comments
 (0)