Class: SoberSwag::Compiler::Paths
- Inherits:
-
Object
- Object
- SoberSwag::Compiler::Paths
- Defined in:
- lib/sober_swag/compiler/paths.rb
Overview
Compile multiple routes into a paths set. This basically just aggregates SoberSwag::Controller::Route objects.
Instance Attribute Summary collapse
-
#routes ⇒ Array<SoberSwag::Controller::Route>
readonly
The routes to document.
Instance Method Summary collapse
-
#add_route(route) ⇒ SoberSwag::Compiler::Paths
Add on a new SoberSwag::Controller::Route.
- #compile_route(route, compiler) ⇒ Object private
-
#found_types {|Class| ... } ⇒ Object
Get a list of all types we discovered when compiling the paths.
-
#grouped_paths ⇒ Object
In the OpenAPI V3 spec, we group action definitions by their path.
-
#initialize ⇒ Paths
constructor
Set up a new paths compiler with no routes in it.
-
#paths_list(compiler) ⇒ Hash
Slightly weird method that gives you a compiled paths list.
Constructor Details
#initialize ⇒ Paths
Set up a new paths compiler with no routes in it.
9 10 11 |
# File 'lib/sober_swag/compiler/paths.rb', line 9 def initialize @routes = [] end |
Instance Attribute Details
#routes ⇒ Array<SoberSwag::Controller::Route> (readonly)
Returns the routes to document.
64 65 66 |
# File 'lib/sober_swag/compiler/paths.rb', line 64 def routes @routes end |
Instance Method Details
#add_route(route) ⇒ SoberSwag::Compiler::Paths
Add on a new SoberSwag::Controller::Route
18 19 20 21 22 |
# File 'lib/sober_swag/compiler/paths.rb', line 18 def add_route(route) @routes << route self end |
#compile_route(route, compiler) ⇒ Object (private)
68 69 70 |
# File 'lib/sober_swag/compiler/paths.rb', line 68 def compile_route(route, compiler) SoberSwag::Compiler::Path.new(route, compiler).schema end |
#found_types {|Class| ... } ⇒ Object
Get a list of all types we discovered when compiling the paths.
52 53 54 55 56 57 58 59 60 |
# File 'lib/sober_swag/compiler/paths.rb', line 52 def found_types return enum_for(:found_types) unless block_given? routes.each do |route| %i[body_class query_class path_params_class].each do |k| yield route.public_send(k) if route.public_send(k) end end end |
#grouped_paths ⇒ Object
In the OpenAPI V3 spec, we group action definitions by their path. This helps us do that.
27 28 29 |
# File 'lib/sober_swag/compiler/paths.rb', line 27 def grouped_paths routes.group_by(&:path) end |
#paths_list(compiler) ⇒ Hash
Slightly weird method that gives you a compiled paths list. Since this is only a compiler for paths, it has no idea how to handle types. So, it takes a compiler which it will use to do that for it.
39 40 41 42 43 44 45 |
# File 'lib/sober_swag/compiler/paths.rb', line 39 def paths_list(compiler) grouped_paths.transform_values do |values| values.map { |route| [route.method, compile_route(route, compiler)] }.to_h end end |