From 8e5519b6f3514e033fe321ee6b136428555fc170 Mon Sep 17 00:00:00 2001 From: Rajas Panat Date: Wed, 29 Jul 2026 12:15:52 -0400 Subject: [PATCH] Render supersedes and replaced-by notes for deprecations The OCSF schema's @deprecated block now carries a "superseded_by" array naming the replacement definition(s), and the schema compiler derives a reverse ":_supersedes" marker on each replacement in browser mode. This surfaces both directions in the browser so consumers migrating off a deprecated definition can find its replacement, and anyone landing on a replacement can see what it supersedes. - page_view: adds format_item_supersedes/3 for classes and objects, append_supersedes/2 for attributes, and format_enum_supersedes/2 for enum values. Each renders a "Supersedes deprecated X" note, linking to the deprecated item's page where one exists. - page_view: adds append_superseded_by/3, rendering a "Replaced by" note on a deprecated attribute whose replacement lives in another container. Only dotted paths (e.g. "job_action.cmd_line") get a forward link; same-context replacements are covered by the reverse note instead. format_attribute_desc/3 and format_dictionary_attribute_desc/3 take an optional conn to build those links, defaulting to nil so existing callers keep working. - schema, page_controller: the classes listing page went through clean_classes_filter_extensions/1, whose filter_internal/1 strips all "_"-prefixed keys and so removed :_supersedes. Adds classes_filter_extensions/1 and switches the page to it, mirroring how the objects listing page already works. Attribute-level profile filtering is not applied, matching objects/2; the listing renders no attribute rows, and per-row profile data for the client-side filter comes from class[:profiles], which is unaffected. - data_types: links out to the OCSF storage strategies data type mappings article. - components.css: styles both notes, with dark-theme variants. Bump version to 4.5.0. Verified against a browser-mode compile of ocsf-schema: 10 class, 3 object, 179 attribute and 1 enum supersedes notes, plus 23 cross- container replaced-by links, all rendering on the class, object, listing, dictionary and profile pages. Signed-off-by: Rajas Panat --- lib/schema.ex | 10 + lib/schema_web/controllers/page_controller.ex | 6 +- lib/schema_web/templates/page/class.html.eex | 3 +- .../templates/page/classes.html.eex | 2 +- .../templates/page/data_types.html.eex | 6 + .../templates/page/dictionary.html.eex | 2 +- lib/schema_web/templates/page/object.html.eex | 3 +- .../templates/page/objects.html.eex | 2 +- .../templates/page/profile.html.eex | 2 +- lib/schema_web/views/page_view.ex | 197 +++++++++++++++++- mix.exs | 2 +- priv/static/css/components.css | 57 +++++ 12 files changed, 273 insertions(+), 19 deletions(-) diff --git a/lib/schema.ex b/lib/schema.ex index 06a9087..53d267e 100644 --- a/lib/schema.ex +++ b/lib/schema.ex @@ -230,6 +230,16 @@ defmodule Schema do SingleRepo.classes() end + @doc """ + Returns all event classes (with browser information) filtered by extensions. + This is meant for the classes HTML page, which needs browser-only metadata such + as :_supersedes. Mirrors objects_filter_extensions/1. + """ + @spec classes_filter_extensions(Utils.string_set_t() | nil) :: map() + def classes_filter_extensions(extensions) do + SingleRepo.classes() |> Utils.filter_items_by_extensions(extensions) + end + @spec clean_classes_filter_extensions(Utils.string_set_t() | nil) :: map() def clean_classes_filter_extensions(extensions) do SingleRepo.clean_classes() |> Utils.filter_items_by_extensions(extensions) diff --git a/lib/schema_web/controllers/page_controller.ex b/lib/schema_web/controllers/page_controller.ex index f3b8c5f..bb1b3f9 100644 --- a/lib/schema_web/controllers/page_controller.ex +++ b/lib/schema_web/controllers/page_controller.ex @@ -84,9 +84,11 @@ defmodule SchemaWeb.PageController do @spec classes(Plug.Conn.t(), any) :: Plug.Conn.t() def classes(conn, params) do + params = Map.put_new(params, "extensions", "") + data = - Map.put_new(params, "extensions", "") - |> SchemaController.classes() + SchemaController.parse_options(SchemaController.extensions(params)) + |> Schema.classes_filter_extensions() |> sort_by(:uid) render(conn, "classes.html", diff --git a/lib/schema_web/templates/page/class.html.eex b/lib/schema_web/templates/page/class.html.eex index 9d3973f..f2d2c86 100644 --- a/lib/schema_web/templates/page/class.html.eex +++ b/lib/schema_web/templates/page/class.html.eex @@ -51,6 +51,7 @@ limitations under the License.
<%= raw description(@data) %>
+ <%= raw format_item_supersedes(@conn, @data, "classes") %> <%= if has_deprecated_attributes?(@data) do %> <% dep_count = deprecated_attributes_count(@data) %>
@@ -120,7 +121,7 @@ limitations under the License. <%= attribute[:group] %> <%= raw format_requirement(constraints, attribute_key, attribute) %> <%= raw format_type(@conn, attribute) %> - <%= raw format_attribute_desc(attribute_key, attribute) %> + <%= raw format_attribute_desc(attribute_key, attribute, @conn) %> <% end %> diff --git a/lib/schema_web/templates/page/classes.html.eex b/lib/schema_web/templates/page/classes.html.eex index 86063a2..bb19138 100644 --- a/lib/schema_web/templates/page/classes.html.eex +++ b/lib/schema_web/templates/page/classes.html.eex @@ -44,7 +44,7 @@ limitations under the License. <% else %> <% end %> - <%= raw description(class) %> + <%= raw description(class) %><%= raw format_item_supersedes(@conn, class, "classes") %> <% end %> diff --git a/lib/schema_web/templates/page/data_types.html.eex b/lib/schema_web/templates/page/data_types.html.eex index 3d231cf..b01ebd3 100644 --- a/lib/schema_web/templates/page/data_types.html.eex +++ b/lib/schema_web/templates/page/data_types.html.eex @@ -17,6 +17,12 @@ limitations under the License.
<%= raw @data[:description] %>
+ <%= raw object_references_section([ + %{ + url: "https://github.com/ocsf/ocsf-docs/blob/main/articles/OCSF-Storage-Strategies.md#data-type-mappings", + description: "Data Type Mappings (storage formats, e.g. Apache Iceberg)" + } + ]) %>
diff --git a/lib/schema_web/templates/page/dictionary.html.eex b/lib/schema_web/templates/page/dictionary.html.eex index 9dd8f66..7da7224 100644 --- a/lib/schema_web/templates/page/dictionary.html.eex +++ b/lib/schema_web/templates/page/dictionary.html.eex @@ -53,7 +53,7 @@ limitations under the License. <%= raw format_attribute_caption(@conn, @schema, attribute_key, attribute) %> <%= raw format_type(@conn, attribute) %> <%= raw dictionary_links(@conn, @schema, attribute_key, attribute[:_links]) %> - <%= raw format_dictionary_attribute_desc(attribute_key, attribute) %> + <%= raw format_dictionary_attribute_desc(attribute_key, attribute, @conn) %> <% end %> diff --git a/lib/schema_web/templates/page/object.html.eex b/lib/schema_web/templates/page/object.html.eex index e01abcf..5baa0a4 100644 --- a/lib/schema_web/templates/page/object.html.eex +++ b/lib/schema_web/templates/page/object.html.eex @@ -46,6 +46,7 @@ limitations under the License.
<%= raw description(@data) %>
+ <%= raw format_item_supersedes(@conn, @data, "objects") %> <%= if has_deprecated_attributes?(@data) do %> <% dep_count = deprecated_attributes_count(@data) %>
@@ -100,7 +101,7 @@ limitations under the License. <%= raw format_attribute_caption(@conn, @schema, attribute_key, attribute) %> <%= raw format_requirement(constraints, attribute_key, attribute) %> <%= raw format_type(@conn, attribute) %> - <%= raw format_attribute_desc(attribute_key, attribute) %> + <%= raw format_attribute_desc(attribute_key, attribute, @conn) %> <% end %> diff --git a/lib/schema_web/templates/page/objects.html.eex b/lib/schema_web/templates/page/objects.html.eex index 9cceabd..c378a9b 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. <%= object_key_str %> <%= raw format_attribute_caption(@conn, @schema, object_key_str, object, false) %> <%= raw object_links(@conn, object[:name], object[:_links], :collapse) %> - <%= raw description(object) %> + <%= raw description(object) %><%= raw format_item_supersedes(@conn, object, "objects") %> <% end %> diff --git a/lib/schema_web/templates/page/profile.html.eex b/lib/schema_web/templates/page/profile.html.eex index a097304..8c17c08 100644 --- a/lib/schema_web/templates/page/profile.html.eex +++ b/lib/schema_web/templates/page/profile.html.eex @@ -80,7 +80,7 @@ limitations under the License. <%= field[:group] %> <%= raw format_requirement(nil, key, field) %> <%= raw format_type(@conn, field) %> - <%= raw format_attribute_desc(key, field) %> + <%= raw format_attribute_desc(key, field, @conn) %> <% end %> diff --git a/lib/schema_web/views/page_view.ex b/lib/schema_web/views/page_view.ex index 15df6e4..76e407f 100644 --- a/lib/schema_web/views/page_view.ex +++ b/lib/schema_web/views/page_view.ex @@ -672,20 +672,34 @@ defmodule SchemaWeb.PageView do end end - @spec format_attribute_desc(String.t() | atom(), map()) :: any - def format_attribute_desc(attribute_key, attribute) do - append_source_references( - base_format_attribute_desc(attribute_key, attribute, false), - "


", + @spec format_attribute_desc(String.t() | atom(), map(), Plug.Conn.t() | nil) :: any + def format_attribute_desc(attribute_key, attribute, conn \\ nil) do + append_supersedes( + append_superseded_by( + append_source_references( + base_format_attribute_desc(attribute_key, attribute, false), + "


", + attribute + ), + attribute, + conn + ), attribute ) end - @spec format_dictionary_attribute_desc(String.t() | atom(), map()) :: any - def format_dictionary_attribute_desc(attribute_key, attribute) do - append_source_references( - base_format_attribute_desc(attribute_key, attribute, true), - "


", + @spec format_dictionary_attribute_desc(String.t() | atom(), map(), Plug.Conn.t() | nil) :: any + def format_dictionary_attribute_desc(attribute_key, attribute, conn \\ nil) do + append_supersedes( + append_superseded_by( + append_source_references( + base_format_attribute_desc(attribute_key, attribute, true), + "


", + attribute + ), + attribute, + conn + ), attribute ) end @@ -745,6 +759,7 @@ defmodule SchemaWeb.PageView do Map.get(item, :caption, id), "
", append_source_references(description(item), item), + format_enum_supersedes(item, enum_values), "
" | acc ] end @@ -820,6 +835,168 @@ defmodule SchemaWeb.PageView do end end + # Appends a "Supersedes" note when this (non-deprecated) attribute replaces one or + # more deprecated attributes. The reverse reference is precomputed by the schema + # compiler in browser mode as the :_supersedes marker. Unlike the deprecation notice, + # this is shown by default so consumers migrating off a deprecated attribute can + # discover its replacement from the live attribute. + @spec append_supersedes(any(), map()) :: any() + defp append_supersedes(html, attribute) do + case attribute[:_supersedes] do + supersedes when is_list(supersedes) and supersedes != [] -> + [html, format_supersedes(supersedes)] + + _ -> + html + end + end + + @spec format_supersedes([map()]) :: any() + defp format_supersedes(supersedes) do + names = + supersedes + |> Enum.map(fn entry -> entry[:type] end) + |> Enum.map(fn name -> + ["", Phoenix.HTML.html_escape(name) |> Phoenix.HTML.safe_to_string(), ""] + end) + |> Enum.intersperse(", ") + + [ + "
Supersedes deprecated ", + names, + "
" + ] + end + + # Appends a "Replaced by" forward link on a DEPRECATED attribute whose replacement + # lives in another object or class (a dotted path in @deprecated.superseded_by, e.g. + # "job_action.cmd_line"). Renders each replacement path as a link to the target's + # page. conn is required to build URLs; when nil (callers that don't pass it) nothing + # is appended. Same-scope replacements are handled by the reverse note instead. + @spec append_superseded_by(any(), map(), Plug.Conn.t() | nil) :: any() + defp append_superseded_by(html, _attribute, nil), do: html + + defp append_superseded_by(html, attribute, conn) do + deprecated = attribute[:"@deprecated"] + + superseded_by = + if is_map(deprecated), do: deprecated[:superseded_by], else: nil + + case superseded_by do + paths when is_list(paths) and paths != [] -> + # Only render forward links for cross-container (dotted path) replacements. + cross = Enum.filter(paths, fn p -> String.contains?(to_string(p), ".") end) + + if cross == [] do + html + else + [html, format_superseded_by(cross, conn)] + end + + _ -> + html + end + end + + @spec format_superseded_by([String.t()], Plug.Conn.t()) :: any() + defp format_superseded_by(paths, conn) do + links = + paths + |> Enum.map(fn path -> superseded_by_link(to_string(path), conn) end) + |> Enum.intersperse(", ") + + [ + "
Replaced by ", + links, + "
" + ] + end + + # Builds a link to the replacement attribute's containing class or object page. + # The path's first segment names the container; if it resolves to a class it links + # to /classes/, otherwise to /objects/. The full path is shown as the + # link text. + @spec superseded_by_link(String.t(), Plug.Conn.t()) :: any() + defp superseded_by_link(path, conn) do + base = path |> String.split(".") |> hd() |> String.split("[") |> hd() + escaped = Phoenix.HTML.html_escape(path) |> Phoenix.HTML.safe_to_string() + + kind = if Schema.class(base) != nil, do: "classes", else: "objects" + href = SchemaWeb.Router.Helpers.static_path(conn, "/#{kind}/#{base}") + ["", escaped, ""] + end + + # Renders a "Supersedes" note for an enum value that replaces one or more deprecated + # enum values of the same attribute. The :_supersedes marker (precomputed by the + # compiler in browser mode) holds the deprecated enum value keys; enum_values is the + # full enum map, used to look up each deprecated value's caption for display. + @spec format_enum_supersedes(map(), map() | list()) :: any() + defp format_enum_supersedes(item, enum_values) do + case item[:_supersedes] do + supersedes when is_list(supersedes) and supersedes != [] -> + labels = + supersedes + |> Enum.map(fn entry -> to_string(entry[:type]) end) + |> Enum.map(fn key -> + caption = enum_value_caption(enum_values, key) + escaped = Phoenix.HTML.html_escape(caption) |> Phoenix.HTML.safe_to_string() + ["", escaped, " [", key, "]"] + end) + |> Enum.intersperse(", ") + + [ + "
Supersedes deprecated ", + labels, + "
" + ] + + _ -> + "" + end + end + + @spec enum_value_caption(map() | list(), String.t()) :: String.t() + defp enum_value_caption(enum_values, key) do + entry = + Enum.find_value(enum_values, nil, fn {k, v} -> + if to_string(k) == key, do: v, else: nil + end) + + case entry do + nil -> key + value -> Map.get(value, :caption, key) + end + end + + # Renders a "Supersedes" note for a whole class or object that replaces one or more + # deprecated classes/objects. The :_supersedes marker is precomputed by the schema + # compiler in browser mode. kind is "classes" or "objects" (the route segment), used + # to link each deprecated item to its page. Shown by default on the live item's page. + @spec format_item_supersedes(any(), map(), String.t()) :: any() + def format_item_supersedes(conn, item, kind) do + case item[:_supersedes] do + supersedes when is_list(supersedes) and supersedes != [] -> + links = + supersedes + |> Enum.map(fn entry -> entry[:type] end) + |> Enum.map(fn name -> + path = SchemaWeb.Router.Helpers.static_path(conn, "/#{kind}/#{name}") + escaped = Phoenix.HTML.html_escape(name) |> Phoenix.HTML.safe_to_string() + ["", escaped, ""] + end) + |> Enum.intersperse(", ") + + [ + "
Supersedes deprecated ", + links, + "
" + ] + + _ -> + "" + end + end + def constraints(rules) do Enum.reduce(rules, [], fn {name, list}, acc -> constraints(name, list, acc) diff --git a/mix.exs b/mix.exs index a0e4897..ba8e5b5 100644 --- a/mix.exs +++ b/mix.exs @@ -10,7 +10,7 @@ defmodule Schema.MixProject do use Mix.Project - @version "4.4.0" + @version "4.5.0" def project do build = System.get_env("GITHUB_RUN_NUMBER") || "SNAPSHOT" diff --git a/priv/static/css/components.css b/priv/static/css/components.css index f34a025..ae78222 100644 --- a/priv/static/css/components.css +++ b/priv/static/css/components.css @@ -883,3 +883,60 @@ button:hover, [data-theme="dark"] .deprecated-attr-notice i { color: #FBBF24; } + +.supersedes-note { + display: block; + background: rgba(8, 145, 178, 0.06); + border-left: 3px solid var(--accent-color); + border-radius: var(--radius-md); + padding: var(--spacing-xs) var(--spacing-sm); + margin-top: var(--spacing-sm); + font-size: var(--text-sm); + color: var(--text-secondary); + line-height: 1.8; +} + +.supersedes-note i { + color: var(--accent-color); + font-size: var(--text-sm); + margin-right: var(--spacing-sm); +} + +.supersedes-note code { + background: transparent; + padding: 0; + white-space: nowrap; +} + +.superseded-by-note { + display: block; + background: rgba(217, 119, 6, 0.06); + border-left: 3px solid var(--warning-color); + border-radius: var(--radius-md); + padding: var(--spacing-xs) var(--spacing-sm); + margin-top: var(--spacing-sm); + font-size: var(--text-sm); + color: var(--text-secondary); + line-height: 1.8; +} + +.superseded-by-note i { + color: var(--warning-color); + font-size: var(--text-sm); + margin-right: var(--spacing-sm); +} + +.superseded-by-note code { + background: transparent; + padding: 0; + white-space: nowrap; +} + +[data-theme="dark"] .superseded-by-note { + background: rgba(251, 191, 36, 0.06); + border-left-color: #FBBF24; +} + +[data-theme="dark"] .superseded-by-note i { + color: #FBBF24; +}