Skip to content

Commit

Permalink
Add examples using references for responses
Browse files Browse the repository at this point in the history
  • Loading branch information
mracos committed Apr 7, 2023
1 parent 0ccecab commit a3824e4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
8 changes: 8 additions & 0 deletions examples/phoenix_app/lib/phoenix_app_web/api_spec.ex
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ defmodule PhoenixAppWeb.ApiSpec do
}
}
}
},
schemas: %{
responses: %{
unprocessable_entity: %Response{
description: "Unprocessable Entity",
content: %{"application/json" => %MediaType{schema: %Schema{type: :object}}}
}
}
}
},
security: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ defmodule PhoenixAppWeb.UserController do
use PhoenixAppWeb, :controller
use OpenApiSpex.ControllerSpecs

alias OpenApiSpex.Schema
alias OpenApiSpex.{Schema, Reference}
alias PhoenixApp.{Accounts, Accounts.User}
alias PhoenixAppWeb.Schemas

Expand All @@ -23,6 +23,7 @@ defmodule PhoenixAppWeb.UserController do
description: "List all users",
responses: [
ok: {"User List Response", "application/json", Schemas.UsersResponse}
unprocessable_entity: %Reference{"$ref": "#/components/responses/unprocessable_entity"},
]

def index(conn, _params) do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ defmodule PhoenixAppWeb.UserControllerWithStructSpecs do
"""
use PhoenixAppWeb, :controller
import OpenApiSpex.Operation, only: [parameter: 5, request_body: 4, response: 3]
alias OpenApiSpex.Operation
alias OpenApiSpex.{Operation, Reference}
alias PhoenixApp.{Accounts, Accounts.User}
alias PhoenixAppWeb.Schemas

Expand Down Expand Up @@ -36,6 +36,7 @@ defmodule PhoenixAppWeb.UserControllerWithStructSpecs do
operationId: "UserController.index",
responses: %{
200 => response("User List Response", "application/json", Schemas.UsersResponse)
422 => %Reference{"$ref": "#/components/responses/unprocessable_entity"},
}
}
end
Expand Down

0 comments on commit a3824e4

Please sign in to comment.