Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Empty examples in schemas in OpenAPI #236

Merged
merged 2 commits into from
Aug 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading