Class: Jdoc::Schema
- Inherits:
-
Object
- Object
- Jdoc::Schema
- Defined in:
- lib/jdoc/schema.rb
Constant Summary collapse
- DEFAULT_ENDPOINT =
"https://api.example.com"
Instance Method Summary collapse
-
#description ⇒ String?
Description property of this schema.
- #host_with_port ⇒ String
-
#initialize(schema) ⇒ Schema
constructor
A new instance of Schema.
-
#resources ⇒ Array<Jdoc::Resource>
All top-level properties in its title order.
-
#title ⇒ String?
Title property of this schema.
Constructor Details
#initialize(schema) ⇒ Schema
Returns a new instance of Schema.
6 7 8 |
# File 'lib/jdoc/schema.rb', line 6 def initialize(schema) @json_schema = JsonSchema.parse!(schema).tap(&:expand_references!) end |
Instance Method Details
#description ⇒ String?
Returns Description property of this schema.
27 28 29 30 31 |
# File 'lib/jdoc/schema.rb', line 27 def description if @json_schema.description "#{@json_schema.description}\n\n" end end |
#host_with_port ⇒ String
37 38 39 40 41 42 43 |
# File 'lib/jdoc/schema.rb', line 37 def host_with_port if [80, 443].include?(port) host else "#{host}:#{port}" end end |
#resources ⇒ Array<Jdoc::Resource>
Returns All top-level properties in its title order.
11 12 13 14 15 |
# File 'lib/jdoc/schema.rb', line 11 def resources @resources ||= @json_schema.properties.map do |key, property| Resource.new(property) end.sort end |
#title ⇒ String?
Returns Title property of this schema.
20 21 22 |
# File 'lib/jdoc/schema.rb', line 20 def title @json_schema.title end |