-module(nori@validator@errors). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]). -define(FILEPATH, "src/nori/validator/errors.gleam"). -export([to_string/1, get_path/1]). -export_type([validation_error/0]). -if(?OTP_RELEASE >= 27). -define(MODULEDOC(Str), -moduledoc(Str)). -define(DOC(Str), -doc(Str)). -else. -define(MODULEDOC(Str), -compile([])). -define(DOC(Str), -compile([])). -endif. ?MODULEDOC(" Validation error types for OpenAPI documents.\n"). -type validation_error() :: {empty_required_field, binary()} | {invalid_path, binary(), binary()} | {invalid_parameter, binary(), binary()} | {invalid_component_name, binary(), binary(), binary()} | {unresolvable_reference, binary()} | {missing_response, binary(), binary()} | {duplicate_operation_id, binary()} | {undefined_security_scheme, binary()} | {invalid_server_url, binary(), binary()} | {schema_error, binary(), binary()} | {generic_error, binary()}. -file("src/nori/validator/errors.gleam", 30). ?DOC(" Converts a validation error to a human-readable string.\n"). -spec to_string(validation_error()) -> binary(). to_string(Error) -> case Error of {empty_required_field, Path} -> <<"Required field is empty: "/utf8, Path/binary>>; {invalid_path, Path@1, Reason} -> <<<<<<"Invalid path '"/utf8, Path@1/binary>>/binary, "': "/utf8>>/binary, Reason/binary>>; {invalid_parameter, Path@2, Reason@1} -> <<<<<<"Invalid parameter at '"/utf8, Path@2/binary>>/binary, "': "/utf8>>/binary, Reason@1/binary>>; {invalid_component_name, Path@3, Name, Reason@2} -> <<<<<<<<<<"Invalid component name '"/utf8, Name/binary>>/binary, "' at '"/utf8>>/binary, Path@3/binary>>/binary, "': "/utf8>>/binary, Reason@2/binary>>; {unresolvable_reference, Ref} -> <<"Cannot resolve reference: "/utf8, Ref/binary>>; {missing_response, Path@4, Message} -> <<<<<<"Missing response at '"/utf8, Path@4/binary>>/binary, "': "/utf8>>/binary, Message/binary>>; {duplicate_operation_id, Op_id} -> <<"Duplicate operationId: "/utf8, Op_id/binary>>; {undefined_security_scheme, Name@1} -> <<"Undefined security scheme: "/utf8, Name@1/binary>>; {invalid_server_url, Url, Reason@3} -> <<<<<<"Invalid server URL '"/utf8, Url/binary>>/binary, "': "/utf8>>/binary, Reason@3/binary>>; {schema_error, Path@5, Message@1} -> <<<<<<"Schema error at '"/utf8, Path@5/binary>>/binary, "': "/utf8>>/binary, Message@1/binary>>; {generic_error, Message@2} -> Message@2 end. -file("src/nori/validator/errors.gleam", 52). ?DOC(" Returns the path where the error occurred, if available.\n"). -spec get_path(validation_error()) -> {ok, binary()} | {error, nil}. get_path(Error) -> case Error of {empty_required_field, Path} -> {ok, Path}; {invalid_path, Path@1, _} -> {ok, Path@1}; {invalid_parameter, Path@2, _} -> {ok, Path@2}; {invalid_component_name, Path@3, _, _} -> {ok, Path@3}; {missing_response, Path@4, _} -> {ok, Path@4}; {schema_error, Path@5, _} -> {ok, Path@5}; {unresolvable_reference, _} -> {error, nil}; {duplicate_operation_id, _} -> {error, nil}; {undefined_security_scheme, _} -> {error, nil}; {invalid_server_url, _, _} -> {error, nil}; {generic_error, _} -> {error, nil} end.