Class: Meta::RouteDSL::ParametersBuilder
- Inherits:
-
Object
- Object
- Meta::RouteDSL::ParametersBuilder
- Defined in:
- lib/meta/route_dsl/parameters_builder.rb
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(route_full_path:, route_method:, &block) ⇒ ParametersBuilder
constructor
A new instance of ParametersBuilder.
- #param(name, options = {}) ⇒ Object
Constructor Details
#initialize(route_full_path:, route_method:, &block) ⇒ ParametersBuilder
Returns a new instance of ParametersBuilder.
9 10 11 12 13 14 15 |
# File 'lib/meta/route_dsl/parameters_builder.rb', line 9 def initialize(route_full_path:, route_method:, &block) @route_full_path = route_full_path || '' @route_method = route_method @parameter_options = {} instance_exec &block if block_given? end |
Instance Method Details
#build ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/meta/route_dsl/parameters_builder.rb', line 31 def build # 补充未声明的 path 参数 (path_param_names - @parameter_options.keys).each do |name| @parameter_options[name] = { in: 'path', schema: JsonSchema::BaseSchema.new(required: true) } end Parameters.new(@parameter_options) end |
#param(name, options = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/meta/route_dsl/parameters_builder.rb', line 17 def param(name, = {}) # 修正 path 参数的选项 = .dup if path_param_names.include?(name) # path 参数 = Utils::Kwargs::Helpers.fix!(, in: 'path', required: true) else = Utils::Kwargs::Helpers.merge_defaults!(, in: 'query') end in_op = .delete(:in) raise ArgumentError, "in 选项只能是 path, query, header, body" unless %w[path query header body].include?(in_op) @parameter_options[name] = { in: in_op, schema: JsonSchema::BaseSchema.new() } end |