Class: Jdoc::Schema

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

Constant Summary collapse

DEFAULT_ENDPOINT =
"https://api.example.com"

Instance Method Summary collapse

Constructor Details

#initialize(schema) ⇒ 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

#descriptionString?

Returns Description property of this schema.

Examples:

schema.description #=> "A schema for a small example API."


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_portString

Examples:

host_with_port #=> "api.example.com"
host_with_port #=> "api.example.com:3000"


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

#resourcesArray<Jdoc::Resource>



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

#titleString?

Returns Title property of this schema.

Examples:

schema.title #=> "app"


20
21
22
# File 'lib/jdoc/schema.rb', line 20

def title
  @json_schema.title
end