Skip to content

Commit

Permalink
Fix: Send FactoryBot examples to JbuilderSchema for proper attributes…
Browse files Browse the repository at this point in the history
… and properties examples in schemas
  • Loading branch information
newstler committed Apr 9, 2023
1 parent d1d9be1 commit ffd9181
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions bullet_train-api/app/helpers/api/open_api_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def automatic_components_for(model, locals: {})
}.merge(locals))

schema_json = jbuilder.json(
model.new,
FactoryBot.example(model.name.underscore.to_sym) || 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"),
Expand Down Expand Up @@ -103,7 +103,8 @@ def automatic_components_for(model, locals: {})

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) }
parameters_output["properties"].select! { |key| strong_parameter_keys.include?(key.to_sym) }
parameters_output["example"]&.select! { |key, value| strong_parameter_keys.include?(key.to_sym) && value.present? }

(
indent(attributes_output.to_yaml.gsub("---", "#{model.name.gsub("::", "")}Attributes:"), 3) +
Expand Down

0 comments on commit ffd9181

Please sign in to comment.