-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto-define open_api_operation/1 for each operation spec
- Loading branch information
Showing
2 changed files
with
62 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,56 @@ | ||
defmodule OpenApiSpex.OperationDslTest do | ||
use ExUnit.Case, async: true | ||
|
||
import ExUnit.CaptureIO | ||
|
||
alias OpenApiSpexTest.DslController | ||
|
||
test "operation/1" do | ||
assert [ | ||
show: %OpenApiSpex.Operation{ | ||
describe "operation/1" do | ||
test "defines open_api_operation/1 for :show action" do | ||
assert %OpenApiSpex.Operation{ | ||
responses: [], | ||
summary: "Show user", | ||
parameters: show_parameters, | ||
tags: show_tags | ||
}, | ||
index: %OpenApiSpex.Operation{ | ||
} = DslController.open_api_operation(:show) | ||
|
||
assert show_tags == ["users"] | ||
|
||
assert [ | ||
%OpenApiSpex.Parameter{ | ||
description: "User ID", | ||
example: 1001, | ||
in: :path, | ||
name: :id, | ||
required: true, | ||
schema: %OpenApiSpex.Schema{type: :integer} | ||
} | ||
] = show_parameters | ||
end | ||
|
||
test "defines open_api_operation/1 for :index action" do | ||
assert %OpenApiSpex.Operation{ | ||
responses: [], | ||
summary: "User index", | ||
parameters: index_parameters | ||
} | ||
] = DslController.spec_attributes() | ||
|
||
assert show_tags == ["users"] | ||
|
||
assert [ | ||
%OpenApiSpex.Parameter{ | ||
description: "User ID", | ||
example: 1001, | ||
in: :path, | ||
name: :id, | ||
required: true, | ||
schema: %OpenApiSpex.Schema{type: :integer} | ||
} | ||
] = show_parameters | ||
|
||
assert [ | ||
%OpenApiSpex.Parameter{ | ||
description: "Free-form query string", | ||
example: "jane", | ||
in: :query, | ||
name: :query, | ||
schema: %OpenApiSpex.Schema{type: :string} | ||
} | ||
] = index_parameters | ||
} = DslController.open_api_operation(:index) | ||
|
||
assert [ | ||
%OpenApiSpex.Parameter{ | ||
description: "Free-form query string", | ||
example: "jane", | ||
in: :query, | ||
name: :query, | ||
schema: %OpenApiSpex.Schema{type: :string} | ||
} | ||
] = index_parameters | ||
end | ||
|
||
test "outputs warning when action not defined for called open_api_operation" do | ||
output = capture_io(:stderr, fn -> DslController.open_api_operation(:undefined) end) | ||
|
||
assert output =~ | ||
~r/warning:.*No operation spec defined for controller action OpenApiSpexTest.DslController.undefined/ | ||
end | ||
end | ||
end |