Module:OpenAPI
Contents |
Introduction
This module allows to integrate in Openbravo APIs documented using the OpenAPI specification. It also provides the ability to visualize and interact with those APIs through Swagger-UI.
![]() | This feature is available starting from 3.0PR19Q3. |
![]() | The OpenAPI module is intended for development purposes and therefore it should not be installed on productive environments. |
API Generation
Defining the API
The steps to define an API are:
- Create a yaml file (.yml) file following the OpenAPI specification. See here for a detailed explanation of how to create the file.
- Place that file under a folder named api of your module.
![]() | It is recommended to follow this naming convention to avoid collisions when defining multiple APIs: modulepackage-apiname.yml. |
See an API definition example here.
Setting the Openbravo server
One of the configuration properties of the OpenAPI specification file is the server which provides connectivity information to a target server that allows to interact with the API.
The OpenAPI module makes it possible to configure this property dynamically, so that it is set with the value of the context.url property of the Openbravo.properties file. This way we will be able to interact with the API using the Openbravo server itself. To define this setting in such way, the ${contextURL} placeholder should be used:
...
servers:
- url: ${contextURL}
...
That placeholder will be replaced with the context.url when deploying the API.
Deploying the API
The APIs are deployed at compile time. To deploy them, the following steps should be done:
- Move to the sourcepath/modules/org.openbravo.service.openapi module
- Run ant compile.api
- Go back to the sourcepath folder
- Run ant smartbuild
Visualizing the API
Once the APIs have been deployed, they can be visualized at the following URL:
http(s)://<openbravo_url>/api
A live example is available here.