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

I'd like to be able to use proper_types:is_inst/2 for RPC schema validation #317

Open
romanr321 opened this issue Jan 2, 2025 · 1 comment

Comments

@romanr321
Copy link

currently proper_types:is_inst/2 is marked as @Private

%% @private

Erlang RPC presents a problem for rolling upgrades, where one release may have changes to the RPC functions. I'd like to use proper_types:is_inst/2 during testing when rpc is called and validate that a module, function exists and is expecting the arguments according to a proper raw_type schema.

For example, very simplified:

call(Mod, Fun, Args) ->
    ValidRPCs = [
% {Key, RawTypes} when Key :: {Module, Function, Arity}
        {{my_module, my_fun_v1, 1}, [list(atom())]},
        {{my_module, my_otherfun_v1, 2}, [integer(), integer()]}
    ],
    {_Key, RawTypes} = lists:keyfind({Mod, Fun, length(Args)}, 1, ValidRPCs),
    true = lists:all(fun(Value, RawType) -> is_inst(Value, RawType) end, lists:zip(Args, RawTypes)),
   % continue_with_call or crash to let me know the API has a braking change

The other issue is that proper type any() is not erlang any() or term(), it fails with missing types like pid(). It would be really great to add more missing types, even if for validation only, but a catchall to ignore missing types would suffice to catch the rest. I've added an ignore() and pid() types locally to test and it worked.

Please let me know if this use can can be accommodated.

@romanr321
Copy link
Author

I am able to expand types in my own code, but I still hope that using this for schema validation can be supported officially.

    -module(more_proper_types).
    -export([pid/0]).

    -import(proper_types, [new_type/2]).

    -spec pid() -> proper_types:type().
    pid() ->
        new_type([{generator, fun() -> spawn(fun() -> ok end) end},
              {is_instance, fun is_pid/1}], 
             basic).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant