Skip to content

Commit ca562ab

Browse files
Changes: inlines anonymous schema nodes in elm code
- Changes: inlines anonymous schema nodes in elm code to reduce the scenarios where we have to auto-generate names like 'zero' and 'one'. - Cleans: major refactoring of the code structure such that the EEx templates correspond to the different output types, e.g. product types, sum decoders, list fuzzers, etc., rather than the different input types, e.g. array, object, oneOf, etc. - Cleans: related to the above point, all the different output elm types/decoders/encoders/fuzzers now have proper type specifications in the elm_{types,decoders,encoders,fuzzers}.ex util modules.
1 parent 40f19de commit ca562ab

File tree

77 files changed

+1894
-1949
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+1894
-1949
lines changed

.formatter.exs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
[
2-
inputs: ["mix.exs", "{config,lib,test}/**/*.{ex,exs}"],
3-
line_length: 80
2+
inputs: ["mix.exs", "{config,lib,test}/**/*.{ex,exs}"]
43
]

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ js2e
33
/js2e_output
44
node_modules
55
elm-stuff
6+
package-lock.json
67

78
# The directory Mix will write compiled artifacts to.
89
/_build

examples/example-output-elm-code/src/Data/Circle.elm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ module Data.Circle exposing (..)
22

33
-- Schema for a circle shape
44

5+
import Data.Definitions as Definitions
6+
import Data.Encode as Encode
57
import Json.Decode as Decode exposing (Decoder)
68
import Json.Decode.Extra as Decode
79
import Json.Decode.Pipeline
@@ -11,8 +13,6 @@ import Json.Decode.Pipeline
1113
, required
1214
)
1315
import Json.Encode as Encode exposing (Value)
14-
import Data.Encode as Encode
15-
import Data.Definitions as Definitions
1616

1717

1818
type alias Circle =

lib/js2e.ex

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ defmodule JS2E do
2626

2727
@spec main([String.t()]) :: :ok
2828
def main(args) do
29-
{options, paths, errors} =
30-
OptionParser.parse(args, switches: [module_name: :string])
29+
{options, paths, errors} = OptionParser.parse(args, switches: [module_name: :string])
3130

3231
if Enum.empty?(paths) == true do
3332
IO.puts(@moduledoc)
@@ -42,9 +41,7 @@ defmodule JS2E do
4241
files = resolve_all_paths(paths)
4342

4443
if Enum.empty?(files) == true do
45-
print_error(
46-
"Error: Could not find any JSON files in path: #{inspect(paths)}"
47-
)
44+
print_error("Error: Could not find any JSON files in path: #{inspect(paths)}")
4845

4946
exit(:no_files)
5047
end
@@ -125,11 +122,9 @@ defmodule JS2E do
125122
else
126123
Logger.info("Converting to Elm code!")
127124

128-
printer_result =
129-
Printer.print_schemas(parser_result.schema_dict, module_name)
125+
printer_result = Printer.print_schemas(parser_result.schema_dict, module_name)
130126

131-
tests_printer_result =
132-
Printer.print_schemas_tests(parser_result.schema_dict, module_name)
127+
tests_printer_result = Printer.print_schemas_tests(parser_result.schema_dict, module_name)
133128

134129
cond do
135130
length(printer_result.errors) > 0 ->
@@ -311,8 +306,7 @@ defmodule JS2E do
311306
end
312307

313308
defp warning_header do
314-
header =
315-
String.duplicate("^", 35) <> " WARNINGS " <> String.duplicate("^", 35)
309+
header = String.duplicate("^", 35) <> " WARNINGS " <> String.duplicate("^", 35)
316310

317311
IO.puts(IO.ANSI.format([:yellow, header]))
318312
end

0 commit comments

Comments
 (0)