Sha256: 26d5f2df1e1a7e7221ed802b27a444e93ccaddf0d67573dc08a917f232f245fc

Contents?: true

Size: 1.48 KB

Versions: 3

Compression:

Stored size: 1.48 KB

Contents

module OpenApiHelper
  def indent(string, count)
    lines = string.lines
    first_line = lines.shift
    lines = lines.map { |line| ("  " * count).to_s + line }
    lines.unshift(first_line).join.html_safe
  end

  def components_for(model)
    for_model model do
      indent(render("api/#{@version}/open_api/#{model.name.underscore.pluralize}/components"), 2)
    end
  end

  def current_model
    @model_stack.last
  end

  def for_model(model)
    @model_stack ||= []
    @model_stack << model
    result = yield
    @model_stack.pop
    result
  end

  def paths_for(model)
    for_model model do
      indent(render("api/#{@version}/open_api/#{model.name.underscore.pluralize}/paths"), 1)
    end
  end

  def attribute(attribute)
    heading = t("#{current_model.name.underscore.pluralize}.fields.#{attribute}.heading")
    # TODO A lot of logic to be done here.
    indent("#{attribute}:\n  description: \"#{heading}\"\n  type: string", 2)
  end

  def parameter(attribute)
    heading = t("#{current_model.name.underscore.pluralize}.fields.#{attribute}.heading")
    # TODO A lot of logic to be done here.
    indent("#{attribute}:\n  description: \"#{heading}\"\n  type: string", 2)
  end
end

class Api::OpenApiController < ApplicationController
  helper :open_api

  def set_default_response_format
    request.format = :yaml
  end

  before_action :set_default_response_format

  def index
    @version = params[:version]
    render "api/#{@version}/open_api/index", layout: nil, format: :text
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
bullet_train-api-1.1.6 app/controllers/api/open_api_controller.rb
bullet_train-api-1.1.5 app/controllers/api/open_api_controller.rb
bullet_train-api-1.1.4 app/controllers/api/open_api_controller.rb