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 d10807f64..6c8314bb4 100644 --- a/bullet_train-api/app/helpers/api/open_api_helper.rb +++ b/bullet_train-api/app/helpers/api/open_api_helper.rb @@ -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"), @@ -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) +