Creating an EGL Client Interface from an External File
This topic explains how to generate multiple interfaces from an OpenAPI document (json, yaml or yml file) not currently in your workbench. For more information about the interface concept, refer to the Introduction to Interface parts guide.
Execute the following steps for the creation of the interfaces:
- In the workbench, click FileNewOther.
- In the Other window, select the EGL Client Interface option.
- Select the OpenAPI file required for generating the code, then select the folder you want to use as landing for your OpenAPI document. The use of the folder EGLSource is recommended.
- In the New EGL part window, you will see all the paths available in the OpenAPI document. Select the paths you want to implement in your code and click the Next button.
- The new window has multiple tabs, one for each selected path and one for more options. Each tab has access to multiple functions. Select the options and functions you want to generate in your code and click Finish.
- The file will open, and you will see all the generated code for the functions that you selected in the previous steps. Edit and implement the output code with your logic.
This process will import the OpenAPI document into the workspace and generate an output code
containing all the functions selected in the wizard and the additional information present in
the OpenAPI Document for every specific function. Each path you selected corresponds to an
interface containing the functions for that specific path. Following is an example of the
generated output:
package interfaces;
interface firstInterf{
description = "Description of the first path"
}
function findByTagsFunction(tags string? in){
tags = [ "tag"],
description = "Get an object using a tag",
@GetRest {
uriTemplate = "/random/findByTags?tags={tags}",
requestFormat = JSON,
responses = [
@RestResponse{
statusCode = 200,
description = "successful operation"
responseFormat = XML
}]
}
};
end
interface secondInterf{
description = "Description of the second path"
}
function getObjectById_GET(id int in){
tags = [ "id"],
description = "Returns a single object using an ID",
@GetRest {
uriTemplate = "/object/{id}",
requestFormat = JSON,
responses = [
@RestResponse{
statusCode = 200,
description = "successful operation",
responseFormat = XML,
responseType = Object
}]
}
};
function updateObjectWithForm_POST(id int in, name string? in, status string? in){
tags = [ "id"],
description = "Update an object in the database",
@PostRest {
uriTemplate = "/object/{id}?name={name}&status={status}",
requestFormat = JSON,
responses = [
@RestResponse{
statusCode = 400,
description = "Invalid input",
responseFormat = JSON
}]
}
};
end