class SoberSwag::Compiler::Paths

Compile multiple routes into a paths set. This basically just aggregates {SoberSwag::Controller::Route} objects.

Attributes

routes[R]

@return [Array<SoberSwag::Controller::Route>] the routes to document

Public Class Methods

new() click to toggle source

Set up a new paths compiler with no routes in it.

# File lib/sober_swag/compiler/paths.rb, line 9
def initialize
  @routes = []
end

Public Instance Methods

add_route(route) click to toggle source

Add on a new {SoberSwag::Controller::Route}

@param route [SoberSwag::Controller::Route] the route description to add to compilation @return [SoberSwag::Compiler::Paths] self

# File lib/sober_swag/compiler/paths.rb, line 18
def add_route(route)
  @routes << route

  self
end
found_types() { |public_send| ... } click to toggle source

Get a list of all types we discovered when compiling the paths.

@yield [Class] all the types found in all the routes described in here.

# 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() click to toggle source

In the OpenAPI V3 spec, we group action definitions by their path. This helps us do that.

# File lib/sober_swag/compiler/paths.rb, line 27
def grouped_paths
  routes.group_by(&:path)
end
paths_list(compiler) click to toggle source

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.

@param compiler [SoberSwag::Compiler::Type] the type compiler to use @return [Hash] a schema for all contained routes.

# 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

Private Instance Methods

compile_route(route, compiler) click to toggle source
# File lib/sober_swag/compiler/paths.rb, line 68
def compile_route(route, compiler)
  SoberSwag::Compiler::Path.new(route, compiler).schema
end