Class: Aho::Schema::Parser

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

Constant Summary collapse

OPENAPI_FILE =
'openapi.yml'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method, path, destination) ⇒ Parser

Returns a new instance of Parser.



10
11
12
13
14
15
# File 'lib/aho/schema/parser.rb', line 10

def initialize(method, path, destination)
  @method = method
  @path = path
  @destination = destination
  @openapi_paths = YAML.load_file(File.join(Aho.root_path, OPENAPI_FILE))['paths']
end

Instance Attribute Details

#destinationObject (readonly)

Returns the value of attribute destination.



8
9
10
# File 'lib/aho/schema/parser.rb', line 8

def destination
  @destination
end

#methodObject (readonly)

Returns the value of attribute method.



8
9
10
# File 'lib/aho/schema/parser.rb', line 8

def method
  @method
end

#openapi_pathsObject (readonly)

Returns the value of attribute openapi_paths.



8
9
10
# File 'lib/aho/schema/parser.rb', line 8

def openapi_paths
  @openapi_paths
end

#pathObject (readonly)

Returns the value of attribute path.



8
9
10
# File 'lib/aho/schema/parser.rb', line 8

def path
  @path
end

Instance Method Details

#actionObject



21
22
23
# File 'lib/aho/schema/parser.rb', line 21

def action
  destination.split('#').last
end

#controllerObject



17
18
19
# File 'lib/aho/schema/parser.rb', line 17

def controller
  "#{destination.split('#').first.split('/').map(&:capitalize).join('::')}Controller"
end

#schemaObject



25
26
27
# File 'lib/aho/schema/parser.rb', line 25

def schema
  remove_descriptions(openapi_paths.dig(path, method, 'requestBody', 'content', 'application/json', 'schema'))
end