Skip to content

Array params with at_least_one_of having custom validation message #396

Open
@milap-neupane

Description

@milap-neupane

When we have array as a params with elements and a validation like at_least_one_of, mutually_exclusive, ... the generated JSON has an extra field which is undesired. This field is present only when we have a custom message filed passed in the validation (message: 'is missing')

params do
  requires :my_top_arr, type: Array, allow_blank: false do
    optional :my_elem1,
             type: Float
    optional :my_elem2,
             type: String
    at_least_one_of :my_elem2,
                    :status,
                    message: 'is missing'
  end
end

The generated JSON is:

[
  [0] {
    "description": null,
             "in": "formData",
          "items": {
      "type": "float"
    },
           "name": "my_top_arr[][my_elem1]",
       "required": false,
           "type": "array"
  },
  [1] {
    "description": null,
             "in": "formData",
          "items": {
      "type": "string"
    },
           "name": "my_top_arr[][my_elem2]",
       "required": false,
           "type": "array"
  },
  [2] {
    "description": null,
             "in": "formData",
          "items": {
      "type": "string"
    },
           "name": "my_top_arr[][my_top_arr]",
       "required": false,
           "type": "array"
  },
  [3] {
    "description": null,
             "in": "formData",
          "items": {
      "type": "string"
    },
           "name": "my_top_arr[][{:message=>\"is missing\"}]",
       "required": false,
           "type": "array"
  }
]

The last field my_top_arr[][{:message=>\"is missing\"}] seems to be extra generated.

This field is generated only when i pass message: 'is missing' to the at_least_one_of validation.
*The message key is used by grape for custom validation message.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions