Class: OasRails::Spec::MediaType

Inherits:
Object
  • Object
show all
Includes:
Specable
Defined in:
lib/oas_rails/spec/media_type.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Specable

#as_json, #to_spec

Constructor Details

#initialize(specification) ⇒ MediaType

Initializes a new MediaType object.

Parameters:

  • schema (Hash)

    the schema of the media type.

  • kwargs (Hash)

    additional keyword arguments.



15
16
17
18
19
20
# File 'lib/oas_rails/spec/media_type.rb', line 15

def initialize(specification)
  @specification = specification
  @schema = {}
  @example =  {}
  @examples = {}
end

Instance Attribute Details

#encodingObject

Returns the value of attribute encoding.



6
7
8
# File 'lib/oas_rails/spec/media_type.rb', line 6

def encoding
  @encoding
end

#exampleObject

Returns the value of attribute example.



6
7
8
# File 'lib/oas_rails/spec/media_type.rb', line 6

def example
  @example
end

#examplesObject

Returns the value of attribute examples.



6
7
8
# File 'lib/oas_rails/spec/media_type.rb', line 6

def examples
  @examples
end

#schemaObject

Returns the value of attribute schema.



6
7
8
# File 'lib/oas_rails/spec/media_type.rb', line 6

def schema
  @schema
end

Class Method Details

.search_for_examples_in_tests(klass, context: :incoming, utils: Utils) ⇒ Hash

Searches for examples in test files based on the provided class and test framework.

Parameters:

  • klass (Class)

    the class to search examples for.

  • utils (Module) (defaults to: Utils)

    a utility module that provides the ‘detect_test_framework` method. Defaults to `Utils`.

Returns:

  • (Hash)

    a hash containing examples data or an empty hash if no examples are found.



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/oas_rails/spec/media_type.rb', line 32

def search_for_examples_in_tests(klass, context: :incoming, utils: Utils)
  @context = context
  case utils.detect_test_framework
  when :factory_bot
    fetch_factory_bot_examples(klass:)
  when :fixtures
    fetch_fixture_examples(klass:)
  else
    {}
  end
end

Instance Method Details

#oas_fieldsObject



22
23
24
# File 'lib/oas_rails/spec/media_type.rb', line 22

def oas_fields
  [:schema, :example, :examples, :encoding]
end