openapi_ada_91e8ce6e/regtests/client/src/testapi-client.adb

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
--  ------------ EDIT NOTE ------------
--  REST API Validation
--  API to validate
--  This file was generated with openapi-generator.  You can modify it to implement
--  the client.  After you modify this file, you should add the following line
--  to the .openapi-generator-ignore file:
--
--  src/testapi.ads
--
--  Then, you can drop this edit note comment.
--  ------------ EDIT NOTE ------------
with TestAPI.Clients;
with TestAPI.Models;
with Swagger;
with Swagger.Credentials.OAuth;
with Util.Http.Clients.Curl;
with Ada.Text_IO;
with Ada.Command_Line;
with Ada.Calendar.Formatting;
with Ada.Exceptions;
procedure TestAPI.Client is

   use Ada.Text_IO;

   procedure Usage;

   Server : constant Swagger.UString :=
     Swagger.To_UString ("http://localhost:8080/v2");
   Arg_Count : constant Natural := Ada.Command_Line.Argument_Count;
   Arg       : Positive         := 1;

   procedure Usage is
   begin
      Put_Line ("Usage: TestAPI {params}...");
   end Usage;

begin
   if Arg_Count <= 1 then
      Usage;
      return;
   end if;
   Util.Http.Clients.Curl.Register;
   declare
      Command : constant String := Ada.Command_Line.Argument (Arg);
      Item    : constant String := Ada.Command_Line.Argument (Arg + 1);
      Cred    : aliased Swagger.Credentials.OAuth.OAuth2_Credential_Type;
      C       : TestAPI.Clients.Client_Type;
   begin
      C.Set_Server (Server);
      C.Set_Credentials (Cred'Unchecked_Access);
      Arg := Arg + 2;

   exception
      when E : Constraint_Error =>
         Put_Line
           ("Constraint error raised: " &
            Ada.Exceptions.Exception_Message (E));

   end;
end TestAPI.Client;