Class: Starter::Importer::Specification

Inherits:
Object
  • Object
show all
Defined in:
lib/starter/importer/specification.rb

Defined Under Namespace

Classes: Error

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(spec:) ⇒ Specification

Returns a new instance of Specification.



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/starter/importer/specification.rb', line 11

def initialize(spec:)
  # mandatory
  @openapi = spec.fetch('openapi')
  @info = spec.fetch('info')

  # in contrast to the spec, paths are required
  @paths = spec.fetch('paths').except('/').sort.to_h

  # optional -> not used atm
  @components = spec.fetch('components', false)
  @webhooks = spec.fetch('webhooks', false)
end

Instance Attribute Details

#componentsObject

Returns the value of attribute components.



8
9
10
# File 'lib/starter/importer/specification.rb', line 8

def components
  @components
end

#infoObject

Returns the value of attribute info.



8
9
10
# File 'lib/starter/importer/specification.rb', line 8

def info
  @info
end

#openapiObject

Returns the value of attribute openapi.



8
9
10
# File 'lib/starter/importer/specification.rb', line 8

def openapi
  @openapi
end

#pathsObject

Returns the value of attribute paths.



8
9
10
# File 'lib/starter/importer/specification.rb', line 8

def paths
  @paths
end

#webhooksObject

Returns the value of attribute webhooks.



8
9
10
# File 'lib/starter/importer/specification.rb', line 8

def webhooks
  @webhooks
end

Instance Method Details

#namespacesObject



24
25
26
27
28
29
30
31
32
33
# File 'lib/starter/importer/specification.rb', line 24

def namespaces
  validate_paths

  @namespaces ||= paths.keys.each_with_object({}) do |path, memo|
    namespace, rest_path = segmentize(path)

    memo[namespace] ||= {}
    memo[namespace][rest_path] = prepare_verbs(paths[path])
  end
end