Class: Jdoc::Schema

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(schema) ⇒ Schema

Returns a new instance of Schema.

Parameters:

  • schema (Hash)

    JSON Schema



12
13
14
# File 'lib/jdoc/schema.rb', line 12

def initialize(schema)
  @json_schema = JsonSchema.parse!(schema).tap(&:expand_references!)
end

Class Method Details

Recursively extracts all links in given JSON schema

Parameters:

  • json_schema (JsonSchema::Schema)

Returns:

  • (Array)

    An array of JsonSchema::Schema::Link



6
7
8
9
# File 'lib/jdoc/schema.rb', line 6

def self.extract_links(json_schema)
  links = json_schema.links.select {|link| link.method && link.href }
  links + json_schema.properties.map {|key, schema| extract_links(schema) }.flatten
end

Instance Method Details

Returns Linkes table indexed by their schemata.

Returns:

  • (Hash{Jdoc::Schema => Array})

    Linkes table indexed by their schemata



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

def links_indexed_by_resource
  @links_indexed_by_schema ||= links.inject(Hash.new {|h, k| h[k] = [] }) do |result, link|
    result[link.resource] << link
    result
  end
end

#titleString?

Returns Title property of this schema.

Examples:

schema.title #=> "app"

Returns:

  • (String, nil)

    Title property of this schema



27
28
29
# File 'lib/jdoc/schema.rb', line 27

def title
  @json_schema.title
end