This is an automated email from the ASF dual-hosted git repository.

rnewson pushed a commit to branch dropwizard-5
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 35b9a9d4f605cf16fd35448f142a04b8b9fb2d4f
Author: Robert Newson <[email protected]>
AuthorDate: Fri Nov 13 16:28:07 2026 +0000

    fetch openapi schema after connecting
---
 src/nouveau/src/nouveau_gun.erl | 32 +++++++++++++++++++++++++++++++-
 1 file changed, 31 insertions(+), 1 deletion(-)

diff --git a/src/nouveau/src/nouveau_gun.erl b/src/nouveau/src/nouveau_gun.erl
index 06aefed84..93bc3b845 100644
--- a/src/nouveau/src/nouveau_gun.erl
+++ b/src/nouveau/src/nouveau_gun.erl
@@ -39,7 +39,8 @@
     enabled,
     url,
     gun_pid,
-    gun_mref
+    gun_mref,
+    openapi
 }).
 
 start_link() ->
@@ -68,10 +69,23 @@ handle_info(restart_config_listener, State) ->
 handle_info(reconfigure, State) ->
     reconfigure(new_state(), State);
 handle_info({gun_up, GunPid, http2}, #state{gun_pid = GunPid} = State) ->
+    Self = self(),
+    spawn_link(fun() ->
+        case sync_request(GunPid, State#state.gun_mref, ~"GET", 
~"/openapi.json", [], ~"") of
+            {ok, {200, _RespHeaders, RespBody}} ->
+                Self ! {openapi_ok, jiffy:decode(RespBody, [return_maps])};
+            {error, Reason} ->
+                Self ! {openapi_error, Reason}
+        end
+    end),
     {noreply, State};
 handle_info({gun_down, GunPid, http2, Reason, KilledStreams}, #state{gun_pid = 
GunPid} = State) ->
     couch_log:warning("Gun down for reason ~p (killed streams: ~p)", [Reason, 
KilledStreams]),
     {noreply, State};
+handle_info({openapi_ok, OpenAPI}, State) ->
+    {noreply, State#state{openapi = OpenAPI}};
+handle_info({openapi_error, Reason}, State) ->
+    {stop, {error, Reason}, State};
 handle_info(Msg, State) ->
     couch_log:warning("~p received unexpected message: ~p", [?MODULE, Msg]),
     {noreply, State}.
@@ -191,3 +205,19 @@ verify(false) ->
     verify_none;
 verify(true) ->
     verify_peer.
+
+sync_request(GunPid, GunMRef, Method, Path, ReqHeaders, ReqBody) ->
+    StreamRef = gun:request(GunPid, Method, Path, ReqHeaders, ReqBody),
+    case gun:await(GunPid, StreamRef, GunMRef) of
+        {response, fin, Status, RespHeaders} ->
+            {ok, {Status, RespHeaders}};
+        {response, nofin, Status, RespHeaders} ->
+            case gun:await_body(GunPid, StreamRef, GunMRef) of
+                {ok, RespBody} ->
+                    {ok, {Status, RespHeaders, RespBody}};
+                {error, Reason} ->
+                    {error, Reason}
+            end;
+        {error, Reason} ->
+            {error, Reason}
+    end.

Reply via email to