Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Excessive warnings cleanup #90

Merged
merged 3 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 0 additions & 32 deletions lib/schema/cache.ex
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ defmodule Schema.Cache do
attribute_keys: nil | MapSet.t(String.t())
}

@ocsf_deprecated :"@deprecated"

@doc """
Load the schema files and initialize the cache.
"""
Expand Down Expand Up @@ -1119,53 +1117,23 @@ defmodule Schema.Cache do

defp final_check(maps, dictionary) do
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 ->
deprecated_warning(name, key, attribute)
missing_desc_warning(attribute[:description], name, key, dictionary)
add_datetime(Utils.find_entity(dictionary, map, key), key, attribute, acc)
end)

update_profiles(list, map, profiles, attributes)
end

defp deprecated_warning(name, key, attribute) do
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
end

defp missing_desc_warning(nil, name, key, dictionary) do
desc = get_in(dictionary, [key, :description]) || ""

Expand Down
14 changes: 0 additions & 14 deletions lib/schema/profiles.ex
Original file line number Diff line number Diff line change
Expand Up @@ -70,25 +70,11 @@ defmodule Schema.Profiles do
acc

profile ->
check_profile(name, profile, map[:attributes])
link = %{group: group, type: Atom.to_string(name), caption: map[:caption]}
profile = Map.update(profile, :_links, [link], fn links -> [link | links] end)
Map.put(acc, p, profile)
end
end)
end

defp check_profile(name, profile, attributes) do
Enum.each(profile[:attributes], fn {k, p} ->
if Map.has_key?(attributes, k) == false do
text = "#{name} uses '#{profile[:name]}' profile, but it does not define '#{k}' attribute"

if p[:requirement] == "required" do
Logger.warning(text)
else
Logger.info(text)
end
end
end)
end
end
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
defmodule Schema.MixProject do
use Mix.Project

@version "2.70.1"
@version "2.70.2"

def project do
build = System.get_env("GITHUB_RUN_NUMBER") || "SNAPSHOT"
Expand Down
Loading