foobara-json-schema-generator 0.0.5 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7dbc744ffb92537271cfafd9f469c75aa7661ab6a4c5d395d905e3d95ccd986a
4
- data.tar.gz: 3ca5e0e634cc184e5338dea8e138c5dbc51d6e5c578de2d1b37f914053e6d0df
3
+ metadata.gz: 7496c412ff45f1dc6db1b129995b127be3b1b5008b4df3d4c2bb1b9c43b966b2
4
+ data.tar.gz: b89116242f86ca0d282eda61a9ca9def2f3f1c16bf34413c40686d3dcd111544
5
5
  SHA512:
6
- metadata.gz: e3e44501025bc736dbf0ca36be6f599c27756f5610f878b3b48313b4ef697b93707ff8be0aaa57ba144219c05db1f0c263f396b505a626687cb0a27d322bd743
7
- data.tar.gz: 74f1e6bd4cb4c0c359b070df0e31df22667d5447b05fd80bcd6d8d03dca7744a545e4d57d9dadc4516c30a85889fa94d6cf06abfab26eb9c3010922128bb5553
6
+ metadata.gz: 254bb5befa15e14b7dfff067cb20a547a907820ce5b20f4de41c6777a2a312ce9ac2198ed47c6f57334eded62aff966c5b373700dad16204fc19b37fc64ae1d2
7
+ data.tar.gz: ef69c5d5a90cfba4f0f2a28f36dcc8a72d8035c754bb7fad8def4988d87a3b24d0f51055f19f33f7ae2ab73425c5b9ef784ed3c5610042e35c8b69ee2c16d4ac
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## [1.0.0] - 2025-07-08
2
+
3
+ - Fix bug resulting in incorrect description when converting entity to primary key
4
+
5
+ ## [0.0.6] - 2025-06-19
6
+
7
+ - Improve the description on entity types converted to primary key types
8
+
1
9
  ## [0.0.5] - 2025-05-25
2
10
 
3
11
  - Support :attributes top-level type
@@ -1,35 +1,42 @@
1
- require_relative "association_depth"
2
-
3
1
  module Foobara
4
2
  module JsonSchemaGenerator
5
3
  class << self
6
- def to_json_schema(type, association_depth: AssociationDepth::ATOM)
4
+ def to_json_schema(type, association_depth: Foobara::AssociationDepth::ATOM)
7
5
  poro = to_json_schema_structure(type, association_depth:)
8
6
 
9
7
  JSON.fast_generate(poro)
10
8
  end
11
9
 
12
- def to_json_schema_structure(type, association_depth: AssociationDepth::ATOM)
10
+ def to_json_schema_structure(type, association_depth: Foobara::AssociationDepth::ATOM)
13
11
  foobara_type_to_json_schema_type_poro(type, association_depth:)
14
12
  end
15
13
 
16
14
  private
17
15
 
18
- def foobara_type_to_json_schema_type_poro(type, association_depth:, within_entity: false)
16
+ def foobara_type_to_json_schema_type_poro(type, association_depth:, within_entity: false, description: nil)
19
17
  declaration_data = type.declaration_data
20
18
 
21
- # from other place
22
19
  type_hash = if type.extends?(BuiltinTypes[:entity])
23
20
  target_class = type.target_class
24
21
 
25
- child_type = if association_depth == AssociationDepth::PRIMARY_KEY_ONLY ||
26
- (association_depth == AssociationDepth::ATOM && within_entity)
27
- target_class.primary_key_type
28
- else
29
- target_class.attributes_type
30
- end
22
+ if association_depth == AssociationDepth::PRIMARY_KEY_ONLY ||
23
+ (association_depth == AssociationDepth::ATOM && within_entity)
24
+ description = [
25
+ "#{target_class.model_name} #{target_class.primary_key_attribute}",
26
+ *type.description
27
+ ].join(" : ")
28
+
29
+ foobara_type_to_json_schema_type_poro(
30
+ target_class.primary_key_type,
31
+ description:,
32
+ association_depth:,
33
+ within_entity: true
34
+ )
35
+ else
36
+ foobara_type_to_json_schema_type_poro(target_class.attributes_type,
37
+ association_depth:, within_entity: true)
38
+ end
31
39
 
32
- foobara_type_to_json_schema_type_poro(child_type, association_depth:, within_entity: true)
33
40
  elsif type.extends?(BuiltinTypes[:model])
34
41
  foobara_type_to_json_schema_type_poro(type.target_class.attributes_type, association_depth:,
35
42
  within_entity:)
@@ -107,7 +114,9 @@ module Foobara
107
114
  type_hash[:type] = [type_hash[:type], "null"]
108
115
  end
109
116
 
110
- if !type.builtin? && type.description
117
+ if description
118
+ type_hash[:description] = description
119
+ elsif !type.builtin? && type.description
111
120
  type_hash[:description] = type.description
112
121
  end
113
122
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foobara-json-schema-generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-05-26 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: foobara
@@ -35,7 +35,6 @@ files:
35
35
  - LICENSE.txt
36
36
  - README.md
37
37
  - lib/foobara/json_schema_generator.rb
38
- - src/association_depth.rb
39
38
  - src/json_schema_generator.rb
40
39
  homepage: https://github.com/foobara/json-schema-generator
41
40
  licenses:
@@ -59,7 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
59
58
  - !ruby/object:Gem::Version
60
59
  version: '0'
61
60
  requirements: []
62
- rubygems_version: 3.6.2
61
+ rubygems_version: 3.6.9
63
62
  specification_version: 4
64
63
  summary: Takes a Foobara type and converts it to a json schema
65
64
  test_files: []
@@ -1,9 +0,0 @@
1
- module Foobara
2
- module JsonSchemaGenerator
3
- module AssociationDepth
4
- PRIMARY_KEY_ONLY = :primary_key_only
5
- ATOM = :atom
6
- AGGREGATE = :aggregate
7
- end
8
- end
9
- end