diff --git a/README.md b/README.md index d71ab4a..a663852 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Jbuilder::Schema -Easily Generate JSON Schemas from Jbuilder Templates for OpenAPI 3.1 +Easily Generate OpenAPI 3.1 Schemas from Jbuilder Templates ## Quick Start @@ -325,9 +325,9 @@ The `title_name` and `description_name` parameters can accept either a single st ```ruby Jbuilder::Schema.configure do |config| - config.components_path = "components/schemas" # could be "definitions/schemas" - config.title_name = "title" # could be "label" - config.description_name = ["api_description", "description"] # could be "heading" + config.components_path = "components/schemas" # could be "definitions/schemas" + config.title_name = "title" # could be "label", or an array to support fallbacks, like + config.description_name = %w[api_description description] # could be just string as well like "heading" end ``` diff --git a/lib/jbuilder/schema/template.rb b/lib/jbuilder/schema/template.rb index f6284d4..de1e297 100644 --- a/lib/jbuilder/schema/template.rb +++ b/lib/jbuilder/schema/template.rb @@ -52,7 +52,9 @@ def translate(keys) translation = I18n.t(key, scope: @scope ||= object&.class&.name&.underscore&.pluralize, default: nil) return translation if translation.present? end - I18n.t(keys.first, scope: @scope ||= object&.class&.name&.underscore&.pluralize) + # FIXME: This produces `addresses/countries` for namespaced models. + # Should be probably `addresses.countries` + I18n.t(keys.first, scope: @scope ||= object&.class&.model_name&.collection) end def title_keys @@ -209,7 +211,7 @@ def _set_title_and_description(key, value) overrides = @schema_overrides&.dig(key)&.to_h || {} return unless overrides.any? || @configuration.object - value[:title] ||= overrides[:title] if overrides&.key?(:title) + value[:title] ||= overrides[:title] if overrides.key?(:title) value[:description] ||= overrides[:description] || @configuration.translate_description(key) end diff --git a/lib/jbuilder/schema/version.rb b/lib/jbuilder/schema/version.rb index 2070463..c3c51f3 100644 --- a/lib/jbuilder/schema/version.rb +++ b/lib/jbuilder/schema/version.rb @@ -1,4 +1,4 @@ # We can't use the standard `Jbuilder::Schema::VERSION =` because # `Jbuilder` isn't a regular module namespace, but a class …which also loads Active Support. # So we use trickery, and assign the proper version once `jbuilder/schema.rb` is loaded. -JBUILDER_SCHEMA_VERSION = "2.6.8" +JBUILDER_SCHEMA_VERSION = "2.6.9"