Skip to content

Commit

Permalink
Merge pull request #689 from ftsanjuan/fix/allow-array-hash-param-swa…
Browse files Browse the repository at this point in the history
…ggergen

fix: enable swagger generator to add referenced schema for an array of hashes param
  • Loading branch information
mathieujobin committed May 20, 2022
2 parents e86c30e + 9c797be commit be4b0fd
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/apipie/swagger_generator.rb
Expand Up @@ -478,9 +478,16 @@ def save_field(entry, openapi_key, v, apipie_key=openapi_key, translate=false)
end

if swagger_def[:type] == "array"
swagger_def[:items] = {type: "string"}
enum = param_desc.options.fetch(:in, [])
array_of_validator_opts = param_desc.validator.param_description.options
items_type = array_of_validator_opts[:of].to_s || array_of_validator_opts[:array_of].to_s
if items_type == "Hash"
ref_name = "#{swagger_op_id_for_path(param_desc.method_description.apis.first.http_method, param_desc.method_description.apis.first.path)}_param_#{param_desc.name}"
swagger_def[:items] = {"$ref" => gen_referenced_block_from_params_array(ref_name, param_desc.validator.param_description.validator.params_ordered, allow_nulls)}
else
swagger_def[:items] = {type: "string"}
end

enum = param_desc.options.fetch(:in, [])
swagger_def[:items][:enum] = enum if enum.any?
end

Expand Down

0 comments on commit be4b0fd

Please sign in to comment.