diff --git a/bullet_train-api/app/helpers/api/open_api_helper.rb b/bullet_train-api/app/helpers/api/open_api_helper.rb index a073d0ccb..120b4a7ce 100644 --- a/bullet_train-api/app/helpers/api/open_api_helper.rb +++ b/bullet_train-api/app/helpers/api/open_api_helper.rb @@ -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"), @@ -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) +