Some Simple and Advanced Features of jQuery Datatable

JQuery is a most powerful jquery plugin for creating table listing and adding intractions to them. I am going to share some simple and advanced features of jQuery datatable. Go through with the…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Importing types defined in an OpenAPI specification into Mule ESB

Due to the large base of tooling and community support that OpenAPI offers, you may prefer to make use of the OpenAPI standard to define your contracts instead of RAML. In this blog we will show you how to import the types defined in an OpenAPI definition into Anypoint Studio for development use in MuleESB.

Once your OpenAPI contract has been defined, the first step is to generate a Java client library version of the contract (json) objects. This is easily achieved in the OpenAPI (Swagger) editor by expanding the ‘Generate Client’ dropdown and choosing ‘Java’.

This will result in a zip file containing Java source code of the OpenAPI specification. Save this file and unzip it.

The OpenAPI generated source utilises com.fasterxml.jackson.annotation.JsonProperty whereas Mule currently only supports the older org.codehaus.jackson.annotate.JsonProperty to map to a JSON field or object name via the ‘JsonProperty’ annotation, so run a ‘find and replace’ for this on the extracted source.

In a Linux based command terminal this can be performed as follows:

Since we are only interested in the types which have been generated, we will remove a few references which are not required as follows:

Create the io/swagger/client/model directory hierarchy within the Mule project’s src/main/java directory and copy the modified files in the io/swagger/client/model folder to the Mule project’s src/main/java/io/swagger/client/model directory.

In Mule Anypoint Studio, refresh the src/main/java folder. To utilise these object types in a flow transformer select the transformer within the flow and in the input or output mapping area, either click ‘Define metadata’ (if no existing metadata has been provided), or right click and select ‘Set Metadata’ (if metadata already exists) for a specific payload or variable object. In the concurrent ‘Define Type’ window:

The output of a mapping using this metadata definition will be a Java object in the Mule flow, but is easily transformed into a JSON object via the ‘Object to JSON’ transformer in a Mule flow (where required). This will allow a developer to import an OpenAPI definition in order to accurately and efficiently map from/to the correct structure of a JSON object as well as in other Mule ESB flow development artefacts like a Mule Expression Language dropdown choice.

Add a comment

Related posts:

EQUITY IN EVERYTHING

In the midst of a global crisis that is disproportionately threatening the lives of Black and brown folks, immigrants, and low-wage workers, equity should be a priority for the philanthropic sector…

Injecting Reality into the Roe v. Wade Debate

Before the ink dried on the Supreme Court decision about Roe v. Wade, the hype machines on both sides were already churning out their responses. I was a journalist for 30 years, and I shake my head…

The Story of Squeaky the Giraffe

Nine thousand years ago, there was a vast empire, the likes of which have never been seen, the Fezertine Empire. Cradled between the rivers Abercrombie and Fitch, it was the envy of all the gods and…