Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ControllerSpecs add support for deprecated #296

Merged
merged 1 commit into from
Oct 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/open_api_spex/controller_specs.ex
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ defmodule OpenApiSpex.ControllerSpecs do

%Operation{
description: Map.get(spec, :description),
deprecated: Map.get(spec, :deprecated),
operationId: OperationBuilder.build_operation_id(spec, module, action),
parameters: OperationBuilder.build_parameters(spec),
requestBody: OperationBuilder.build_request_body(spec),
Expand Down
7 changes: 7 additions & 0 deletions test/controller_specs_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ defmodule OpenApiSpex.ControllerSpecsTest do
assert %MediaType{schema: OpenApiSpexTest.DslController.UserResponse} = media_type
end

test ":deprecated" do
assert %OpenApiSpex.Operation{
summary: "User destroy",
deprecated: true
} = DslController.open_api_operation(:destroy)
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)

Expand Down
27 changes: 27 additions & 0 deletions test/support/dsl_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ defmodule OpenApiSpexTest.DslController do
})
end

defmodule UsersDestroyResponse do
alias OpenApiSpex.Schema
require OpenApiSpex

OpenApiSpex.schema(%{
type: :string
})
end

tags ["users"]

security [%{"api_key" => ["mySecurityScheme"]}]
Expand Down Expand Up @@ -93,4 +102,22 @@ defmodule OpenApiSpexTest.DslController do
def index(conn, _) do
json(conn, [])
end

operation :destroy,
deprecated: true,
summary: "User destroy",
parameters: [
username: [
in: :query,
description: "Username to destroy",
type: :string
]
],
responses: [
no_content: {"Users destroy response", "application/json", UsersDestroyResponse}
]

def index(conn, _) do
json(conn, [])
end
end