Class: Apicraft::Mocker::AllOf
- Defined in:
- lib/apicraft/mocker/all_of.rb
Overview
Generate mock based on the OneOf schema
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
Methods inherited from Base
Constructor Details
This class inherits a constructor from Apicraft::Mocker::Base
Instance Method Details
#mock ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/apicraft/mocker/all_of.rb', line 7 def mock res = schema.all_of.map do |s| Mocker.mock(s) end type = res[0].class # TODO: This is not an accurate implementation # especially when it comes to numbers and strings # Ideally, we would want to combine rules from # all the schemas and then generate a value. if type.is_a?(Hash) res.reduce(&:merge) elsif type.is_a?(Array) res.reduce(&:concat) else res.sample end end |