362625bfa9
* Add Ada client petstore samples - Add script to generate Ada client support with swagger-codegen - Add files to build the Ada sample - Add main program to use the generated client samples API and connect to the server to perform some operations * Add some description for the samples * Update the documentation to explain how to build, how to use the generated Ada client code * Add server support for path parameters - Update postProcessOperations to scan each path parameter and emit a x-path-index vendor attribute to tell the index of the path parameter * Add and fix Ada server code package declaration - fix declaration of operations - generate a generic package that must be instantiated with the target server implementation and which provides the skeleton (deserialization and serialization of data) * Implement the Ada server side operations - extract body, query parameters, path parameters - serialize the result - register operations to the server according to the path/routes * Update the code generation to generate server Ada implementation code * Improvement of Ada server support: generate the swagger.json template file * Define toModelName operation to the creation of a model identifier * Add support for server permission generation - collect the security scopes in postProcessAuthMethod() method and make sure these scopes have unique identifiers. Some scopes correspond to URLs but others correspond to pseudo identifiers. * Use the #lambdaAdaComment filter to indent correctly a multi-line description * Fix model generation to support arrays * Update the generated GNAT project file * Refactoring and improvement of server code generation - Change the server generated code to pass a Context_Type object to allow the server implementation to get/set headers in the request/response and control what is put in some responses - Generate the security permissions based on the scopes that have been collected * Server code generation improvement - Fix generation of GNAT project - Generate the intermediate Ada packages if necessary - Generate the server main * Ada server main template * Ada server code improvement - Add support to generate server permission verification - Fix the GNAT project definition - Templates for Ada intermediate packages * Skeleton for the server side implementation * Generate an empty Ada server implementation * Templates for the Ada server implementation * Add a README.md file and a GNAT config.gpr file * New templates to document the generated Ada server * Add server configuration file for the Ada server * Fix the log message in the Ada server to report the correct URI to connect to * Generate the Ada server configuration file * Improvement of Ada code model to support nullable types * Update the Ada server templates * Refactor the Ada code generator - separate the Ada client and Ada server code generators - register the Ada server code generator under the name 'ada-server' keep 'ada' for the client Ada code generator - moved the common Ada code operation supports to the AbstractAdaCodegen * Improvement and cleanup of Ada client and server code - new template for the client main program - fix the GNAT project template for client or server programs - remove unused options to better use the --model-package option * Fix the GNAT project file name to use a lower case name Fix the default GNAT config Fix the headers of intermediate Ada package files * Regenerate the model and client Ada files * Update the Ada client sample to take into account the Nullable types * Regenerate some files with Ada Swagger Codegen * Ignore generation of petstore.gpr |
||
---|---|---|
.. | ||
.swagger-codegen | ||
src | ||
.swagger-codegen-ignore | ||
config.gpr | ||
petstore.gpr | ||
README.md |
Swagger Petstore Ada Client
Overview
This Ada client uses the Petstore API to demonstrate how to use the generator and use the generated Ada code. The following files are generated by Swagger Codegen:
- src/client/samples-petstore-models.ads
- src/client/samples-petstore-models.adb
- src/client/samples-petstore-clients.ads
- src/client/samples-petstore-clients.adb
The 'Models' package contains the definition of types used by the request or response in the API operations. It also provides operations to serialize and deserialize these objects in JSON, XML or form-based data streams.
The 'Clients' package contains the definition of operations provided by the Petstore API.
Requirements.
To build this sample, you must have installed the GNAT Ada compiler as well the following libraries:
- Ada Util (https://github.com/stcarrez/ada-util)
- Swagger Ada (https://github.com/stcarrez/swagger-ada)
- AWS (http://libre.adacore.com/libre/tools/aws/)
Building the petstore client
Build the petstore client by using the following command:
gprbuild -Ppetstore -p
Using the Swagger Ada code
Initialization
The HTTP/REST support is provided by Ada Util and encapsulated by Swagger Ada. If you want to use Curl, you should initialize with the following:
Util.Http.Clients.Curl.Register;
But if you want to use AWS, you will initialize with:
Util.Http.Clients.Web.Register;
After the initialization is done, you will declare a client instance to access the API operations:
C : Samples.Petstore.Clients.Client_Type;
The 'Client_Type' is the generated type that will implement the operations described in the OpenAPI description file.
And you should initialize the server base URI you want to connect to:
C.Set_Server ("http://petstore.swagger.io/v2");
At this stage, you can use the generated operation.
Calling an operation
Let's retrieve some pet information by calling the 'Get_Pet_By_Id' operation. This operation needs an integer as input parameter and returns a 'Pet_Type' object that contains all the pet information. You will first declare the pet instance as follows:
Pet : Samples.Petstore.Models.Pet_Type;
And then call the 'Get_Pet_By_Id' operation:
C.Get_Pet_By_Id (768, Pet);
At this stage, you can access information from the 'Pet' instance:
Ada.Text_IO.Put_Line ("Id : " & Swagger.Long'Image (Pet.Id));
Ada.Text_IO.Put_Line ("Name : " & Swagger.To_String (Pet.Name));
Ada.Text_IO.Put_Line ("Status : " & Swagger.To_String (Pet.Status));