Class: Openapi2ruby::Openapi::Schema

Inherits:
Object
  • Object
show all
Defined in:
lib/openapi2ruby/openapi/schema.rb

Defined Under Namespace

Classes: Property

Instance Method Summary collapse

Constructor Details

#initialize(content) ⇒ Schema

Returns a new instance of Schema.



3
4
5
6
# File 'lib/openapi2ruby/openapi/schema.rb', line 3

def initialize(content)
  @name = content[:name]
  @definition = content[:definition]
end

Instance Method Details

#nameString

OpenAPI camelcase schema name

Returns:

  • (String)


10
11
12
# File 'lib/openapi2ruby/openapi/schema.rb', line 10

def name
  @name.camelcase
end

#one_ofsObject



38
39
40
41
42
43
44
45
46
47
# File 'lib/openapi2ruby/openapi/schema.rb', line 38

def one_ofs
  return [] if properties.empty?
  properties.each_with_object([]) do |value, results|
    if value.one_of?
      results << value.one_of_refs
    else
      results
    end
  end
end

#propertiesArray[Openapi2ruby::Openapi::Schema]

OpenAPI schema properties

Returns:



22
23
24
25
26
27
28
# File 'lib/openapi2ruby/openapi/schema.rb', line 22

def properties
  return [] if @definition['properties'].nil?
  @definition['properties'].each_with_object([]) do |(key, value), results|
    content = { name: key, definition: value }
    results << Openapi2ruby::Openapi::Schema::Property.new(content)
  end
end

#required?(property) ⇒ Boolean

Whether property is required or not

Parameters:

Returns:

  • (Boolean)


33
34
35
36
# File 'lib/openapi2ruby/openapi/schema.rb', line 33

def required?(property)
  return false if requireds.nil?
  requireds.include?(property.name)
end

#requiredsArray[String]

OpenAPI required properties name

Returns:

  • (Array[String])


16
17
18
# File 'lib/openapi2ruby/openapi/schema.rb', line 16

def requireds
  @definition['required']
end