Skip to content

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

Open
@romanr321

Description

@romanr321

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions