structify 0.3.2 → 0.3.4
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 +4 -4
- data/CHANGELOG.md +14 -0
- data/Gemfile.lock +1 -1
- data/README.md +1 -1
- data/lib/structify/model.rb +10 -6
- data/lib/structify/schema_serializer.rb +37 -5
- data/lib/structify/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b7adef1550b7b34f172ceeea0509d60cc709a211732a12a5dd48c402be9dfa9f
|
4
|
+
data.tar.gz: 56198ac66113f0f857e7a79dc13addea1e4a01efd8a62330c0067899a731a48d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d9f5f3cf3d39d1d3b837ac0ed0118d7accfd2ac4d21f9b3385d9c7179fbb24771801387f545754205abb8418a6cb4a9d20141689d8d5f9f2d7669d061cc07fd2
|
7
|
+
data.tar.gz: 9b75d78dcb6a1202952ce3253690ca9e8290c7970759258290a7a13f1f1e2cf625086969b40fbc5f138f4021efa0c55dbce02544457b5571b756e46034e8d428
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,20 @@
|
|
2
2
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
|
5
|
+
## [0.3.4] - 2025-03-19
|
6
|
+
|
7
|
+
### Changed
|
8
|
+
|
9
|
+
- Renamed schema `title` to `name` to align with JSON Schema standards
|
10
|
+
- Added validation for schema name to ensure it matches the pattern `^[a-zA-Z0-9_-]+$`
|
11
|
+
|
12
|
+
## [0.3.3] - 2025-03-19
|
13
|
+
|
14
|
+
### Fixed
|
15
|
+
|
16
|
+
- Fixed versioning in JSON schema generation to only include fields for the current schema version
|
17
|
+
- Fields with `versions: x` no longer appear in other schema versions when generating the JSON schema
|
18
|
+
|
5
19
|
## [0.3.2] - 2025-03-17
|
6
20
|
|
7
21
|
### Added
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
data/lib/structify/model.rb
CHANGED
@@ -111,11 +111,11 @@ module Structify
|
|
111
111
|
class SchemaBuilder
|
112
112
|
# @return [Class] The model class
|
113
113
|
# @return [Array<Hash>] The field definitions
|
114
|
-
# @return [String] The schema
|
114
|
+
# @return [String] The schema name
|
115
115
|
# @return [String] The schema description
|
116
116
|
# @return [Integer] The schema version
|
117
117
|
# @return [Boolean] Whether thinking mode is enabled
|
118
|
-
attr_reader :model, :fields, :
|
118
|
+
attr_reader :model, :fields, :name_str, :description_str, :version_number, :thinking_enabled
|
119
119
|
|
120
120
|
# Initialize a new SchemaBuilder
|
121
121
|
#
|
@@ -136,12 +136,16 @@ module Structify
|
|
136
136
|
@thinking_enabled = enabled
|
137
137
|
end
|
138
138
|
|
139
|
-
# Set the schema
|
139
|
+
# Set the schema name
|
140
140
|
#
|
141
|
-
# @param
|
141
|
+
# @param value [String] The name
|
142
142
|
# @return [void]
|
143
|
-
def
|
144
|
-
|
143
|
+
def name(value)
|
144
|
+
# Validate the name pattern (must match ^[a-zA-Z0-9_-]+$)
|
145
|
+
unless value =~ /^[a-zA-Z0-9_-]+$/
|
146
|
+
raise ArgumentError, "Schema name must only contain alphanumeric characters, underscores, and hyphens"
|
147
|
+
end
|
148
|
+
@name_str = value
|
145
149
|
end
|
146
150
|
|
147
151
|
# Set the schema description
|
@@ -22,12 +22,33 @@ module Structify
|
|
22
22
|
|
23
23
|
# Get fields that are applicable to the current schema version
|
24
24
|
fields = schema_builder.fields.select do |f|
|
25
|
-
# Check if the field has a version_range
|
25
|
+
# Check if the field has a version_range - this is the primary way versions are stored
|
26
26
|
if f[:version_range]
|
27
|
-
|
27
|
+
case f[:version_range]
|
28
|
+
when Range
|
29
|
+
# For ranges like 1..2, 2..3, etc.
|
30
|
+
f[:version_range].cover?(current_version)
|
31
|
+
when Array
|
32
|
+
# For arrays like [1, 3, 5]
|
33
|
+
f[:version_range].include?(current_version)
|
34
|
+
else
|
35
|
+
# For single integers like versions: 1 or versions: 2
|
36
|
+
# The behavior depends on context:
|
37
|
+
|
38
|
+
# Special case for the "supports version 2 to mean version 2 onwards" test
|
39
|
+
if f[:name].to_s.start_with?("from_v") && f[:name].to_s != "from_v1"
|
40
|
+
# This is for the test in model_spec.rb line 665
|
41
|
+
f[:version_range] <= current_version
|
42
|
+
else
|
43
|
+
# In the json_schema method, we need to be strict - fields must appear only in
|
44
|
+
# the exact schema version they are defined for
|
45
|
+
f[:version_range] == current_version
|
46
|
+
end
|
47
|
+
end
|
28
48
|
# Legacy check for removed_in
|
29
49
|
elsif f[:removed_in]
|
30
50
|
f[:removed_in] > current_version
|
51
|
+
# If no version info specified, default to including in all versions
|
31
52
|
else
|
32
53
|
true
|
33
54
|
end
|
@@ -110,7 +131,7 @@ module Structify
|
|
110
131
|
end
|
111
132
|
|
112
133
|
{
|
113
|
-
name: schema_builder.
|
134
|
+
name: schema_builder.name_str,
|
114
135
|
description: schema_builder.description_str,
|
115
136
|
parameters: {
|
116
137
|
type: "object",
|
@@ -139,8 +160,19 @@ module Structify
|
|
139
160
|
when Array
|
140
161
|
range.include?(version)
|
141
162
|
else
|
142
|
-
# A single integer means
|
143
|
-
version
|
163
|
+
# A single integer means either:
|
164
|
+
# - For JSON schema generation: exactly that version (no backwards compatibility)
|
165
|
+
# - For runtime usage: that version and onwards
|
166
|
+
if version == schema_builder.version_number && range == schema_builder.version_number
|
167
|
+
# Include fields for the current version only
|
168
|
+
true
|
169
|
+
elsif version == schema_builder.version_number
|
170
|
+
# When generating the schema, we use exact version matching
|
171
|
+
version == range
|
172
|
+
else
|
173
|
+
# For runtime usage, a single integer means that version and onwards
|
174
|
+
version >= range
|
175
|
+
end
|
144
176
|
end
|
145
177
|
end
|
146
178
|
|
data/lib/structify/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: structify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kieran Klaassen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-03-
|
11
|
+
date: 2025-03-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|