Class: Openapi2ruby::Openapi::Schema
- Inherits:
-
Object
- Object
- Openapi2ruby::Openapi::Schema
- Defined in:
- lib/openapi2ruby/openapi/schema.rb
Defined Under Namespace
Classes: Property
Instance Method Summary collapse
-
#initialize(content) ⇒ Schema
constructor
A new instance of Schema.
-
#name ⇒ String
OpenAPI camelcase schema name.
- #one_ofs ⇒ Object
-
#properties ⇒ Array[Openapi2ruby::Openapi::Schema]
OpenAPI schema properties.
-
#required?(property) ⇒ Boolean
Whether property is required or not.
-
#requireds ⇒ Array[String]
OpenAPI required properties name.
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
#name ⇒ String
OpenAPI camelcase schema name
10 11 12 |
# File 'lib/openapi2ruby/openapi/schema.rb', line 10 def name @name.camelcase end |
#one_ofs ⇒ Object
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 |
#properties ⇒ Array[Openapi2ruby::Openapi::Schema]
OpenAPI schema properties
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
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 |
#requireds ⇒ Array[String]
OpenAPI required properties name
16 17 18 |
# File 'lib/openapi2ruby/openapi/schema.rb', line 16 def requireds @definition['required'] end |