Skip to content

Commit

Permalink
rebuild examples (tyrchen#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyrchen authored Dec 2, 2020
1 parent 3b13e23 commit bc631f0
Show file tree
Hide file tree
Showing 25 changed files with 88 additions and 1,066 deletions.
3 changes: 3 additions & 0 deletions builder/lib/mix/tasks/compile.quenya.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ defmodule Mix.Tasks.Compile.Quenya do

defp build_spec do
cwd = File.cwd!()

# remove existing files
Enum.each(["gen", "lib/gen", "test/gen"], &File.rm_rf!/1)
filename = Path.join(cwd, "priv/spec/main.yml")
app = Mix.Project.config()[:app]
QuenyaBuilder.run(filename, app)
Expand Down
10 changes: 6 additions & 4 deletions builder/lib/quenya_builder/api_router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ defmodule QuenyaBuilder.ApiRouter do

alias QuenyaBuilder.Object

def gen(doc, app, opts \\ []) do
def gen(doc, base_path, app, opts \\ []) do
mod_name = Util.gen_api_router_name(app)

preamble = gen_preamble()

contents =
Enum.map(doc, fn {uri, ops} ->
gen_uri(uri, ops, app, opts)
gen_uri(uri, base_path, ops, app, opts)
end)
|> List.flatten()

Expand All @@ -45,7 +45,7 @@ defmodule QuenyaBuilder.ApiRouter do
end
end

defp gen_uri(uri, ops, app, opts) do
defp gen_uri(uri, base_path, ops, app, opts) do
Enum.map(ops, fn {method, doc} ->
name =
doc["operationId"] ||
Expand Down Expand Up @@ -73,7 +73,9 @@ defmodule QuenyaBuilder.ApiRouter do
|> Keyword.put(:type, :test)
|> Keyword.update!(:path, fn _ -> "test/gen" end)

UnitTestGenerator.gen(method, uri, req, params, res, app, name, ut_opts)
if Application.get_env(:quenya, :gen_tests, true) do
UnitTestGenerator.gen(method, Path.join(base_path, uri), req, params, res, app, name, ut_opts)
end

init_opts = gen_route_plug_opts(app, name)

Expand Down
14 changes: 8 additions & 6 deletions builder/lib/quenya_builder/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@ defmodule QuenyaBuilder.Router do

mod_name = Util.gen_router_name(app)

uri =
Util.get_localhost_uri(root["servers"]) || raise "Must define localhost under servers in OAS3 spec."

base_path = uri.path || "/"

preamble = gen_preamble()
contents = gen_contents(root["servers"], app)
contents = gen_contents(base_path, app)

ApiRouter.gen(doc, app, opts)
ApiRouter.gen(doc, base_path, app, opts)

DynamicModule.gen(mod_name, preamble, contents, opts)
end
Expand All @@ -32,11 +37,8 @@ defmodule QuenyaBuilder.Router do
end
end

defp gen_contents(servers, app) do
uri =
Util.get_localhost_uri(servers) || raise "Must define localhost under servers in OAS3 spec."
defp gen_contents(path, app) do

path = uri.path || "/"
api_router_mod = Module.concat("Elixir", Util.gen_api_router_name(app))

routes = [
Expand Down
2 changes: 1 addition & 1 deletion builder/mix.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule QuenyaBuilder.MixProject do
use Mix.Project

@version "0.3.1"
@version "0.3.2"
def project do
[
app: :quenya_builder,
Expand Down
33 changes: 0 additions & 33 deletions builder/test/fixture/todo/main.yml

This file was deleted.

34 changes: 0 additions & 34 deletions builder/test/fixture/todo/params.yml

This file was deleted.

21 changes: 0 additions & 21 deletions builder/test/fixture/todo/responses.yml

This file was deleted.

47 changes: 0 additions & 47 deletions builder/test/fixture/todo/schemas.yml

This file was deleted.

47 changes: 0 additions & 47 deletions builder/test/fixture/todo/services/todo.yml

This file was deleted.

41 changes: 0 additions & 41 deletions builder/test/fixture/todo/services/todos.yml

This file was deleted.

8 changes: 0 additions & 8 deletions config/config.exs

This file was deleted.

2 changes: 2 additions & 0 deletions examples/petstore/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@ petstore-*.tar

# Quenya generated code
/gen
/lib/gen
/test/gen
7 changes: 3 additions & 4 deletions examples/petstore/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ defmodule Petstore.MixProject do
version: "0.1.0",
elixir: "~> 1.10",
elixirc_paths: elixirc_paths(Mix.env()),
compilers: [:quenya] ++ Mix.compilers(),
compilers: Mix.compilers(),
start_permanent: Mix.env() == :prod,
deps: deps()
]
Expand Down Expand Up @@ -36,14 +36,13 @@ defmodule Petstore.MixProject do
{:plug_cowboy, "~> 2.0"},

# Quenya
{:quenya, "~> 0.2"},
{:quenya, path: "../..", override: true},

# Quenya builder
{:quenya_builder, "~> 0.2", runtime: false},
{:quenya_builder, path: "../../builder", override: true, runtime: false},

# Only needed if you'd like to generate fake handler
{:json_data_faker, "~> 0.1"}

]
end
end
10 changes: 6 additions & 4 deletions examples/petstore/mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,23 @@
"cowboy_telemetry": {:hex, :cowboy_telemetry, "0.3.1", "ebd1a1d7aff97f27c66654e78ece187abdc646992714164380d8a041eda16754", [:rebar3], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "3a6efd3366130eab84ca372cbd4a7d3c3a97bdfcfb4911233b035d117063f0af"},
"cowlib": {:hex, :cowlib, "2.9.1", "61a6c7c50cf07fdd24b2f45b89500bb93b6686579b069a89f88cb211e1125c78", [:rebar3], [], "hexpm", "e4175dc240a70d996156160891e1c62238ede1729e45740bdd38064dad476170"},
"deep_merge": {:hex, :deep_merge, "1.0.0", "b4aa1a0d1acac393bdf38b2291af38cb1d4a52806cf7a4906f718e1feb5ee961", [:mix], [], "hexpm", "ce708e5f094b9cd4e8f2be4f00d2f4250c4095be93f8cd6d018c753894885430"},
"dynamic_module": {:hex, :dynamic_module, "0.1.10", "d2fe266449c70a29d9d13572cd27cdb59ef5e49b596f940375c34c12e7276bad", [:mix], [{:recase, "~> 0.3", [hex: :recase, repo: "hexpm", optional: false]}], "hexpm", "cf4489bc0863044d96b56eec3cdde20f240e738f86ee031faefa23b3db06cfa0"},
"dynamic_module_new": {:hex, :dynamic_module_new, "0.1.12", "41c92b0eeb9bc1d76598a3baf78e0fe530683dc693079691d04591221ed24fc0", [:mix], [{:recase, "~> 0.7", [hex: :recase, repo: "hexpm", optional: false]}], "hexpm", "f99eb9d68f5dff5b0c351df8878fc6610209f3c0070b810875c19517be4a6ccf"},
"ex_json_schema": {:hex, :ex_json_schema, "0.7.4", "09eb5b0c8184e5702bc89625a9d0c05c7a0a845d382e9f6f406a0fc1c9a8cc3f", [:mix], [], "hexpm", "45c67fa840f0d719a2b5578126dc29bcdc1f92499c0f61bcb8a3bcb5935f9684"},
"faker": {:hex, :faker, "0.16.0", "1e2cf3e8d60d44a30741fb98118fcac18b2020379c7e00d18f1a005841b2f647", [:mix], [], "hexpm", "fbcb9bf1299dff3c9dd7e50f41802bbc472ffbb84e7656394c8aa913ec315141"},
"jason": {:hex, :jason, "1.2.2", "ba43e3f2709fd1aa1dce90aaabfd039d000469c05c56f0b8e31978e03fa39052", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "18a228f5f0058ee183f29f9eae0805c6e59d61c3b006760668d8d18ff0d12179"},
"json_data_faker": {:hex, :json_data_faker, "0.1.0", "503c9abc31c662fcb6c5382bf21622c90017e56bf19dac9513615c907710e47d", [:mix], [{:ex_json_schema, "~> 0.7", [hex: :ex_json_schema, repo: "hexpm", optional: false]}, {:faker, "~> 0.16", [hex: :faker, repo: "hexpm", optional: false]}, {:randex, "~> 0.4.0", [hex: :randex, repo: "hexpm", optional: false]}, {:uuid, "~> 1.1", [hex: :uuid, repo: "hexpm", optional: false]}], "hexpm", "88135acc49bf9669d9c1e0baa4a12013f2eb1fd4762ce8d3d1941cc73fd43ef3"},
"json_data_faker": {:hex, :json_data_faker, "0.2.0", "1e5db984f14889c15e045c66f612bf09a0d7559901a08d01ed2c16181b3ad569", [:mix], [{:ex_json_schema, "~> 0.7", [hex: :ex_json_schema, repo: "hexpm", optional: false]}, {:faker, "~> 0.16", [hex: :faker, repo: "hexpm", optional: false]}, {:randex, "~> 0.4.0", [hex: :randex, repo: "hexpm", optional: false]}, {:stream_data, "~> 0.5", [hex: :stream_data, repo: "hexpm", optional: false]}, {:uuid, "~> 1.1", [hex: :uuid, repo: "hexpm", optional: false]}], "hexpm", "7285f97b37e6aa8de50a67a84dc0b89ea9fb0c8b8b08114892512135d778fb23"},
"mime": {:hex, :mime, "1.5.0", "203ef35ef3389aae6d361918bf3f952fa17a09e8e43b5aa592b93eba05d0fb8d", [:mix], [], "hexpm", "55a94c0f552249fc1a3dd9cd2d3ab9de9d3c89b559c2bd01121f824834f24746"},
"plug": {:hex, :plug, "1.11.0", "f17217525597628298998bc3baed9f8ea1fa3f1160aa9871aee6df47a6e4d38e", [:mix], [{:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "2d9c633f0499f9dc5c2fd069161af4e2e7756890b81adcbb2ceaa074e8308876"},
"plug_cowboy": {:hex, :plug_cowboy, "2.4.1", "779ba386c0915027f22e14a48919a9545714f849505fa15af2631a0d298abf0f", [:mix], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:cowboy_telemetry, "~> 0.3", [hex: :cowboy_telemetry, repo: "hexpm", optional: false]}, {:plug, "~> 1.7", [hex: :plug, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "d72113b6dff7b37a7d9b2a5b68892808e3a9a752f2bf7e503240945385b70507"},
"plug_crypto": {:hex, :plug_crypto, "1.2.0", "1cb20793aa63a6c619dd18bb33d7a3aa94818e5fd39ad357051a67f26dfa2df6", [:mix], [], "hexpm", "a48b538ae8bf381ffac344520755f3007cc10bd8e90b240af98ea29b69683fc2"},
"quenya": {:hex, :quenya, "0.2.1", "e79c4f905e1339541b02be7d95dac3c2b7edf84d4f7629c8e4fa9f7f6623e213", [:mix], [{:deep_merge, "~> 1.0", [hex: :deep_merge, repo: "hexpm", optional: false]}, {:ex_json_schema, "~> 0.7", [hex: :ex_json_schema, repo: "hexpm", optional: false]}, {:jason, "~> 1.2", [hex: :jason, repo: "hexpm", optional: false]}, {:plug, "~>1.11", [hex: :plug, repo: "hexpm", optional: false]}, {:uuid, "~> 1.0", [hex: :uuid, repo: "hexpm", optional: false]}, {:yaml_elixir, "~> 2.5", [hex: :yaml_elixir, repo: "hexpm", optional: false]}], "hexpm", "480815b06f8dfe8c24dd2f9befbff79a7f6cb156636195be36ef034cf72fd480"},
"quenya_builder": {:hex, :quenya_builder, "0.2.1", "404896813b491a657e27b3ed9a009acd67d20f3dcad8227dd154a2bddb144f7d", [:mix], [{:dynamic_module, "~> 0.1", [hex: :dynamic_module, repo: "hexpm", optional: false]}, {:ex_json_schema, "~> 0.7", [hex: :ex_json_schema, repo: "hexpm", optional: false]}, {:jason, "~> 1.2", [hex: :jason, repo: "hexpm", optional: false]}, {:json_data_faker, "~> 0.1", [hex: :json_data_faker, repo: "hexpm", optional: false]}, {:plug, "~> 1.11", [hex: :plug, repo: "hexpm", optional: false]}, {:quenya, "~> 0.2", [hex: :quenya, repo: "hexpm", optional: false]}, {:recase, "~> 0.7", [hex: :recase, repo: "hexpm", optional: false]}], "hexpm", "3f861fa1d8cd0170904d462e414936061f23d6a1e6b4e351c01f596007c35336"},
"quenya": {:hex, :quenya, "0.3.0", "3cc2c0ea5e5e24551f2ee1b1d7d6c46aa98b6ad0be1931ed2cd336a768a53ecf", [:mix], [{:deep_merge, "~> 1.0", [hex: :deep_merge, repo: "hexpm", optional: false]}, {:ex_json_schema, "~> 0.7", [hex: :ex_json_schema, repo: "hexpm", optional: false]}, {:jason, "~> 1.2", [hex: :jason, repo: "hexpm", optional: false]}, {:json_data_faker, "~> 0.2", [hex: :json_data_faker, repo: "hexpm", optional: false]}, {:plug, "~>1.11", [hex: :plug, repo: "hexpm", optional: false]}, {:stream_data, "~> 0.5", [hex: :stream_data, repo: "hexpm", optional: false]}, {:uuid, "~> 1.0", [hex: :uuid, repo: "hexpm", optional: false]}, {:yaml_elixir, "~> 2.5", [hex: :yaml_elixir, repo: "hexpm", optional: false]}], "hexpm", "02472f4936dead804160c3173e07093be9fd76eafa11ee60b25ab48f5348f41e"},
"quenya_builder": {:hex, :quenya_builder, "0.3.1", "586cfecc78f6fa333e4453bf057cf16d9b0523651f11594e54fd3f782beed5f8", [:mix], [{:dynamic_module_new, "~> 0.1", [hex: :dynamic_module_new, repo: "hexpm", optional: false]}, {:ex_json_schema, "~> 0.7", [hex: :ex_json_schema, repo: "hexpm", optional: false]}, {:jason, "~> 1.2", [hex: :jason, repo: "hexpm", optional: false]}, {:json_data_faker, "~> 0.2", [hex: :json_data_faker, repo: "hexpm", optional: false]}, {:plug, "~> 1.11", [hex: :plug, repo: "hexpm", optional: false]}, {:quenya, "~> 0.3", [hex: :quenya, repo: "hexpm", optional: false]}, {:recase, "~> 0.7", [hex: :recase, repo: "hexpm", optional: false]}, {:stream_data, "~> 0.5", [hex: :stream_data, repo: "hexpm", optional: false]}, {:typed_struct, "~> 0.2.1", [hex: :typed_struct, repo: "hexpm", optional: false]}], "hexpm", "f55431a991e46b89a2c2147abe8dc0598b67e4f5ca8a0284a1b948b2e34b7622"},
"ranch": {:hex, :ranch, "1.7.1", "6b1fab51b49196860b733a49c07604465a47bdb78aa10c1c16a3d199f7f8c881", [:rebar3], [], "hexpm", "451d8527787df716d99dc36162fca05934915db0b6141bbdac2ea8d3c7afc7d7"},
"randex": {:hex, :randex, "0.4.0", "f76712da3663dd7d4166e017829ec428dc67df9e11b82d923dfd6f9b4854b373", [:mix], [{:stream_data, "~> 0.4", [hex: :stream_data, repo: "hexpm", optional: true]}], "hexpm", "f803f256542bd264acea832a69f6e5fea3df4cd3f8a9f03588e5593f04c61095"},
"recase": {:hex, :recase, "0.7.0", "3f2f719f0886c7a3b7fe469058ec539cb7bbe0023604ae3bce920e186305e5ae", [:mix], [], "hexpm", "36f5756a9f552f4a94b54a695870e32f4e72d5fad9c25e61bc4a3151c08a4e0c"},
"stream_data": {:hex, :stream_data, "0.5.0", "b27641e58941685c75b353577dc602c9d2c12292dd84babf506c2033cd97893e", [:mix], [], "hexpm", "012bd2eec069ada4db3411f9115ccafa38540a3c78c4c0349f151fc761b9e271"},
"telemetry": {:hex, :telemetry, "0.4.2", "2808c992455e08d6177322f14d3bdb6b625fbcfd233a73505870d8738a2f4599", [:rebar3], [], "hexpm", "2d1419bd9dda6a206d7b5852179511722e2b18812310d304620c7bd92a13fcef"},
"typed_struct": {:hex, :typed_struct, "0.2.1", "e1993414c371f09ff25231393b6430bd89d780e2a499ae3b2d2b00852f593d97", [:mix], [], "hexpm", "8f5218c35ec38262f627b2c522542f1eae41f625f92649c0af701a6fab2e11b3"},
"uuid": {:hex, :uuid, "1.1.8", "e22fc04499de0de3ed1116b770c7737779f226ceefa0badb3592e64d5cfb4eb9", [:mix], [], "hexpm", "c790593b4c3b601f5dc2378baae7efaf5b3d73c4c6456ba85759905be792f2ac"},
"yamerl": {:hex, :yamerl, "0.8.0", "8214cfe16bbabe5d1d6c14a14aea11c784b9a21903dd6a7c74f8ce180adae5c7", [:rebar3], [], "hexpm", "010634477bf9c208a0767dcca89116c2442cf0b5e87f9c870f85cd1c3e0c2aab"},
"yaml_elixir": {:hex, :yaml_elixir, "2.5.0", "45de762be6d75fa5a8b5f44ddff8c30f64c26526eab5b1d72e36d616007b7796", [:mix], [{:yamerl, "~> 0.7", [hex: :yamerl, repo: "hexpm", optional: false]}], "hexpm", "80fe4e43f05582f2a90f2dcd73fc6171fbd65f2e6836f71fe4ce2154ef358c36"},
Expand Down
2 changes: 2 additions & 0 deletions examples/todo/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@ todo-*.tar

# Quenya generated code
/gen
/lib/gen
/test/gen
Loading

0 comments on commit bc631f0

Please sign in to comment.