Module: OasRails::Spec::Specable

Included in:
Components, Contact, Info, License, MediaType, Operation, Parameter, PathItem, Paths, Reference, RequestBody, Response, Responses, Server, Specification, Tag
Defined in:
lib/oas_rails/spec/specable.rb

Instance Method Summary collapse

Instance Method Details

#as_json(options = nil) ⇒ Object

rubocop:disable Lint/UnusedMethodArgument



36
37
38
# File 'lib/oas_rails/spec/specable.rb', line 36

def as_json(options = nil)
  to_spec
end

#oas_fieldsObject



4
5
6
# File 'lib/oas_rails/spec/specable.rb', line 4

def oas_fields
  []
end

#to_specObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/oas_rails/spec/specable.rb', line 8

def to_spec
  hash = {}
  oas_fields.each do |var|
    key = var.to_s

    camel_case_key = key.camelize(:lower).to_sym
    value = send(var)

    processed_value = if value.respond_to?(:to_spec)
                        value.to_spec
                      elsif value.is_a?(Array) && value.all? { |elem| elem.respond_to?(:to_spec) }
                        value.map(&:to_spec)
                      # elsif value.is_a?(Hash)
                      #   hash = {}
                      #   value.each do |key, object|
                      #     hash[key] = object.to_spec
                      #   end
                      #   hash
                      else
                        value
                      end

    hash[camel_case_key] = processed_value unless valid_processed_value?(processed_value)
  end
  hash
end