From 24cbffd4a0d941adde8b028bc24d3a5fbcb83c81 Mon Sep 17 00:00:00 2001 From: Mathias Polligkeit Date: Fri, 2 Jun 2017 23:08:31 +0200 Subject: [PATCH 1/2] group resources by path --- lib/blue_bird/writer/blueprint.ex | 32 ++++++++++++++++++++----- mix.exs | 2 +- mix.lock | 2 +- test/support/examples/grouping.ex | 28 ++++++++++++++-------- test/support/examples/notes_warnings.ex | 8 +++++-- test/support/examples/parameters.ex | 4 +++- test/support/examples/requests.ex | 6 +++-- test/support/examples/responses.ex | 12 +++++++--- test/support/examples/route_titles.ex | 8 +++++-- test/support/examples/simple.ex | 12 +++++++--- test/writer/blueprint_test.exs | 16 ++++++------- 11 files changed, 91 insertions(+), 39 deletions(-) diff --git a/lib/blue_bird/writer/blueprint.ex b/lib/blue_bird/writer/blueprint.ex index 802ebaa..33f05fe 100644 --- a/lib/blue_bird/writer/blueprint.ex +++ b/lib/blue_bird/writer/blueprint.ex @@ -80,9 +80,29 @@ defmodule BlueBird.Writer.Blueprint do end @spec process_group({String.t | nil, [Route.t]}) :: String.t - defp process_group({nil, routes}), do: process_routes(routes) + defp process_group({nil, routes}) do + routes + |> group_routes(:path) + |> process_resources + end defp process_group({group_name, routes}) do + grouped_routes = group_routes(routes, :path) + "# Group #{group_name}\n\n" + <> process_resources(grouped_routes) + end + + ## Resources + + @spec process_resources([{String.t, [{String.t, String.t, [Route.t]}]}]) :: + String.t + defp process_resources(resources) do + Enum.map_join(resources, "\n", &process_resource(&1)) + end + + @spec process_resource({String.t | nil, [Route.t]}) :: String.t + defp process_resource({path, routes}) do + "## #{routes |> Enum.at(0) |> display_path}\n\n" <> process_routes(routes) end @@ -201,14 +221,14 @@ defmodule BlueBird.Writer.Blueprint do defp print_route_definition(route) do path = display_path(route) - print_route_header(route.method, path, route.title) + print_route_header(route.method, route.title) <> print_route_description(route.description) end - @spec print_route_header(String.t, String.t, String.t | nil) :: String.t - defp print_route_header(method, path, nil), do: "## #{method} #{path}\n" - defp print_route_header(method, path, title) do - "## #{title} [#{method} #{path}]\n" + @spec print_route_header(String.t, String.t | nil) :: String.t + defp print_route_header(method, nil), do: "### #{method}\n" + defp print_route_header(method, title) do + "### #{title} [#{method}]\n" end @spec print_route_description(String.t | nil) :: String.t diff --git a/mix.exs b/mix.exs index fb7873e..521f74b 100644 --- a/mix.exs +++ b/mix.exs @@ -51,7 +51,7 @@ defmodule BlueBird.Mixfile do defp deps do [ # Static code analysis - {:credo, "~> 0.8.0-rc7", only: [:dev, :test]}, + {:credo, "~> 0.8.0", only: [:dev, :test]}, {:dialyxir, "~> 0.5.0", only: [:dev, :test], runtime: false}, # Coverage diff --git a/mix.lock b/mix.lock index 1d31bf7..78d43e9 100644 --- a/mix.lock +++ b/mix.lock @@ -1,6 +1,6 @@ %{"bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], []}, "certifi": {:hex, :certifi, "1.2.1", "c3904f192bd5284e5b13f20db3ceac9626e14eeacfbb492e19583cf0e37b22be", [:rebar3], []}, - "credo": {:hex, :credo, "0.8.0-rc7", "8cd92113a5cb37487102e5551240bdc6e4d93c19bdf7fc902f865ff0b4887256", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, optional: false]}]}, + "credo": {:hex, :credo, "0.8.0", "187ce36098afef67baa503d0bb3ec047953c88e4c662591371d15ae9ce150119", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, optional: false]}]}, "dialyxir": {:hex, :dialyxir, "0.5.0", "5bc543f9c28ecd51b99cc1a685a3c2a1a93216990347f259406a910cf048d1d7", [:mix], []}, "earmark": {:hex, :earmark, "1.2.2", "f718159d6b65068e8daeef709ccddae5f7fdc770707d82e7d126f584cd925b74", [:mix], []}, "ex_doc": {:hex, :ex_doc, "0.16.1", "b4b8a23602b4ce0e9a5a960a81260d1f7b29635b9652c67e95b0c2f7ccee5e81", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, optional: false]}]}, diff --git a/test/support/examples/grouping.ex b/test/support/examples/grouping.ex index 2a1de70..57484c2 100644 --- a/test/support/examples/grouping.ex +++ b/test/support/examples/grouping.ex @@ -76,27 +76,35 @@ defmodule BlueBird.Test.Support.Examples.Grouping do # Group Airplanes - ## GET /airplanes + ## /airplanes - ## POST /airplanes + ### GET - ## DELETE /airplanes/{id} + ### POST - ## GET /airplanes/{id} + ## /airplanes/{id} - ## PUT /airplanes/{id} + ### DELETE + + ### GET + + ### PUT # Group Cats - ## GET /cats + ## /cats + + ### GET + + ### POST - ## POST /cats + ## /cats/{id} - ## DELETE /cats/{id} + ### DELETE - ## GET /cats/{id} + ### GET - ## PUT /cats/{id} + ### PUT """ end end diff --git a/test/support/examples/notes_warnings.ex b/test/support/examples/notes_warnings.ex index 8c4f52c..f49b369 100644 --- a/test/support/examples/notes_warnings.ex +++ b/test/support/examples/notes_warnings.ex @@ -32,14 +32,18 @@ defmodule BlueBird.Test.Support.Examples.NotesWarnings do # Heavenly API - ## GET /route-with-description-and-note + ## /route-with-description-and-note + + ### GET This is my route. My route is not my enemy. ::: note This is my route. ::: - ## GET /route-with-note-and-warning + ## /route-with-note-and-warning + + ### GET ::: note This is my route. diff --git a/test/support/examples/parameters.ex b/test/support/examples/parameters.ex index 6c83ef9..5e297fb 100644 --- a/test/support/examples/parameters.ex +++ b/test/support/examples/parameters.ex @@ -82,7 +82,9 @@ defmodule BlueBird.Test.Support.Examples.Parameters do # Pastry API - ## GET /pastry/{id}/{type}{?page,query} + ## /pastry/{id}/{type}{?page,query} + + ### GET + Parameters diff --git a/test/support/examples/requests.ex b/test/support/examples/requests.ex index d0416a1..8eb8bad 100644 --- a/test/support/examples/requests.ex +++ b/test/support/examples/requests.ex @@ -13,7 +13,7 @@ defmodule BlueBird.Test.Support.Examples.Requests do path: "/request-headers", requests: [%Request{ method: "GET", - path: "/plain-with-line-breaks", + path: "/request-headers", body_params: %{"peter" => "paul", "mary" => "peter"}, headers: [ {"accept", "application/json"}, @@ -39,7 +39,9 @@ defmodule BlueBird.Test.Support.Examples.Requests do # Trendy API - ## GET /request-headers + ## /request-headers + + ### GET + Request diff --git a/test/support/examples/responses.ex b/test/support/examples/responses.ex index b02f4b5..0297ce9 100644 --- a/test/support/examples/responses.ex +++ b/test/support/examples/responses.ex @@ -66,7 +66,9 @@ defmodule BlueBird.Test.Support.Examples.Responses do # Lavish API - ## GET /multiple-headers + ## /multiple-headers + + ### GET + Response 200 (text/plain) @@ -79,7 +81,9 @@ defmodule BlueBird.Test.Support.Examples.Responses do Multiple headers. - ## GET /plain-response + ## /plain-response + + ### GET + Response 200 (text/plain) @@ -87,7 +91,9 @@ defmodule BlueBird.Test.Support.Examples.Responses do Plain response. - ## GET /plain-with-line-breaks + ## /plain-with-line-breaks + + ### GET + Response 200 (text/plain) diff --git a/test/support/examples/route_titles.ex b/test/support/examples/route_titles.ex index c363141..a669399 100644 --- a/test/support/examples/route_titles.ex +++ b/test/support/examples/route_titles.ex @@ -47,11 +47,15 @@ defmodule BlueBird.Test.Support.Examples.RouteTitles do # Group Pony - ## Ride [GET /route-with-title] + ## /route-with-title + + ### Ride [GET] + Response 204 - ## GET /route-without-title + ## /route-without-title + + ### GET + Response 204 """ diff --git a/test/support/examples/simple.ex b/test/support/examples/simple.ex index daa856b..5795328 100644 --- a/test/support/examples/simple.ex +++ b/test/support/examples/simple.ex @@ -54,11 +54,15 @@ defmodule BlueBird.Test.Support.Examples.Simple do It may be helpful. Or not. - ## GET /route-with-204-response + ## /route-with-204-response + + ### GET + Response 204 - ## GET /route-with-simple-response + ## /route-with-simple-response + + ### GET + Response 200 (text/plain) @@ -66,7 +70,9 @@ defmodule BlueBird.Test.Support.Examples.Simple do Simple response. - ## GET /route-without-info-or-response + ## /route-without-info-or-response + + ### GET """ end end diff --git a/test/writer/blueprint_test.exs b/test/writer/blueprint_test.exs index fe2e433..75a1f02 100644 --- a/test/writer/blueprint_test.exs +++ b/test/writer/blueprint_test.exs @@ -51,7 +51,7 @@ defmodule BlueBird.Test.Writer.BlueprintTest do end describe "process_route/1" do - test "prints header with method, title, path, and description" do + test "prints header with method, title, and description" do result = process_route(%Route{ method: "POST", path: "/path", @@ -60,17 +60,17 @@ defmodule BlueBird.Test.Writer.BlueprintTest do }) assert result == """ - ## Get all [POST /path] + ### Get all [POST] This route gets all things. Really. """ end - test "prints header with method and path, without title and description" do + test "prints header with method, without title and description" do result = process_route(%Route{method: "POST", path: "/path"}) - assert result == "## POST /path\n" + assert result == "### POST\n" end test "prints note" do @@ -80,7 +80,7 @@ defmodule BlueBird.Test.Writer.BlueprintTest do note: "This is important.\n\nVery." }) assert result == """ - ## POST /path + ### POST ::: note This is important. @@ -97,7 +97,7 @@ defmodule BlueBird.Test.Writer.BlueprintTest do warning: "This is important.\n\nEven more." }) assert result == """ - ## POST /path + ### POST ::: warning This is important. @@ -126,7 +126,7 @@ defmodule BlueBird.Test.Writer.BlueprintTest do }) assert result == """ - ## POST /path + ### POST + Parameters @@ -174,7 +174,7 @@ defmodule BlueBird.Test.Writer.BlueprintTest do }) assert result == """ - ## POST /users/{id}/pets{?q} + ### POST + Request (application/json) From 03bc904615356df9fef29dded110e23dde77eb98 Mon Sep 17 00:00:00 2001 From: Mathias Polligkeit Date: Wed, 14 Jun 2017 12:43:43 +0200 Subject: [PATCH 2/2] Create CHANGELOG --- CHANGELOG | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 67afd37..b8fbd6f 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,9 @@ # Changelog BlueBird +## v0.3.1 + +- group actions by resource to avoid aglio warnings + ## v0.3.0 This release is a complete rewrite of the library.