jbuilder-schema 2.6.8 → 2.6.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3f75cc13caa4465745a822b1bd1d7e66899fa1bb2387457d1e638ba1df9e360a
4
- data.tar.gz: 6ec03326e02493379e9e97e2c9d50eac1f1bfb4a4cc340c1e3941774cddde6c6
3
+ metadata.gz: dc6b74ad43767a8a12d27263b224beb94b8a3aa4deab865e81fb2753ff367718
4
+ data.tar.gz: 03243e798c0e28991c926b52b90d448b79d7f66aa0f59b997d9fd384b5d4bd28
5
5
  SHA512:
6
- metadata.gz: 9704440704b61701c9b3852a97b86b4dbed7e4456e8fbf37934cab3978690d41fe4fd9c7fa786ef1479da9c3b8be53e67cc0a05516073481f21eaabeb864921a
7
- data.tar.gz: b875004bb14f11ba6eed4a8f1ca77675bb7b2484e5c97676943fb21fe1023aedb8b263476191517b45f89ab7c15bd2c2f1a1e97e1a2082bc002f7734454ed310
6
+ metadata.gz: aaa65e842309918131ba5ae7f01f2063dcd9312505d9677a1037bab01801b8eab1865b8cd00daeca3712cbf367dd5494526939468623b4b1af706c86ac6c5751
7
+ data.tar.gz: a12318b8132a8a6edca71fcfe746dc6a757afe7a105405c17ca9ba22683ad7ebd51c4978bad692ab90c81f14d242ebf0dba016d6ff4e9fc039cc9b816ed007e5
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Jbuilder::Schema
2
2
 
3
- Easily Generate JSON Schemas from Jbuilder Templates for OpenAPI 3.1
3
+ Easily Generate OpenAPI 3.1 Schemas from Jbuilder Templates
4
4
 
5
5
  ## Quick Start
6
6
 
@@ -321,14 +321,18 @@ en:
321
321
 
322
322
  Configure Jbuilder::Schema in `config/initializers/jbuilder_schema.rb`:
323
323
 
324
+ The `title_name` and `description_name` parameters can accept either a single string or an array of strings. This feature provides the flexibility to specify fallback keys.
325
+
324
326
  ```ruby
325
327
  Jbuilder::Schema.configure do |config|
326
- config.components_path = "components/schemas" # could be "definitions/schemas"
327
- config.title_name = "title" # could be "label"
328
- config.description_name = "description" # could be "heading"
328
+ config.components_path = "components/schemas" # could be "definitions/schemas"
329
+ config.title_name = "title" # could be "label", or an array to support fallbacks, like
330
+ config.description_name = %w[api_description description] # could be just string as well like "heading"
329
331
  end
330
332
  ```
331
333
 
334
+ With this configuration, the system will first try to find a translation for <underscored_plural_model_name>.fields.<field_name>.api_description. If it doesn't find a translation for this key, it will then attempt to find a translation for <underscored_plural_model_name>.fields.<field_name>.description.
335
+
332
336
  ### Integration with RSwag
333
337
 
334
338
  Use `yaml`/`json` methods in your `swagger_helper.rb` for Swagger documentation:
@@ -30,25 +30,39 @@ class Jbuilder::Schema
30
30
  end
31
31
 
32
32
  def title
33
- super || translate(Jbuilder::Schema.title_name)
33
+ super || translate(title_keys)
34
34
  end
35
35
 
36
36
  def description
37
- super || translate(Jbuilder::Schema.description_name)
37
+ super || translate(description_keys)
38
38
  end
39
39
 
40
40
  def translate_title(key)
41
- translate("fields.#{key}.#{Jbuilder::Schema.title_name}")
41
+ translate(title_keys.map { |k| "fields.#{key}.#{k}" })
42
42
  end
43
43
 
44
44
  def translate_description(key)
45
- translate("fields.#{key}.#{Jbuilder::Schema.description_name}")
45
+ translate(description_keys.map { |k| "fields.#{key}.#{k}" })
46
46
  end
47
47
 
48
48
  private
49
49
 
50
- def translate(key)
51
- I18n.t(key, scope: @scope ||= object&.class&.name&.underscore&.pluralize)
50
+ def translate(keys)
51
+ keys.each do |key|
52
+ translation = I18n.t(key, scope: @scope ||= object&.class&.name&.underscore&.pluralize, default: nil)
53
+ return translation if translation.present?
54
+ end
55
+ # FIXME: This produces `addresses/countries` for namespaced models.
56
+ # Should be probably `addresses.countries`
57
+ I18n.t(keys.first, scope: @scope ||= object&.class&.model_name&.collection)
58
+ end
59
+
60
+ def title_keys
61
+ Array(Jbuilder::Schema.title_name)
62
+ end
63
+
64
+ def description_keys
65
+ Array(Jbuilder::Schema.description_name)
52
66
  end
53
67
  end
54
68
 
@@ -197,7 +211,7 @@ class Jbuilder::Schema
197
211
  overrides = @schema_overrides&.dig(key)&.to_h || {}
198
212
  return unless overrides.any? || @configuration.object
199
213
 
200
- value[:title] ||= overrides[:title] if overrides&.key?(:title)
214
+ value[:title] ||= overrides[:title] if overrides.key?(:title)
201
215
  value[:description] ||= overrides[:description] || @configuration.translate_description(key)
202
216
  end
203
217
 
@@ -1,4 +1,4 @@
1
1
  # We can't use the standard `Jbuilder::Schema::VERSION =` because
2
2
  # `Jbuilder` isn't a regular module namespace, but a class …which also loads Active Support.
3
3
  # So we use trickery, and assign the proper version once `jbuilder/schema.rb` is loaded.
4
- JBUILDER_SCHEMA_VERSION = "2.6.8"
4
+ JBUILDER_SCHEMA_VERSION = "2.6.9"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jbuilder-schema
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.6.8
4
+ version: 2.6.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuri Sidorov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-12-06 00:00:00.000000000 Z
11
+ date: 2024-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jbuilder
@@ -89,7 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
89
89
  - !ruby/object:Gem::Version
90
90
  version: '0'
91
91
  requirements: []
92
- rubygems_version: 3.4.10
92
+ rubygems_version: 3.5.6
93
93
  signing_key:
94
94
  specification_version: 4
95
95
  summary: Generate JSON Schema from Jbuilder files