Skip to content

Commit

Permalink
Fix: Empty examples in schemas in OpenAPI (#236)
Browse files Browse the repository at this point in the history
* Fix: Send FactoryBot examples to JbuilderSchema for proper attributes and properties examples in schemas

* Fix: namespaced model names transform to undercored
  • Loading branch information
newstler authored Aug 24, 2023
1 parent c3f7c94 commit 28873ec
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 @@ -60,7 +60,7 @@ def automatic_components_for(model, locals: {})
}.merge(locals))

schema_json = jbuilder.json(
model.new,
FactoryBot.example(model.model_name.param_key.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 @@ -92,7 +92,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 28873ec

Please sign in to comment.