diff --git a/lib/schema/cache.ex b/lib/schema/cache.ex
index 666e641..71471d7 100644
--- a/lib/schema/cache.ex
+++ b/lib/schema/cache.ex
@@ -41,6 +41,8 @@ defmodule Schema.Cache do
@type category_t() :: map()
@type dictionary_t() :: map()
+ @ocsf_deprecated :"@deprecated"
+
@doc """
Load the schema files and initialize the cache.
"""
@@ -64,6 +66,7 @@ defmodule Schema.Cache do
# Apply profiles to objects and classes
{objects, profiles} = Profiles.sanity_check(:object, objects, profiles)
+
objects =
objects
|> Utils.update_objects(attributes)
@@ -290,6 +293,7 @@ defmodule Schema.Cache do
[ext, _] ->
ext_name = String.to_atom("#{ext}/#{name}")
dictionary[ext_name] || dictionary[name]
+
_ ->
Logger.warning("#{name} has an invalid source: #{source}")
dictionary[name]
@@ -662,17 +666,44 @@ defmodule Schema.Cache do
end
defp final_check(maps, dictionary) do
- Enum.into(maps, %{}, fn {name, value} ->
- {name, final_check(name, value, dictionary)}
+ Enum.into(maps, %{}, fn {name, map} ->
+ deprecated_type(name, map, Map.get(map, @ocsf_deprecated))
+
+ {name, final_check(name, map, dictionary)}
end)
end
+ defp deprecated_type(_name, _map, nil) do
+ end
+
+ defp deprecated_type(name, map, deprecated) do
+ type =
+ if Map.has_key?(map, :category) do
+ "class"
+ else
+ "object"
+ end
+
+ message = Map.get(deprecated, :message)
+ Logger.warning("The #{name} #{type} has been deprecated. #{message}")
+ end
+
defp final_check(name, map, dictionary) do
profiles = map[:profiles]
attributes = map[:attributes]
list =
Enum.reduce(attributes, [], fn {key, attribute}, acc ->
+ case Map.get(attribute, @ocsf_deprecated) do
+ nil ->
+ :ok
+
+ deprecated ->
+ Logger.warning(
+ "The #{key} attribute in #{name} has been deprecated. #{Map.get(deprecated, :message)}"
+ )
+ end
+
if is_nil(attribute[:description]) do
desc = get_in(dictionary, [key, :description]) || ""
diff --git a/lib/schema_web/templates/page/category.html.eex b/lib/schema_web/templates/page/category.html.eex
index 00c90bf..fabfd0d 100644
--- a/lib/schema_web/templates/page/category.html.eex
+++ b/lib/schema_web/templates/page/category.html.eex
@@ -18,7 +18,7 @@ limitations under the License.
Category
-
<%= raw @data[:description] %>
+ <%= raw description(@data) %>
@@ -54,7 +54,7 @@ limitations under the License.
<% else %>
|
<% end %>
-
<%= raw class[:description] %> |
+
<%= raw description(class) %> |
<% end %>
diff --git a/lib/schema_web/templates/page/class.html.eex b/lib/schema_web/templates/page/class.html.eex
index f9c853f..2889275 100644
--- a/lib/schema_web/templates/page/class.html.eex
+++ b/lib/schema_web/templates/page/class.html.eex
@@ -32,7 +32,7 @@ limitations under the License.
- <%= raw @data[:description] %>
+ <%= raw description(@data) %>
<%= raw class_examples(@data) %>
diff --git a/lib/schema_web/templates/page/classes.html.eex b/lib/schema_web/templates/page/classes.html.eex
index 845e961..f6a0e31 100644
--- a/lib/schema_web/templates/page/classes.html.eex
+++ b/lib/schema_web/templates/page/classes.html.eex
@@ -50,7 +50,7 @@ limitations under the License.
<% else %>
|
<% end %>
-
<%= raw map[:description] %> |
+
<%= raw description(map) %> |
<% end %>
diff --git a/lib/schema_web/templates/page/dictionary.html.eex b/lib/schema_web/templates/page/dictionary.html.eex
index 8fdb3df..ec2889b 100644
--- a/lib/schema_web/templates/page/dictionary.html.eex
+++ b/lib/schema_web/templates/page/dictionary.html.eex
@@ -47,7 +47,7 @@ limitations under the License.
<%= name %> |
<%= raw format_type(@conn, field) %> |
<%= raw links(@conn, key, field[:_links]) %> |
-
<%= raw field[:description] %> |
+
<%= raw description(field) %> |
<% end %>
diff --git a/lib/schema_web/templates/page/object.html.eex b/lib/schema_web/templates/page/object.html.eex
index ed7a709..e137acd 100644
--- a/lib/schema_web/templates/page/object.html.eex
+++ b/lib/schema_web/templates/page/object.html.eex
@@ -41,7 +41,7 @@
- <%= raw @data[:description] %>
+ <%= raw description(@data) %>
diff --git a/lib/schema_web/templates/page/objects.html.eex b/lib/schema_web/templates/page/objects.html.eex
index 1ee65c1..737eeea 100644
--- a/lib/schema_web/templates/page/objects.html.eex
+++ b/lib/schema_web/templates/page/objects.html.eex
@@ -45,7 +45,7 @@ limitations under the License.
<%= raw format_attribute_name(name, map) %> |
<%= name %> |
<%= raw links(@conn, name, map[:_links]) %> |
-
<%= raw map[:description] %> |
+
<%= raw description(map) %> |
<% end %>
diff --git a/lib/schema_web/views/page_view.ex b/lib/schema_web/views/page_view.ex
index 03b8b7d..867114b 100644
--- a/lib/schema_web/views/page_view.ex
+++ b/lib/schema_web/views/page_view.ex
@@ -313,9 +313,9 @@ defmodule SchemaWeb.PageView do
end
end
- @spec format_desc(nil | map) :: any
+ @spec format_desc(map) :: any
def format_desc(obj) do
- description = Map.get(obj, :description)
+ description = description(obj)
case Map.get(obj, :enum) do
nil ->
@@ -488,4 +488,22 @@ defmodule SchemaWeb.PageView do
defp format_number(n) do
Number.Delimit.number_to_delimited(n, precision: 0)
end
+
+ def description(map) do
+ deprecated(map, Map.get(map, :"@deprecated"))
+ end
+
+ defp deprecated(map, nil) do
+ Map.get(map, :description)
+ end
+
+ defp deprecated(map, deprecated) do
+ [
+ Map.get(map, :description),
+ "
DEPRECATED ",
+ Map.get(deprecated, :message),
+ "
"
+ ]
+ end
+
end
diff --git a/mix.exs b/mix.exs
index 1a3e439..dd5018d 100644
--- a/mix.exs
+++ b/mix.exs
@@ -10,7 +10,7 @@
defmodule Schema.MixProject do
use Mix.Project
- @version "2.53.0"
+ @version "2.54.0"
def project do
build = System.get_env("GITHUB_RUN_NUMBER") || "SNAPSHOT"