class OpenApiDocumentation::Base

Public Class Methods

new(app, prefix, chunks) click to toggle source
# File lib/apiculture/openapi_documentation.rb, line 6
def initialize(app, prefix, chunks)
  @app, @prefix = app, prefix
  @paths = chunks.select { |chunk| chunk.respond_to?(:http_verb) }
  @data = {
    openapi: '3.0.0',
    info: {
      title: @app.to_s,
      version: '0.0.1',
      description: @app.to_s + " " + chunks.select { |chunk| chunk.respond_to?(:to_markdown) }.map(&:to_markdown).join("\n")
    },
    tags: []
  }
  @data[:paths] = build_paths
end

Public Instance Methods

paths() click to toggle source
# File lib/apiculture/openapi_documentation.rb, line 25
def paths
  @data[:paths]
end
spec() click to toggle source
# File lib/apiculture/openapi_documentation.rb, line 29
def spec
  @data
end
to_yaml() click to toggle source
# File lib/apiculture/openapi_documentation.rb, line 21
def to_yaml
  JSON.load(@data.to_json).to_yaml # trickery to get string based yaml
end

Private Instance Methods

build_paths() click to toggle source
# File lib/apiculture/openapi_documentation.rb, line 35
def build_paths
  paths = {}
  @paths.each do |path|
    path = Path.new(path, @prefix, @app)
    paths = merge_paths(paths, path)
  end
  paths
end
merge_paths(paths, path) click to toggle source

We don’t have deep_merge here so this is the poor man’s alternative

# File lib/apiculture/openapi_documentation.rb, line 45
def merge_paths(paths, path)
  if paths.key?(path.name)
    paths[path.name].merge!(path.build[path.name])
  else
    paths.merge!(path.build)
  end
  paths
end