lutaml-model 0.8.99 → 0.8.100
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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2bd54a574eb02eec487d980543835abb2bec61c12104d6eea6b898a516fb301f
|
|
4
|
+
data.tar.gz: ffc5d3ed5b0c6df7140839064baec52624a034b2d1c5cfdc764dc4ee78c199ce
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 191c5ee654cc6863a6f8d865448f0fbb29c31f7d602e3ab2a356148fdca7117b254aa497bb1ebdd80da1c80f495cf46c5f1029897cf87e7423a7409747e4e97c
|
|
7
|
+
data.tar.gz: 4b55a05f437df7e0c85c7545d2042990572c70a4d64b42d9ae3ee44950ca6875cd640c2089cd9620951264180556e2e3776e7b32028b1b1d9962cbdaad739ecb
|
|
@@ -901,3 +901,28 @@ The generated schema will include validation constraints:
|
|
|
901
901
|
</define>
|
|
902
902
|
</grammar>
|
|
903
903
|
----
|
|
904
|
+
|
|
905
|
+
== Documentation metadata (desc)
|
|
906
|
+
|
|
907
|
+
Models and attributes carry documentation strings through `desc` —
|
|
908
|
+
set on the model class or on any `attribute` declaration, read back
|
|
909
|
+
by documentation and schema tooling. Serialization is never affected
|
|
910
|
+
by it.
|
|
911
|
+
|
|
912
|
+
[source,ruby]
|
|
913
|
+
----
|
|
914
|
+
class Title < Lutaml::Model::Serializable
|
|
915
|
+
desc "This is a title."
|
|
916
|
+
|
|
917
|
+
attribute :type, :string, desc: "This attribute is used for..."
|
|
918
|
+
end
|
|
919
|
+
|
|
920
|
+
Title.desc # => "This is a title."
|
|
921
|
+
Title.attributes[:type].desc # => "This attribute is used for..."
|
|
922
|
+
----
|
|
923
|
+
|
|
924
|
+
Subclasses inherit the nearest ancestor's class description; an
|
|
925
|
+
explicit `desc` overrides it. A consumer override-free `desc` value
|
|
926
|
+
does not change any generated schema today — wiring `desc` into the
|
|
927
|
+
generated `description` fields is deliberate product scope, not a
|
|
928
|
+
free rider on this option.
|
|
@@ -46,6 +46,7 @@ module Lutaml
|
|
|
46
46
|
signed
|
|
47
47
|
min_length
|
|
48
48
|
max_length
|
|
49
|
+
desc
|
|
49
50
|
].freeze
|
|
50
51
|
|
|
51
52
|
# Per-type-class memo of the custom from_xml/from_json probe used by #cast.
|
|
@@ -641,6 +642,12 @@ instance_object = nil)
|
|
|
641
642
|
options[:pattern]
|
|
642
643
|
end
|
|
643
644
|
|
|
645
|
+
# Documentation metadata (#356): the `:desc` attribute option,
|
|
646
|
+
# consumed by documentation and schema tooling.
|
|
647
|
+
def desc
|
|
648
|
+
options[:desc]
|
|
649
|
+
end
|
|
650
|
+
|
|
644
651
|
# Performance: Frozen empty array to reduce allocations
|
|
645
652
|
EMPTY_VALUES_ARRAY = [].freeze
|
|
646
653
|
|
|
@@ -505,6 +505,22 @@ module Lutaml
|
|
|
505
505
|
end
|
|
506
506
|
end
|
|
507
507
|
|
|
508
|
+
# Class-level documentation metadata (#356): `desc "text"` on
|
|
509
|
+
# the model class; a zero-argument call reads it back.
|
|
510
|
+
# Subclasses inherit the nearest ancestor's description — an
|
|
511
|
+
# explicit `desc` overrides. Consumed by documentation and
|
|
512
|
+
# schema tooling; the serialization paths never read it.
|
|
513
|
+
def desc(text = nil)
|
|
514
|
+
return @lutaml_desc = text if text
|
|
515
|
+
|
|
516
|
+
return @lutaml_desc if defined?(@lutaml_desc)
|
|
517
|
+
|
|
518
|
+
if superclass.is_a?(::Class) &&
|
|
519
|
+
superclass < ::Lutaml::Model::Serializable
|
|
520
|
+
superclass.desc
|
|
521
|
+
end
|
|
522
|
+
end
|
|
523
|
+
|
|
508
524
|
# Define an attribute for the model
|
|
509
525
|
#
|
|
510
526
|
# @param name [Symbol] The attribute name
|
data/lib/lutaml/model/version.rb
CHANGED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../../spec_helper"
|
|
4
|
+
|
|
5
|
+
RSpec.describe "Documentation metadata (desc)" do
|
|
6
|
+
let(:widget_class) do
|
|
7
|
+
Class.new(Lutaml::Model::Serializable) do
|
|
8
|
+
desc "A widget."
|
|
9
|
+
|
|
10
|
+
attribute :name, :string, desc: "The widget name."
|
|
11
|
+
attribute :size, :integer
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "stores and reads the class-level description" do
|
|
16
|
+
expect(widget_class.desc).to eq("A widget.")
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it "returns nil when no description is set" do
|
|
20
|
+
plain = Class.new(Lutaml::Model::Serializable)
|
|
21
|
+
expect(plain.desc).to be_nil
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it "inherits the description on subclasses" do
|
|
25
|
+
child = Class.new(widget_class)
|
|
26
|
+
expect(child.desc).to eq("A widget.")
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "lets a subclass override the description" do
|
|
30
|
+
child = Class.new(widget_class) do
|
|
31
|
+
desc "A special widget."
|
|
32
|
+
end
|
|
33
|
+
expect(child.desc).to eq("A special widget.")
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it "does not leak an override back to the superclass" do
|
|
37
|
+
Class.new(widget_class) { desc "Child only." }
|
|
38
|
+
expect(widget_class.desc).to eq("A widget.")
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it "stores the attribute-level description" do
|
|
42
|
+
expect(widget_class.attributes[:name].desc).to eq("The widget name.")
|
|
43
|
+
expect(widget_class.attributes[:size].desc).to be_nil
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it "keeps serialization untouched" do
|
|
47
|
+
widget = widget_class.new(name: "w", size: 3)
|
|
48
|
+
expect(widget.to_hash).to eq("name" => "w", "size" => 3)
|
|
49
|
+
end
|
|
50
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: lutaml-model
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.8.
|
|
4
|
+
version: 0.8.100
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ribose Inc.
|
|
@@ -1742,6 +1742,7 @@ files:
|
|
|
1742
1742
|
- spec/lutaml/model/deferred_type_no_materialize_spec.rb
|
|
1743
1743
|
- spec/lutaml/model/delegation_spec.rb
|
|
1744
1744
|
- spec/lutaml/model/derived_attribute_serialization_spec.rb
|
|
1745
|
+
- spec/lutaml/model/desc_spec.rb
|
|
1745
1746
|
- spec/lutaml/model/dynamic_attribute_spec.rb
|
|
1746
1747
|
- spec/lutaml/model/encoding_spec.rb
|
|
1747
1748
|
- spec/lutaml/model/enum_spec.rb
|