Generate an IBM Mobile Foundation adapter from the OpenAPI specification

3 min read

Generate an IBM Mobile Foundation adapter from the OpenAPI specification

By reading the title, if you are wondering how to model an OpenAPI Specification, Read our previous blog post – Modelling OpenAPI – Swagger 2.0 Specification using API Connect for generating OpenAPI specification using API Connect.

In this post, we will see how to generate an IBM Mobile Foundation Adapter from the generated OpenAPI specification from the above blog.

IBM Mobile Foundation Adapter Auto-generation framework can automatically generate Adapters for a back-end system or microservices from its OpenAPI specification. The OpenAPI specification of the microservices can be made available either as a JSON file or yaml file. The adapter generation framework takes the OpenAPI Specification file as input and generates the adapter and downloads, which can be deployed to Mobile Foundation.

Deploy Microservice Connector Adapter

Microservice Connector adapter is an MFP adapter that you need to deploy onto MFP. This adapter provides a UI that can be used to generate the adapter from OpenAPI specification. To deploy Microservice Connector adapter, download it from the ‘Download Center-> Tools’ page of MFP Operation Console. Deploy the downloaded Microservice adapter to MFP. The deployed adapter will be shown under the ‘Extensions’ section in the left pane of MFP Console. Selecting the ‘Microservice Adapter Generator’ will show the page that can be used to auto-generate the adapter.

Generate Adapter from OpenAPI specification

Now we will see how to generate the adapter from the OpenAPI specification generated by following the Modelling OpenAPI – Swagger 2.0 Specification using API Connect blog. Let’s assume that the generated OpenAPI specification is saved in a file called Telecom.yaml. In the Adapter generator page, that we discussed in the previous section, browse and selected the Telecom.Generate Adapter and Deploy yaml file as the input OpenAPI file for which the adapter to be generated. Once the input file is selected, click on the ‘Generate Adapter’ button to automatically generate and download the adapter. The downloaded adapters can be found in the download folder of the browser. To use the adapter in your mobile app, you need to now deploy the adapter. You can use the MFP operation console to deploy the adapter.

Test the generated adapter

The generated adapter can now be tested from the swagger API explorer available from MFP Console.

For the adapter to securely connect to your APIs defined in APIC connect, you need to configure the adapter to use the ApiKey that is generated by the APIC Connect. You can go to the deployed adapter ‘Configuration’ Tab and provide the ApiKey in the ‘Credential: ApiKey’ textbox. Once it’s done you can now test the Adapter

The ‘billing’ API in the adapter is protected by ‘default’ scope. You can create a confidential client called ‘test’ in MFP and authenticate against the ‘test’ client for the defect scope. Once it’s done, you will be able to test the APIs.

Create a Mobile App to test the generated Adapter

Let’s now see how a native Android app makes use to the MFP adapter to call the API exposed in API Connect. To call MFP adapter from your mobile app, you need to download the ‘Android SDK’ from the ‘Download Center-> SDKs’ tab from the MobileFirst Operations Console. You can then add the MobileFirst SDK to your Android Studio Project. Once the SDKs are added to the Android studio project, you can call the adapter invocation API from the Android App. Before starting the app you need to register the app with MFP. You can either use the mfpdev cli or directly register it from the MobileFirst Operation Console. One app is registered with MFP, you can open the app from the device and see the billing statement is being displayed. The call to API Connect goes via the auto-generated adapter in MFP and the result is sent back to the Mobile App.

To summarize, we have seen how to generate MFP adapter from OpenAPI specification generated from API Connect. We have seen how to use the generated adapter in an android app.

Thanks for reading.

If you have any comments reach out to us either at @shinojedakkara

Or @VidyasagarMSC 

Be the first to hear about news, product updates, and innovation from IBM Cloud