Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F115776
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/lib/open_api_spex/server.ex b/lib/open_api_spex/server.ex
index 471ba34..c0dc47f 100644
--- a/lib/open_api_spex/server.ex
+++ b/lib/open_api_spex/server.ex
@@ -1,35 +1,44 @@
defmodule OpenApiSpex.Server do
@moduledoc """
Defines the `OpenApiSpex.Server.t` type.
"""
alias OpenApiSpex.{Server, ServerVariable}
@enforce_keys :url
defstruct [
:url,
:description,
variables: %{}
]
@typedoc """
[Server Object](https://swagger.io/specification/#serverObject)
An object representing a Server.
"""
@type t :: %Server{
url: String.t,
description: String.t | nil,
variables: %{String.t => ServerVariable.t}
}
+ @doc """
+ Builds a Server from a phoenix Endpoint module
+ """
+ @deprecated "Use from_endpoint/1 instead"
+ @spec from_endpoint(module, ignored :: any()) :: t
+ def from_endpoint(endpoint, _opts) do
+ from_endpoint(endpoint)
+ end
+
@doc """
Builds a Server from a phoenix Endpoint module
"""
@spec from_endpoint(module) :: t
def from_endpoint(endpoint) do
uri = apply(endpoint, :struct_url, [])
%Server{
url: URI.to_string(uri)
}
end
end
diff --git a/test/server_test.exs b/test/server_test.exs
index 832f2cd..d5555d6 100644
--- a/test/server_test.exs
+++ b/test/server_test.exs
@@ -1,27 +1,41 @@
defmodule OpenApiSpex.ServerTest do
use ExUnit.Case
alias OpenApiSpex.{Server}
alias OpenApiSpexTest.Endpoint
+ @otp_app :open_api_spex_test
+
describe "Server" do
- test "from_endpoint" do
- Application.put_env(:open_api_spex_test, Endpoint, [
- url: [
- scheme: "https",
- host: "example.com",
- port: 1234,
- path: "/api/v1/"
- ]
- ])
- Endpoint.start_link()
+ test "from_endpoint/1" do
+ setup_endpoint()
server = Server.from_endpoint(Endpoint)
assert %{
url: "https://example.com:1234/api/v1/"
} = server
end
+
+ test "from_endpoint/2" do
+ setup_endpoint()
+
+ expected = Server.from_endpoint(Endpoint)
+ actual = Server.from_endpoint(Endpoint, [opt_app: @otp_app])
+
+ assert ^expected = actual
+ end
end
+ defp setup_endpoint do
+ Application.put_env(@otp_app, Endpoint, [
+ url: [
+ scheme: "https",
+ host: "example.com",
+ port: 1234,
+ path: "/api/v1/"
+ ]
+ ])
+ Endpoint.start_link()
+ end
end
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Fri, Nov 29, 12:32 AM (1 d, 15 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
41121
Default Alt Text
(2 KB)
Attached To
Mode
R22 open_api_spex
Attached
Detach File
Event Timeline
Log In to Comment