Skip to content

Commit

Permalink
Merge pull request #15 from mgrojo/master
Browse files Browse the repository at this point in the history
Add support for Boolean parameters
  • Loading branch information
stcarrez authored Mar 19, 2022
2 parents be8eb48 + ba592a8 commit 70e83f4
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/openapi-clients.adb
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,30 @@ package body OpenAPI.Clients is
end if;
end Add_Param;

-- ------------------------------
-- Add a query parameter.
-- ------------------------------
procedure Add_Param (URI : in out URI_Type;
Name : in String;
Value : in Boolean) is
begin
if Length (URI.Query) > 0 then
Append (URI.Query, "&");
end if;
Append (URI.Query, Name);
Append (URI.Query, "=");
Append (URI.Query, Boolean'Image (Value));
end Add_Param;

procedure Add_Param (URI : in out URI_Type;
Name : in String;
Value : in Nullable_Boolean) is
begin
if not Value.Is_Null then
URI.Add_Param (Name, Value.Value);
end if;
end Add_Param;

-- ------------------------------
-- Add a query parameter.
-- ------------------------------
Expand Down
8 changes: 8 additions & 0 deletions src/openapi-clients.ads
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ package OpenAPI.Clients is
Name : in String;
Value : in Nullable_UString);

-- Add a query parameter.
procedure Add_Param (URI : in out URI_Type;
Name : in String;
Value : in Boolean);
procedure Add_Param (URI : in out URI_Type;
Name : in String;
Value : in Nullable_Boolean);

-- Add a query parameter.
procedure Add_Param (URI : in out URI_Type;
Name : in String;
Expand Down
23 changes: 23 additions & 0 deletions src/server/openapi-servers.adb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,29 @@ package body OpenAPI.Servers is
Value.Is_Null := V'Length = 0;
end Get_Query_Parameter;

-- ------------------------------
-- Get a request parameter from the query as boolean.
-- ------------------------------
procedure Get_Query_Parameter (Req : in Request'Class;
Name : in String;
Value : out Boolean) is
begin
Value := Boolean'Value (Req.Get_Parameter (Name));
end Get_Query_Parameter;

procedure Get_Query_Parameter (Req : in Request'Class;
Name : in String;
Value : out Nullable_Boolean) is
V : constant String := Req.Get_Parameter (Name);
begin
Value.Is_Null := V'Length = 0;
if Value.Is_Null then
Value.Value := False;
else
Value.Value := Boolean'Value (V);
end if;
end Get_Query_Parameter;

-- Get a request parameter from the query string.
procedure Get_Query_Parameter (Req : in Request'Class;
Name : in String;
Expand Down
9 changes: 9 additions & 0 deletions src/server/openapi-servers.ads
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ package OpenAPI.Servers is
Name : in String;
Value : out Nullable_UString_Vectors.Vector);


-- Get a request parameter from the query as boolean.
procedure Get_Query_Parameter (Req : in Request'Class;
Name : in String;
Value : out Boolean);
procedure Get_Query_Parameter (Req : in Request'Class;
Name : in String;
Value : out Nullable_Boolean);

-- Read the request body and get a value object tree.
procedure Read (Req : in Request'Class;
Value : out Value_Type);
Expand Down

0 comments on commit 70e83f4

Please sign in to comment.