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, "binary" => -> { "binary" }, "byte" => -> { "Ynl0ZQ==" } }.freeze
- RANDOM_FORMAT_HANDLERS =
{ "uri" => -> { Faker::Internet.url }, "uuid" => -> { SecureRandom.uuid }, "guid" => -> { SecureRandom.uuid }, "email" => -> { Faker::Internet.email }, "date" => -> { Faker::Date.backward(days: 100).iso8601 }, "date-time" => -> { Faker::Time.backward(days: 100).iso8601 }, "binary" => -> { Faker::String.random(length: 1..30) }, "byte" => -> { Base64.strict_encode64(Faker::String.random(length: 1..30)) } }.freeze
- DEFAULT_BITS =
32
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]] generate_array_example(, -> { non_empty_size }) else generate_array_example(, -> { random_array_size() }) 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
6 7 8 9 10 11 12 |
# File 'lib/fakeit/openapi/example/integer_example.rb', line 6 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(**, property: name) end end |
#string_example(example_options) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/fakeit/openapi/example/string_example.rb', line 29 def string_example() @string_pattern ||= Regexp.new(pattern) if pattern if [:use_static][type: "string", property: [:property]] static_string_example else random_string_example end end |