diff --git a/apps/transport/lib/validators/netex_validator.ex b/apps/transport/lib/validators/netex_validator.ex index e7ec9bea58..7fceddbd98 100644 --- a/apps/transport/lib/validators/netex_validator.ex +++ b/apps/transport/lib/validators/netex_validator.ex @@ -36,7 +36,7 @@ defmodule Transport.Validators.NeTEx do resource_history.id, result_url, %{elapsed_seconds: elapsed_seconds, retries: retries}, - errors + demote_non_xsd_errors(errors) ) :ok @@ -76,7 +76,7 @@ defmodule Transport.Validators.NeTEx do # result_url in metadata? {:ok, %{ - "validations" => index_messages(errors), + "validations" => errors |> demote_non_xsd_errors() |> index_messages(), "metadata" => %{elapsed_seconds: elapsed_seconds, retries: retries} }} @@ -344,4 +344,20 @@ defmodule Transport.Validators.NeTEx do defp client do Transport.EnRouteChouetteValidClient.Wrapper.impl() end + + defp demote_non_xsd_errors(errors), do: Enum.map(errors, &demote_non_xsd_error(&1)) + + defp demote_non_xsd_error(%{"criticity" => criticity, "code" => code} = error) do + criticity = + if String.starts_with?(code, "xsd-") do + criticity + else + case criticity do + "error" -> "warning" + _ -> criticity + end + end + + Map.update!(error, "criticity", fn _ -> criticity end) + end end diff --git a/apps/transport/test/transport/validators/netex_validator_test.exs b/apps/transport/test/transport/validators/netex_validator_test.exs index cd41dda0e0..20312562b5 100644 --- a/apps/transport/test/transport/validators/netex_validator_test.exs +++ b/apps/transport/test/transport/validators/netex_validator_test.exs @@ -15,6 +15,12 @@ defmodule Transport.Validators.NeTExTest do setup :verify_on_exit! @sample_error_messages [ + %{ + "code" => "xsd-1871", + "criticity" => "error", + "message" => + "Element '{http://www.netex.org.uk/netex}OppositeDIrectionRef': This element is not expected. Expected is ( {http://www.netex.org.uk/netex}OppositeDirectionRef )." + }, %{ "code" => "uic-operating-period", "message" => "Resource 23504000009 hasn't expected class but Netex::OperatingPeriod", @@ -70,18 +76,26 @@ defmodule Transport.Validators.NeTExTest do assert multi_validation.metadata.metadata == %{"retries" => 0, "elapsed_seconds" => 31} assert multi_validation.result == %{ + "xsd-1871" => [ + %{ + "code" => "xsd-1871", + "criticity" => "error", + "message" => + "Element '{http://www.netex.org.uk/netex}OppositeDIrectionRef': This element is not expected. Expected is ( {http://www.netex.org.uk/netex}OppositeDirectionRef )." + } + ], "uic-operating-period" => [ %{ "code" => "uic-operating-period", "message" => "Resource 23504000009 hasn't expected class but Netex::OperatingPeriod", - "criticity" => "error" + "criticity" => "warning" } ], "valid-day-bits" => [ %{ "code" => "valid-day-bits", "message" => "Mandatory attribute valid_day_bits not found", - "criticity" => "error" + "criticity" => "warning" } ], "frame-arret-resources" => [ @@ -121,18 +135,26 @@ defmodule Transport.Validators.NeTExTest do expect_get_messages(validation_id, @sample_error_messages) validation_result = %{ + "xsd-1871" => [ + %{ + "code" => "xsd-1871", + "criticity" => "error", + "message" => + "Element '{http://www.netex.org.uk/netex}OppositeDIrectionRef': This element is not expected. Expected is ( {http://www.netex.org.uk/netex}OppositeDirectionRef )." + } + ], "uic-operating-period" => [ %{ "code" => "uic-operating-period", "message" => "Resource 23504000009 hasn't expected class but Netex::OperatingPeriod", - "criticity" => "error" + "criticity" => "warning" } ], "valid-day-bits" => [ %{ "code" => "valid-day-bits", "message" => "Mandatory attribute valid_day_bits not found", - "criticity" => "error" + "criticity" => "warning" } ], "frame-arret-resources" => [ @@ -160,11 +182,12 @@ defmodule Transport.Validators.NeTExTest do expect_get_messages(validation_id, @sample_error_message) validation_result = %{ - "uic-operating-period" => [ + "xsd-1871" => [ %{ - "code" => "uic-operating-period", - "message" => "Resource 23504000009 hasn't expected class but Netex::OperatingPeriod", - "criticity" => "error" + "code" => "xsd-1871", + "criticity" => "error", + "message" => + "Element '{http://www.netex.org.uk/netex}OppositeDIrectionRef': This element is not expected. Expected is ( {http://www.netex.org.uk/netex}OppositeDirectionRef )." } ] }