How would I define that a given param can have multiple possible hash values?
As a very simplified example, say that either of these hashes are valid params:
"value": {
"time_unit": "hour",
"rate": 100.0
}
"value": {
"fixed_price": 100.0,
}
but that value can take only one or the other of those forms. It's also possible I could add more acceptable formats in the future, but that there will always be a finite number of acceptable formats to the "value" key.
I attempted something like this but it does not seem to be possible:
params do
requires :value, desc: "TODO", types: [
Hash {
requires :fixed_price, type: Float
},
Hash {
requires :time_unit, type: String
requires :rate, type: Float
},
]
end
I can sort of achieve what I want right now by delcaring its type as hash, declaring all of the possible fields as optional, and setting some complicated rules with mutually_exclusive and given, but this is messy and it is difficult to parse at a glance what the expected possible schemas are.
Is there a better way to achieve this?
How would I define that a given param can have multiple possible hash values?
As a very simplified example, say that either of these hashes are valid params:
but that value can take only one or the other of those forms. It's also possible I could add more acceptable formats in the future, but that there will always be a finite number of acceptable formats to the "value" key.
I attempted something like this but it does not seem to be possible:
I can sort of achieve what I want right now by delcaring its type as hash, declaring all of the possible fields as optional, and setting some complicated rules with
mutually_exclusiveandgiven, but this is messy and it is difficult to parse at a glance what the expected possible schemas are.Is there a better way to achieve this?