Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F116388
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/examples/phoenix_app/lib/phoenix_app_web/controllers/user_controller.ex b/examples/phoenix_app/lib/phoenix_app_web/controllers/user_controller.ex
index 73a72e9..5a30f53 100644
--- a/examples/phoenix_app/lib/phoenix_app_web/controllers/user_controller.ex
+++ b/examples/phoenix_app/lib/phoenix_app_web/controllers/user_controller.ex
@@ -1,76 +1,82 @@
defmodule PhoenixAppWeb.UserController do
use PhoenixAppWeb, :controller
import OpenApiSpex.Operation, only: [parameter: 5, request_body: 4, response: 3]
alias OpenApiSpex.Operation
alias PhoenixApp.{Accounts, Accounts.User}
alias PhoenixAppWeb.Schemas
- plug OpenApiSpex.Plug.Cast
- plug OpenApiSpex.Plug.Validate
+ plug(OpenApiSpex.Plug.Cast)
+ plug(OpenApiSpex.Plug.Validate)
def open_api_operation(action) do
apply(__MODULE__, :"#{action}_operation", [])
end
def index_operation() do
%Operation{
tags: ["users"],
summary: "List users",
description: "List all useres",
operationId: "UserController.index",
responses: %{
200 => response("User List Response", "application/json", Schemas.UsersResponse)
}
}
end
+
def index(conn, _params) do
users = Accounts.list_users()
render(conn, "index.json", users: users)
end
def create_operation() do
%Operation{
tags: ["users"],
summary: "Create user",
description: "Create a user",
operationId: "UserController.create",
parameters: [
Operation.parameter(:group_id, :path, :integer, "Group ID", example: 1)
],
- requestBody: request_body("The user attributes", "application/json", Schemas.UserRequest, required: true),
+ requestBody:
+ request_body("The user attributes", "application/json", Schemas.UserRequest,
+ required: true
+ ),
responses: %{
201 => response("User", "application/json", Schemas.UserResponse)
}
}
end
- def create(conn, %Schemas.UserRequest{user: user_params}) do
+
+ def create(conn = %{body_params: %Schemas.UserRequest{user: user_params}}, %{group_id: group_id}) do
with {:ok, %User{} = user} <- Accounts.create_user(user_params) do
conn
|> put_status(:created)
|> put_resp_header("location", user_path(conn, :show, user))
|> render("show.json", user: user)
end
end
@doc """
API Spec for :show action
"""
def show_operation() do
%Operation{
tags: ["users"],
summary: "Show user",
description: "Show a user by ID",
operationId: "UserController.show",
parameters: [
parameter(:id, :path, :integer, "User ID", example: 123, minimum: 1)
],
responses: %{
200 => response("User", "application/json", Schemas.UserResponse)
}
}
end
+
def show(conn, %{id: id}) do
user = Accounts.get_user!(id)
render(conn, "show.json", user: user)
end
end
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sun, Dec 1, 11:32 AM (1 d, 11 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
41672
Default Alt Text
(2 KB)
Attached To
Mode
R22 open_api_spex
Attached
Detach File
Event Timeline
Log In to Comment