File tree Expand file tree Collapse file tree
test/wanda_web/controllers Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ defmodule WandaWeb.InfoController do
2+ use WandaWeb , :controller
3+ use OpenApiSpex.ControllerSpecs
4+
5+ alias WandaWeb.Schemas.V1.Info
6+
7+ operation :info ,
8+ summary: "Wanda service information." ,
9+ tags: [ "Checks/Operations Platform" ] ,
10+ description:
11+ "This endpoint returns information about this Wanda instance for service discovery purposes, including name and version" ,
12+ security: [ ] ,
13+ responses: [
14+ ok:
15+ { "This response provides service discovery information about the current Wanda instance." ,
16+ "application/json" , Info }
17+ ]
18+
19+ def info ( conn , _ ) do
20+ version = to_string ( Application . spec ( :wanda , :vsn ) )
21+
22+ conn
23+ |> put_status ( 200 )
24+ |> json ( % {
25+ name: "wanda" ,
26+ version: version
27+ } )
28+ end
29+ end
Original file line number Diff line number Diff line change @@ -146,6 +146,7 @@ defmodule WandaWeb.Router do
146146
147147 scope "/api" , WandaWeb do
148148 pipe_through :api
149+ get "/" , InfoController , :info
149150 get "/healthz" , HealthController , :health
150151 get "/readyz" , HealthController , :ready
151152 end
Original file line number Diff line number Diff line change 1+ defmodule WandaWeb.Schemas.V1.Info do
2+ @ moduledoc """
3+ Info response schema.
4+ """
5+
6+ alias OpenApiSpex.Operation
7+ alias OpenApiSpex.Schema
8+
9+ require OpenApiSpex
10+
11+ OpenApiSpex . schema (
12+ % Schema {
13+ title: "InfoV1" ,
14+ description:
15+ "This response provides service discovery information about the current Wanda instance." ,
16+ type: :object ,
17+ example: % {
18+ name: "wanda" ,
19+ version: "2.0.0"
20+ } ,
21+ additionalProperties: false ,
22+ properties: % {
23+ name: % Schema {
24+ description: "The service name." ,
25+ type: :string ,
26+ example: "wanda"
27+ } ,
28+ version: % Schema {
29+ description: "The version of the running Wanda application." ,
30+ type: :string ,
31+ example: "2.0.0"
32+ }
33+ } ,
34+ required: [ :name , :version ]
35+ } ,
36+ struct?: false
37+ )
38+
39+ def response do
40+ Operation . response (
41+ "This response provides service discovery information about the current Wanda instance." ,
42+ "application/json" ,
43+ __MODULE__
44+ )
45+ end
46+ end
Original file line number Diff line number Diff line change 1+ defmodule WandaWeb.InfoControllerTest do
2+ @ moduledoc false
3+
4+ use WandaWeb.ConnCase , async: true
5+
6+ import OpenApiSpex.TestAssertions
7+
8+ alias WandaWeb.Schemas.Unversioned.ApiSpec
9+
10+ setup do
11+ % { api_spec: ApiSpec . spec ( ) }
12+ end
13+
14+ describe "Info" do
15+ test "returns the current Wanda instance information" , % {
16+ conn: conn ,
17+ api_spec: api_spec
18+ } do
19+ response =
20+ conn
21+ |> get ( "/api" )
22+ |> json_response ( 200 )
23+
24+ assert % {
25+ "name" => "wanda" ,
26+ "version" => _
27+ } = response
28+
29+ assert_schema ( response , "InfoV1" , api_spec )
30+ end
31+ end
32+ end
You can’t perform that action at this time.
0 commit comments