Module: Fakeit::Openapi::Example
- Included in:
- Schema
- Defined in:
- lib/fakeit/openapi/example/array_example.rb,
lib/fakeit/openapi/example/number_example.rb,
lib/fakeit/openapi/example/object_example.rb,
lib/fakeit/openapi/example/string_example.rb,
lib/fakeit/openapi/example/boolean_example.rb,
lib/fakeit/openapi/example/integer_example.rb
Constant Summary collapse
- MIN_NUM =
-2**31
- MAX_NUM =
2**31 - 1
- STATIC_FORMAT_HANDLERS =
{ 'uri' => -> { 'https://some.uri' }, 'uuid' => -> { '11111111-1111-1111-1111-111111111111' }, 'guid' => -> { '11111111-1111-1111-1111-111111111111' }, 'email' => -> { '[email protected]' }, 'date' => -> { Date.today.iso8601 }, 'date-time' => lambda do now = Time.now Time.new(now.year, now.month, now.day, 0, 0, 0, now.utc_offset).iso8601 end }.freeze
- RANDOM_FORMAT_HANDLERS =
{ 'uri' => -> { Faker::Internet.url }, 'uuid' => -> { SecureRandom.uuid }, 'guid' => -> { SecureRandom.uuid }, 'email' => -> { Faker::Internet.email }, 'date' => -> { Faker::Date.backward(100).iso8601 }, 'date-time' => -> { Faker::Time.backward(100).iso8601 } }.freeze
Instance Method Summary collapse
- #array_example(options) ⇒ Object
- #boolean_example(example_options) ⇒ Object
- #integer_example(example_options) ⇒ Object
- #number_example(example_options) ⇒ Object
- #object_example(example_options) ⇒ Object
- #string_example(example_options) ⇒ Object
Instance Method Details
#array_example(options) ⇒ Object
4 5 6 7 8 9 10 11 |
# File 'lib/fakeit/openapi/example/array_example.rb', line 4 def array_example() = add_depth() if [:use_static][type: 'array', property: [:property]] static_array_example() else random_array_example() end end |
#boolean_example(example_options) ⇒ Object
4 5 6 |
# File 'lib/fakeit/openapi/example/boolean_example.rb', line 4 def boolean_example() [:use_static][type: 'boolean', property: [:property]] || Faker::Boolean.boolean end |
#integer_example(example_options) ⇒ Object
4 5 6 7 8 9 10 |
# File 'lib/fakeit/openapi/example/integer_example.rb', line 4 def integer_example() if [:use_static][type: 'integer', property: [:property]] static_integer_example else random_integer_example end end |
#number_example(example_options) ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/fakeit/openapi/example/number_example.rb', line 7 def number_example() if [:use_static][type: 'number', property: [:property]] static_number_example else random_number_example end end |
#object_example(example_options) ⇒ Object
4 5 6 7 8 |
# File 'lib/fakeit/openapi/example/object_example.rb', line 4 def object_example() properties.each_with_object({}) do |(name, schema), obj| obj[name] = schema.to_example(.merge(property: name)) end end |
#string_example(example_options) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/fakeit/openapi/example/string_example.rb', line 25 def string_example() if [:use_static][type: 'string', property: [:property]] static_string_example else random_string_example end end |