From d3eaadeda5f85309fbf5ae5f36b644cc52694585 Mon Sep 17 00:00:00 2001 From: Phillip Calvin Date: Tue, 13 Feb 2018 22:11:00 -0500 Subject: [PATCH] Adjust typespecs for Erlang R17+ --- rebar.config | 2 +- src/jerg.erl | 52 ++++++++++++++++++++++++++-------------------------- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/rebar.config b/rebar.config index edb06bb..1832d92 100644 --- a/rebar.config +++ b/rebar.config @@ -1,7 +1,7 @@ %% == Dependencies == {deps, [ {jsx, ".*", {git, "git://github.com/ddossot/jsx.git", {tag, "v1.4.1"}}}, - {kvc, ".*", {git, "git://github.com/ddossot/kvc.git", {tag, "v1.3.0"}}}, + {kvc, ".*", {git, "https://github.com/etrepum/kvc.git", {tag, "v1.7.0"}}}, {getopt, ".*", {git, "git://github.com/ddossot/getopt.git", {tag, "v0.7.1"}}} ]}. diff --git a/src/jerg.erl b/src/jerg.erl index 64c0d50..acc8688 100644 --- a/src/jerg.erl +++ b/src/jerg.erl @@ -105,7 +105,7 @@ get_output_io_device(ParsedOpts) when is_list(ParsedOpts) -> IoDeviceOut end. --spec load_source(string(), string() | undefined) -> digraph(). +-spec load_source(string(), string() | undefined) -> digraph:digraph(). load_source(Source, Prefix) -> SchemaGraph = digraph:new(), case filelib:is_dir(Source) of @@ -118,14 +118,14 @@ load_source(Source, Prefix) -> end, SchemaGraph. --spec load_schemas(list(string()), digraph(), string() | undefined) -> ok. +-spec load_schemas(list(string()), digraph:digraph(), string() | undefined) -> ok. load_schemas([], _, _) -> ok; load_schemas([SchemaFile|Rest], SchemaGraph, Prefix) -> load_single_schema(SchemaFile, SchemaGraph, Prefix), load_schemas(Rest, SchemaGraph, Prefix). --spec load_single_schema(string(), digraph(), string() | undefined) -> digraph:vertex(). +-spec load_single_schema(string(), digraph:digraph(), string() | undefined) -> digraph:vertex(). load_single_schema(SchemaFile, SchemaGraph, Prefix) -> {ok, SchemaFileContent} = file:read_file(SchemaFile), JsonSchema = parse_and_enrich_json_schema(SchemaFileContent, Prefix), @@ -153,7 +153,7 @@ ensure_supported_json_schema(FileName, JsonSchema) when is_list(JsonSchema) -> ensure_supported_json_schema(FileName, _) -> throw({error, {FileName, "JSON Schema is not an object"}}). --spec get_schema(digraph(), binary()) -> {binary(), jsx:json_term()}. +-spec get_schema(digraph:digraph(), binary()) -> {binary(), jsx:json_term()}. get_schema(SchemaGraph, Vertex) -> {Vertex, {RawSchemaId, JsonSchema}} = digraph:vertex(SchemaGraph, Vertex), {get_schema_id(RawSchemaId, JsonSchema), JsonSchema}. @@ -173,13 +173,13 @@ get_schema_id(RawSchemaId, JsonSchema) -> end, fn(ActualSchemaId)). --spec set_schemas_relationships(digraph()) -> ok. +-spec set_schemas_relationships(digraph:digraph()) -> ok. set_schemas_relationships(SchemaGraph) -> set_schemas_relationships( SchemaGraph, get_schema_vertices(SchemaGraph)). --spec set_schemas_relationships(digraph(), list(jsx:json_term())) -> ok. +-spec set_schemas_relationships(digraph:digraph(), list(jsx:json_term())) -> ok. set_schemas_relationships(_, []) -> ok; set_schemas_relationships(SchemaGraph, [Vertex|Vertices]) -> @@ -188,7 +188,7 @@ set_schemas_relationships(SchemaGraph, [Vertex|Vertices]) -> set_schema_relationships(SchemaGraph, Vertex, SchemaDependencies), set_schemas_relationships(SchemaGraph, Vertices). --spec set_schema_relationships(digraph(), jsx:json_term(), list(jsx:json_term())) -> ok. +-spec set_schema_relationships(digraph:digraph(), jsx:json_term(), list(jsx:json_term())) -> ok. set_schema_relationships(_, _, []) -> ok; set_schema_relationships(SchemaGraph, Vertex, [DependencyVertex|SchemaDependencies]) -> @@ -214,12 +214,12 @@ get_schema_parent_vertex(JsonSchema) -> get_schema_ref_vertices(JsonSchema) -> [[kvc:path(['$ref'], S)] ++ [kvc:path([items,'$ref'], S)] || {_, S} <- kvc:path([properties], JsonSchema)]. --spec ensure_no_cyclicity(digraph()) -> ok. +-spec ensure_no_cyclicity(digraph:digraph()) -> ok. ensure_no_cyclicity(SchemaGraph) -> ensure(fun() -> digraph_utils:is_acyclic(SchemaGraph) end, fun() -> {schema_cyclic, digraph_utils:cyclic_strong_components(SchemaGraph)} end). --spec output_records(digraph(), file:io_device()) -> ok. +-spec output_records(digraph:digraph(), file:io_device()) -> ok. output_records(SchemaGraph, IoDevice) -> {{Year,Month,Day},{Hour,Min,Sec}} = erlang:localtime(), output("%%~n%% Generated by jerg v~s on ~B-~2..0B-~2..0B at ~2..0B:~2..0B:~2..0B~n%%~n%% DO NOT EDIT - CHANGES WILL BE OVERWRITTEN!~n%%~n~n", @@ -227,17 +227,17 @@ output_records(SchemaGraph, IoDevice) -> IoDevice), output_records(SchemaGraph, get_schema_vertices(SchemaGraph), IoDevice). --spec get_schema_vertices(digraph()) -> list(digraph:vertex()). +-spec get_schema_vertices(digraph:digraph()) -> list(digraph:vertex()). get_schema_vertices(SchemaGraph) -> get_schema_vertices(SchemaGraph, digraph:no_edges(SchemaGraph)). --spec get_schema_vertices(digraph(), non_neg_integer()) -> list(digraph:vertex()). +-spec get_schema_vertices(digraph:digraph(), non_neg_integer()) -> list(digraph:vertex()). get_schema_vertices(SchemaGraph, 0) -> digraph:vertices(SchemaGraph); get_schema_vertices(SchemaGraph, _NumberOfEdges) -> digraph_utils:postorder(SchemaGraph). --spec output_records(digraph(), list(digraph:vertex()), file:io_device()) -> ok. +-spec output_records(digraph:digraph(), list(digraph:vertex()), file:io_device()) -> ok. output_records(_, [], _) -> ok; output_records(SchemaGraph, [Vertex|Vertices], IoDevice) when is_list(Vertices) -> @@ -245,7 +245,7 @@ output_records(SchemaGraph, [Vertex|Vertices], IoDevice) when is_list(Vertices) output_record(SchemaGraph, SchemaId, JsonSchema, IoDevice), output_records(SchemaGraph, Vertices, IoDevice). --spec output_record(digraph(), binary(), jsx:json_term(), file:io_device()) -> ok. +-spec output_record(digraph:digraph(), binary(), jsx:json_term(), file:io_device()) -> ok. output_record(SchemaGraph, SchemaId, JsonSchema, IoDevice) -> case {kvc:path([type], JsonSchema), kvc:path([abstract], JsonSchema)} of {<<"object">>, Abstract} when Abstract =:= false ; Abstract =:= [] -> @@ -254,7 +254,7 @@ output_record(SchemaGraph, SchemaId, JsonSchema, IoDevice) -> ok end. --spec output_object_record(digraph(), binary(), jsx:json_term(), file:io_device()) -> no_return(). +-spec output_object_record(digraph:digraph(), binary(), jsx:json_term(), file:io_device()) -> no_return(). output_object_record(SchemaGraph, SchemaId, JsonSchema, IoDevice) -> output_title(JsonSchema, IoDevice), output_description(JsonSchema, IoDevice), @@ -278,14 +278,14 @@ output_description(JsonObject, IoDevice) -> output_description(JsonObject, IoDevice, Margin) -> output_path_value([description], JsonObject, Margin ++ "% ~s~n", IoDevice). --spec output_properties(digraph(), jsx:json_term(), file:io_device()) -> no_return(). +-spec output_properties(digraph:digraph(), jsx:json_term(), file:io_device()) -> no_return(). output_properties(SchemaGraph, JsonSchema, IoDevice) -> Properties = collect_properties(SchemaGraph, JsonSchema), NameWidth = find_longest_property_name(Properties), DefaultValueWidth = find_longest_default_value(SchemaGraph, Properties), output_property(SchemaGraph, Properties, IoDevice, NameWidth, DefaultValueWidth). --spec output_property(digraph(), list(jsx:json_term()), file:io_device(), integer(), integer()) -> ok. +-spec output_property(digraph:digraph(), list(jsx:json_term()), file:io_device(), integer(), integer()) -> ok. output_property(_, [], _, _, _) -> ok; output_property(SchemaGraph, [{PropertyName, PropertySchema}|Properties], IoDevice, NameWidth, DefaultValueWidth) -> @@ -310,7 +310,7 @@ output_property(SchemaGraph, [{PropertyName, PropertySchema}|Properties], IoDevi end, output_property(SchemaGraph, Properties, IoDevice, NameWidth, DefaultValueWidth). --spec format_default_value(digraph(), jsx:json_term(), integer()) -> binary(). +-spec format_default_value(digraph:digraph(), jsx:json_term(), integer()) -> binary(). format_default_value(_, _, 0) -> <<>>; format_default_value(SchemaGraph, PropertySchema, DefaultValueWidth) -> @@ -323,7 +323,7 @@ format_default_value(<<>>, DefaultValueWidth) -> format_default_value(DefaultValue, DefaultValueWidth) -> format_to_binary("= ~-" ++ integer_to_list(DefaultValueWidth) ++ "s ", [DefaultValue]). --spec collect_properties(digraph(), jsx:json_term()) -> list(jsx:json_term()). +-spec collect_properties(digraph:digraph(), jsx:json_term()) -> list(jsx:json_term()). collect_properties(SchemaGraph, JsonSchema) -> Properties = kvc:path([properties], JsonSchema), @@ -339,11 +339,11 @@ collect_properties(SchemaGraph, JsonSchema) -> find_longest_property_name(Properties) -> lists:max([size(PropertyName) || {PropertyName, _} <- Properties]). --spec find_longest_default_value(digraph(), jsx:json_term()) -> binary(). +-spec find_longest_default_value(digraph:digraph(), jsx:json_term()) -> binary(). find_longest_default_value(SchemaGraph, Properties) -> lists:max([size(get_property_default_value(SchemaGraph, PropertySchema)) || {_, PropertySchema} <- Properties]). --spec get_property_default_value(digraph(), jsx:json_term()) -> binary(). +-spec get_property_default_value(digraph:digraph(), jsx:json_term()) -> binary(). get_property_default_value(SchemaGraph, PropertySchema) -> case_path_has_value( ['default'], @@ -353,18 +353,18 @@ get_property_default_value(SchemaGraph, PropertySchema) -> end, fn(<<>>)). --spec convert_property_default_value(digraph(), jsx:json_term(), term()) -> binary(). +-spec convert_property_default_value(digraph:digraph(), jsx:json_term(), term()) -> binary(). convert_property_default_value(SchemaGraph, PropertySchema, DefaultValue) -> TypeSpec = get_property_type_spec(SchemaGraph, PropertySchema), convert_property_value(DefaultValue, TypeSpec). --spec convert_property_value(digraph(), binary()) -> binary(). +-spec convert_property_value(digraph:digraph(), binary()) -> binary(). convert_property_value(_, <<"term()">>) -> <<>>; convert_property_value(DefaultValue, _) -> format_to_binary("~p", [DefaultValue]). --spec get_property_type_spec(digraph(), jsx:json_term()) -> binary(). +-spec get_property_type_spec(digraph:digraph(), jsx:json_term()) -> binary(). get_property_type_spec(SchemaGraph, PropertySchema) -> case_path_has_value( ['$ref'], @@ -376,7 +376,7 @@ get_property_type_spec(SchemaGraph, PropertySchema) -> convert_property_type_spec(SchemaGraph, kvc:path([type], PropertySchema), PropertySchema) end). --spec get_schema_reference_type_spec(digraph(), binary()) -> binary(). +-spec get_schema_reference_type_spec(digraph:digraph(), binary()) -> binary(). get_schema_reference_type_spec(SchemaGraph, Ref) -> {RawSchemaId, JsonSchema} = get_schema(SchemaGraph, Ref), SchemaId = get_schema_id(RawSchemaId, JsonSchema), @@ -392,7 +392,7 @@ get_enum_type_spec([Value|Values]) -> " | ", (get_enum_type_spec(Values))/binary>>. --spec convert_property_type_spec(digraph(), jsx:json_term(), jsx:json_term()) -> binary(). +-spec convert_property_type_spec(digraph:digraph(), jsx:json_term(), jsx:json_term()) -> binary(). convert_property_type_spec(_, [], _) -> <<"term()">>; % default type convert_property_type_spec(SchemaGraph, [UnionedType], PropertySchema) -> @@ -517,4 +517,4 @@ get_jerg_version() -> id(T) -> T. -spec fn(term()) -> fun(() -> term()). -fn(T) -> fun() -> T end. \ No newline at end of file +fn(T) -> fun() -> T end.