Skip to content

Commit f986d33

Browse files
Adds parser behaviour
1 parent 28a7c55 commit f986d33

13 files changed

+48
-27
lines changed

.tool-versions

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
erlang 20.0
2+
elixir 1.5.1

lib/parsers/all_of_parser.ex

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
defmodule JS2E.Parsers.AllOfParser do
2+
@behaviour JS2E.Parsers.ParserBehaviour
23
@moduledoc ~S"""
34
Parses a JSON schema allOf type:
45
@@ -36,7 +37,8 @@ defmodule JS2E.Parsers.AllOfParser do
3637
@doc ~S"""
3738
Parses a JSON schema allOf type into an `JS2E.Types.AllOfType`.
3839
"""
39-
@spec parse(map, URI.t, URI.t, TypePath.t, String.t)
40+
@impl JS2E.Parsers.ParserBehaviour
41+
@spec parse(map, URI.t, URI.t | nil, TypePath.t, String.t)
4042
:: Types.typeDictionary
4143
def parse(schema_node, parent_id, id, path, name) do
4244
Logger.debug "Parsing '#{inspect path}' as allOf type"

lib/parsers/any_of_parser.ex

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
defmodule JS2E.Parsers.AnyOfParser do
2+
@behaviour JS2E.Parsers.ParserBehaviour
23
@moduledoc ~S"""
34
Parses a JSON schema anyOf type:
45
@@ -36,7 +37,8 @@ defmodule JS2E.Parsers.AnyOfParser do
3637
@doc ~S"""
3738
Parses a JSON schema anyOf type into an `JS2E.Types.AnyOfType`.
3839
"""
39-
@spec parse(map, URI.t, URI.t, TypePath.t, String.t)
40+
@impl JS2E.Parsers.ParserBehaviour
41+
@spec parse(map, URI.t, URI.t | nil, TypePath.t, String.t)
4042
:: Types.typeDictionary
4143
def parse(schema_node, parent_id, id, path, name) do
4244
Logger.debug "Parsing '#{inspect path}' as anyOf type"

lib/parsers/array_parser.ex

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
defmodule JS2E.Parsers.ArrayParser do
2+
@behaviour JS2E.Parsers.ParserBehaviour
23
@moduledoc ~S"""
34
Parses a JSON schema array type:
45
@@ -20,7 +21,8 @@ defmodule JS2E.Parsers.ArrayParser do
2021
@doc ~S"""
2122
Parses a JSON schema array type into an `JS2E.Types.ArrayType`.
2223
"""
23-
@spec parse(map, URI.t, URI.t, TypePath.t, String.t)
24+
@impl JS2E.Parsers.ParserBehaviour
25+
@spec parse(map, URI.t, URI.t | nil, TypePath.t, String.t)
2426
:: Types.typeDictionary
2527
def parse(schema_node, parent_id, id, path, name) do
2628
Logger.debug "Parsing '#{inspect path}' as ArrayType"

lib/parsers/definitions_parser.ex

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
defmodule JS2E.Parsers.DefinitionsParser do
2+
@behaviour JS2E.Parsers.ParserBehaviour
23
@moduledoc ~S"""
34
Parses a 'definitions' property in a JSON schema or subschema.
45
@@ -20,13 +21,9 @@ defmodule JS2E.Parsers.DefinitionsParser do
2021
@doc ~S"""
2122
Parses a JSON schema 'definitions' property into a map of types.
2223
"""
23-
@spec parse(
24-
map,
25-
URI.t,
26-
URI.t | nil,
27-
TypePath.t,
28-
String.t
29-
) :: Types.typeDictionary
24+
@impl JS2E.Parsers.ParserBehaviour
25+
@spec parse(map, URI.t, URI.t | nil, TypePath.t, String.t)
26+
:: Types.typeDictionary
3027
def parse(schema_node, parent_id, _id, path, _name) do
3128
Logger.debug "Parsing '#{inspect path}' as definitions"
3229

lib/parsers/enum_parser.ex

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
defmodule JS2E.Parsers.EnumParser do
2+
@behaviour JS2E.Parsers.ParserBehaviour
23
@moduledoc ~S"""
34
Parse a JSON schema enum type:
45
@@ -18,7 +19,9 @@ defmodule JS2E.Parsers.EnumParser do
1819
@doc ~S"""
1920
Parses a JSON schema enum type into an `JS2E.Types.EnumType`.
2021
"""
21-
@spec parse(map, URI.t, URI.t, TypePath.t, String.t) :: Types.typeDictionary
22+
@impl JS2E.Parsers.ParserBehaviour
23+
@spec parse(map, URI.t, URI.t | nil, TypePath.t, String.t)
24+
:: Types.typeDictionary
2225
def parse(schema_node, _parent_id, id, path, name) do
2326
Logger.debug "parsing '#{inspect path}' as EnumType"
2427

lib/parsers/object_parser.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
defmodule JS2E.Parsers.ObjectParser do
2+
@behaviour JS2E.Parsers.ParserBehaviour
23
@moduledoc ~S"""
34
Parses a JSON schema object type:
45
@@ -29,6 +30,7 @@ defmodule JS2E.Parsers.ObjectParser do
2930
@doc ~S"""
3031
Parses a JSON schema object type into an `JS2E.Types.ObjectType`.
3132
"""
33+
@impl JS2E.Parsers.ParserBehaviour
3234
@spec parse(map, URI.t, URI.t, TypePath.t, String.t) :: Types.typeDictionary
3335
def parse(schema_node, parent_id, id, path, name) do
3436
Logger.debug "Parsing '#{inspect path}' as ObjectType"

lib/parsers/one_of_parser.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
defmodule JS2E.Parsers.OneOfParser do
2+
@behaviour JS2E.Parsers.ParserBehaviour
23
@moduledoc ~S"""
34
Parses a JSON schema oneOf type:
45
@@ -36,6 +37,7 @@ defmodule JS2E.Parsers.OneOfParser do
3637
@doc ~S"""
3738
Parses a JSON schema oneOf type into an `JS2E.Types.OneOfType`.
3839
"""
40+
@impl JS2E.Parsers.ParserBehaviour
3941
@spec parse(map, URI.t, URI.t, TypePath.t, String.t)
4042
:: Types.typeDictionary
4143
def parse(schema_node, parent_id, id, path, name) do

lib/parsers/parser_behaviour.ex

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
defmodule JS2E.Parsers.ParserBehaviour do
2+
@moduledoc ~S"""
3+
Describes the functions needed to implement a parser for a JSON schema node.
4+
"""
5+
6+
@callback parse(map, URI.t, URI.t | nil, TypePath.t, String.t)
7+
:: Types.typeDictionary
8+
end

lib/parsers/primitive_parser.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
defmodule JS2E.Parsers.PrimitiveParser do
2+
@behaviour JS2E.Parsers.ParserBehaviour
23
@moduledoc ~S"""
34
Parses a JSON schema primitive type:
45
@@ -17,6 +18,7 @@ defmodule JS2E.Parsers.PrimitiveParser do
1718
@doc ~S"""
1819
Parses a JSON schema primitive type into an `JS2E.Types.PrimitiveType`.
1920
"""
21+
@impl JS2E.Parsers.ParserBehaviour
2022
@spec parse(map, URI.t, URI.t, TypePath.t, String.t) :: Types.typeDictionary
2123
def parse(schema_node, _parent_id, id, path, name) do
2224
Logger.debug "Parsing '#{inspect path}' as primitive type"

0 commit comments

Comments
 (0)