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

Small fixes and version bump #85

Merged
merged 1 commit into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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
```

Expand Down
6 changes: 4 additions & 2 deletions lib/jbuilder/schema/template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/jbuilder/schema/version.rb
Original file line number Diff line number Diff line change
@@ -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"