-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into fixes/vanilla-error
- Loading branch information
Showing
237 changed files
with
1,945 additions
and
1,173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ orbs: | |
browser-tools: circleci/[email protected] | ||
aliases: | ||
- &ruby_node_browsers_docker_image | ||
- image: cimg/ruby:3.2.1-browsers | ||
- image: cimg/ruby:3.2.2-browsers | ||
environment: | ||
PGHOST: localhost | ||
PGUSER: untitled_application | ||
|
@@ -29,7 +29,7 @@ jobs: | |
steps: | ||
- checkout | ||
- browser-tools/install-browser-tools: | ||
firefox-version: 108.0.1 | ||
firefox-version: "112.0" | ||
|
||
- ruby/install-deps: | ||
clean-bundle: true | ||
|
@@ -62,7 +62,7 @@ jobs: | |
- checkout: | ||
path: ~/project | ||
- browser-tools/install-browser-tools: | ||
firefox-version: 108.0.1 | ||
firefox-version: "112.0" | ||
|
||
# TODO: This is a workaround to get `git clone` working, but it shouldn't be here. | ||
# https://github.com/CircleCI-Public/browser-tools-orb/issues/62 | ||
|
@@ -114,7 +114,7 @@ jobs: | |
- checkout: | ||
path: ~/project | ||
- browser-tools/install-browser-tools: | ||
firefox-version: 108.0.1 | ||
firefox-version: "112.0" | ||
|
||
# TODO: This is a workaround to get `git clone` working, but it shouldn't be here. | ||
# https://github.com/CircleCI-Public/browser-tools-orb/issues/62 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
source "https://rubygems.org" | ||
git_source(:github) { |repo| "https://github.com/#{repo}.git" } | ||
|
||
ruby "3.2.1" | ||
ruby "3.2.2" | ||
|
||
gem "standard" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 1 addition & 124 deletions
125
bullet_train-api/app/controllers/api/open_api_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,128 +1,5 @@ | ||
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 | ||
|
||
# TODO: Remove this method? It's not being used anywhere | ||
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 gem_paths | ||
@gem_paths ||= `bundle show --paths`.lines.map { |gem_path| gem_path.chomp } | ||
end | ||
|
||
def automatic_paths_for(model, parent, except: []) | ||
output = render("api/#{@version}/open_api/shared/paths", except: except) | ||
output = Scaffolding::Transformer.new(model.name, [parent&.name]).transform_string(output).html_safe | ||
indent(output, 1) | ||
end | ||
|
||
def automatic_components_for(model, locals: {}) | ||
path = "app/views/api/#{@version}" | ||
paths = ([path] + gem_paths.map { |gem_path| "#{gem_path}/#{path}" }) | ||
jbuilder = Jbuilder::Schema.renderer(paths, locals: { | ||
# If we ever get to the point where we need a real model here, we should implement an example team in seeds that we can source it from. | ||
model.name.underscore.split("/").last.to_sym => model.new, | ||
# Same here, if we ever need this to be a real object, this should be `[email protected]` with an `SecureRandom.hex` password. | ||
:current_user => User.new | ||
}.merge(locals)) | ||
|
||
schema_json = jbuilder.json( | ||
model.new, | ||
title: I18n.t("#{model.name.underscore.pluralize}.label"), | ||
# TODO Improve this. We don't have a generic description for models we can use here. | ||
description: I18n.t("#{model.name.underscore.pluralize}.label"), | ||
) | ||
|
||
attributes_output = JSON.parse(schema_json) | ||
|
||
# Rails attachments aren't technically attributes in a model, | ||
# so we add the attributes manually to make them available in the API. | ||
if model.attachment_reflections.any? | ||
model.attachment_reflections.each do |reflection| | ||
attribute_name = reflection.first | ||
|
||
attributes_output["properties"][attribute_name] = { | ||
"type" => "object", | ||
"description" => attribute_name.titleize.to_s | ||
} | ||
|
||
attributes_output["example"].merge!({attribute_name.to_s => nil}) | ||
end | ||
end | ||
|
||
if has_strong_parameters?("Api::#{@version.upcase}::#{model.name.pluralize}Controller".constantize) | ||
strong_params_module = "Api::#{@version.upcase}::#{model.name.pluralize}Controller::StrongParameters".constantize | ||
strong_parameter_keys = BulletTrain::Api::StrongParametersReporter.new(model, strong_params_module).report | ||
if strong_parameter_keys.last.is_a?(Hash) | ||
strong_parameter_keys += strong_parameter_keys.pop.keys | ||
end | ||
|
||
parameters_output = JSON.parse(schema_json) | ||
parameters_output["required"].select! { |key| strong_parameter_keys.include?(key.to_sym) } | ||
parameters_output["properties"].select! { |key, value| strong_parameter_keys.include?(key.to_sym) } | ||
|
||
( | ||
indent(attributes_output.to_yaml.gsub("---", "#{model.name.gsub("::", "")}Attributes:"), 3) + | ||
indent(" " + parameters_output.to_yaml.gsub("---", "#{model.name.gsub("::", "")}Parameters:"), 3) | ||
).html_safe | ||
else | ||
|
||
indent(attributes_output.to_yaml.gsub("---", "#{model.name.gsub("::", "")}Attributes:"), 3) | ||
.html_safe | ||
end | ||
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") | ||
attribute_data = current_model.columns_hash[attribute.to_s] | ||
|
||
# Default to `string` when the type returns nil. | ||
type = attribute_data.nil? ? "string" : attribute_data.type | ||
|
||
attribute_block = <<~YAML | ||
#{attribute}: | ||
description: "#{heading}" | ||
type: #{type} | ||
YAML | ||
indent(attribute_block.chomp, 2) | ||
end | ||
alias_method :parameter, :attribute | ||
|
||
private | ||
|
||
def has_strong_parameters?(controller) | ||
methods = controller.action_methods | ||
methods.include?("create") || methods.include?("update") | ||
end | ||
end | ||
|
||
class Api::OpenApiController < ApplicationController | ||
helper :open_api | ||
helper "api/open_api" | ||
|
||
def set_default_response_format | ||
request.format = :yaml | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.