1.2.3 • Published 6 years ago

caclwatevertesthj v1.2.3

Weekly downloads
3
License
-
Repository
-
Last release
6 years ago

Getting started

APIMATIC CodeGen as a Service

APIMATIC is an automatic code generator for RESTful APIs. This API exposes the access to its underlying code generation engine. We currently support the following format for API descriptions, API Blueprint, RAML, Google API Discovery, IODocs, WADL, and Swagger. Although most API descriptions can be used, not all API decsriptions are written well-enough for automatic code generation and may fail the code generation process. For this purpose, we have provided a verbose validation API, which can be used to improve your API description.

Looking for a way to convert between API description formats like Swagger and API Blueprint? Try APIMATIC's Transformer API or it's web version at Transformer.

APIMATIC works in two modes i.e., perform operations on pre-configured API descriptions, and perform operations on API descriptions sent on the fly with requests. The later mode of operations has its limitations with respect to the customization of the generated code through our codegen settings.

See this article for more information about customization of the output code.

Working with pre-configured API descriptions

This mode of operation is useful where APIs are stable and therefore can be pre-configured in APIMATIC. You can always update an API description in APIMATIC using the API Editor by clicking on the Edit button. When working with stored API descriptions, pre-configured codegen settings are used that allow customization of the generated output. In order to uniquely identify the API to perform operations on, an API Key is used, which can be retrieved using the API context menu. This API Key is a secret value and therefore operations on pre-configured API descriptions do not require authentication.

See this article on how to get your API Key from APIMATIC.

Working with API descriptions documents

This mode of operation is useful in cases where API descriptions are automatically generated from a process or external source and cannot be pre-configured in APIMATIC. In this case code generation uses the default codegen settings. However, if custom codegen settings are desired you may use the APIMATIC format for generating your API descriptions, which contains nested codegen settings. For getting the full benefit of our advanced features in our code generator, you must either pre-configure your API, or use APIMATIC format for API description.

APIMATIC API Transformer

APIMATIC Transformer allows its users to convert between different API description formats e.g. Swagger, RAML, etc. This enables the user to benefit from a wide range of tools available associated with any format, not just one. The complete list of supported formats of Transformer are:

InputsOutputs
API BlueprintAPI Blueprint
Swagger v.1.2Swagger 1.2
Swagger 2.0 (JSON and YAML)Swagger 2.0 (JSON, YAML)
Open API v.3.0Open API 3.0
WADL 2009 (W3C)WADL 2009 (W3C)
WSDL (W3C)WSDL (W3C)
Google DiscoveryRAML 0.8 - 1.0
RAML 0.8 - 1.0Postman Collection 1.0 - 2.0
I/O Docs - MasheryAPIMATIC Format
HAR 1.2
Postman Collection 1.0 - 2.0
APIMATIC Format
Mashape

How to Build

The generated SDK relies on Node Package Manager (NPM) being available to resolve dependencies. If you don't already have NPM installed, please go ahead and follow instructions to install NPM from here. The SDK also requires Node to be installed. If Node isn't already installed, please install it from here

NPM is installed by default when Node is installed

To check if node and npm have been successfully installed, write the following commands in command prompt:

  • node --version
  • npm -version

Version Check

Now use npm to resolve all dependencies by running the following command in the root directory (of the SDK folder):

npm install

Resolve Dependencies

Resolve Dependencies

This will install all dependencies in the node_modules folder.

Once dependencies are resolved, you will need to move the folder APIMATICCodeGenAndTransformerAPILib in to your node_modules folder.

How to Use

The following section explains how to use the library in a new project.

1. Open Project Folder

Open an IDE/Text Editor for JavaScript like Sublime Text. The basic workflow presented here is also applicable if you prefer using a different editor or IDE.

Click on File and select Open Folder.

Open Folder

Select the folder of your SDK and click on Select Folder to open it up in Sublime Text. The folder will become visible in the bar on the left.

Open Project

2. Creating a Test File

Now right click on the folder name and select the New File option to create a new test file. Save it as index.js Now import the generated NodeJS library using the following lines of code:

var lib = require('lib');

Save changes.

Create new file

Save new file

3. Running The Test File

To run the index.js file, open up the command prompt and navigate to the Path where the SDK folder resides. Type the following command to run the file:

node index.js

Run file

How to Test

These tests use Mocha framework for testing, coupled with Chai for assertions. These dependencies need to be installed for tests to run. Tests can be run in a number of ways:

Method 1 (Run all tests)

  1. Navigate to the root directory of the SDK folder from command prompt.
  2. Type mocha --recursive to run all the tests.

Method 2 (Run all tests)

  1. Navigate to the ../test/Controllers/ directory from command prompt.
  2. Type mocha * to run all the tests.

Method 3 (Run specific controller's tests)

  1. Navigate to the ../test/Controllers/ directory from command prompt.
  2. Type mocha APIMATIC CodeGen and Transformer APIController to run all the tests in that controller file.

To increase mocha's default timeout, you can change the TEST_TIMEOUT parameter's value in TestBootstrap.js.

Run Tests

Initialization

Authentication

In order to setup authentication in the API client, you need the following information.

ParameterDescription
basicAuthUserNameThe username to use with basic authentication
basicAuthPasswordThe password to use with basic authentication

API client can be initialized as following:

const lib = require('lib');

// Configuration parameters and credentials
lib.Configuration.basicAuthUserName = "basicAuthUserName"; // The username to use with basic authentication
lib.Configuration.basicAuthPassword = "basicAuthPassword"; // The password to use with basic authentication

Class Reference

List of Controllers

Class: CodeGenerationController

Get singleton instance

The singleton instance of the CodeGenerationController class can be accessed from the API Client.

var controller = lib.CodeGenerationController;

Method: usingApikeyAsBinary

Convert an API from the user's account using the API's API Integration Key. The response is generated zip file as per selected template.

Note: This endpoint does not require Basic Authentication.

function usingApikeyAsBinary(apikey, template, dl, callback)

Parameters

ParameterTagsDescription
apikeyRequiredThe API Key of the pre-configured API
templateRequiredThe template to use for code generation
dlOptional DefaultValueOptional

Example Usage

    var apikey = 'apikey';
    var template = Object.keys(template)[0];
    var dl = 233;

    TestHelper.getFileContents('url', function(data) {
        controller.usingApikeyAsBinary(apikey, template, dl, function(error, response, context) {

        });
    });

Errors

Error CodeError Description
401Unauthorized: Access is denied due to invalid credentials.
412Precondition Failed

Method: usingApikeyAsString

The code generation endpoint. The response is a path to the generated zip file relative to https://apimatic.io/

Note: This endpoint does not require Basic Authentication.

function usingApikeyAsString(apikey, template, dl, callback)

Parameters

ParameterTagsDescription
apikeyRequiredThe API Key of the pre-configured API
templateRequiredThe template to use for code generation
dlOptional DefaultValueOptional

Example Usage

    var apikey = 'apikey';
    var template = Object.keys(template)[0];
    var dl = 233;

    controller.usingApikeyAsString(apikey, template, dl, function(error, response, context) {

    
    });

Errors

Error CodeError Description
401Unauthorized: Access is denied due to invalid credentials.
412Precondition Failed

Method: usingUrlAsBinary

Download API description from the given URL and convert it to the given format. The API description format of the provided file will be detected automatically. The response is generated zip file as per selected template.

function usingUrlAsBinary(template, format, name, descriptionUrl, dl, callback)

Parameters

ParameterTagsDescription
templateRequiredThe template to use for code generation
formatRequiredThe format of the API description to use for code generation
nameRequiredThe name of the API being used for code generation
descriptionUrlRequiredThe absolute public Uri for an API description doucment
dlOptional DefaultValueOptional

Example Usage

    var template = Object.keys(template)[0];
    var format = Object.keys(format)[0];
    var name = 'name';
    var descriptionUrl = 'descriptionUrl';
    var dl = 192;

    TestHelper.getFileContents('url', function(data) {
        controller.usingUrlAsBinary(template, format, name, descriptionUrl, dl, function(error, response, context) {

        });
    });

Errors

Error CodeError Description
401Unauthorized: Access is denied due to invalid credentials.
412Precondition Failed

Method: usingUrlAsString

The code generation endpoint. The response is a path to the generated zip file relative to https://apimatic.io/

function usingUrlAsString(template, format, name, descriptionUrl, dl, callback)

Parameters

ParameterTagsDescription
templateRequiredThe template to use for code generation
formatRequiredThe format of the API description to use for code generation
nameRequiredThe name of the API being used for code generation
descriptionUrlRequiredThe absolute public Uri for an API description doucment
dlOptional DefaultValueOptional

Example Usage

    var template = Object.keys(template)[0];
    var format = Object.keys(format)[0];
    var name = 'name';
    var descriptionUrl = 'descriptionUrl';
    var dl = 192;

    controller.usingUrlAsString(template, format, name, descriptionUrl, dl, function(error, response, context) {

    
    });

Errors

Error CodeError Description
401Unauthorized: Access is denied due to invalid credentials.
412Precondition Failed

Method: usingFileAsBinary

The code generation endpoint! Upload a file and convert it to the given format. The API description format of uploaded file will be detected automatically. The response is generated zip file as per selected template.

function usingFileAsBinary(name, format, template, body, dl, callback)

Parameters

ParameterTagsDescription
nameRequiredThe name of the API being used for code generation
formatRequiredThe format of the API description to use for code generation
templateRequiredThe template to use for code generation
bodyRequiredThe input file to use for code generation
dlOptional DefaultValueOptional

Example Usage

    TestHelper.getFilePath('url', function(data) {
        var name = 'name';
    var format = Object.keys(format)[0];
    var template = Object.keys(template)[0];
    var body = data;
    var dl = 192;

        controller.usingFileAsBinary(name, format, template, body, dl, function(error, response, context) {

        });
    });

Errors

Error CodeError Description
401Unauthorized: Access is denied due to invalid credentials.
412Precondition Failed

Method: usingFileAsString

The code generation endpoint. The response is a path to the generated zip file relative to https://apimatic.io/

function usingFileAsString(name, format, template, body, dl, callback)

Parameters

ParameterTagsDescription
nameRequiredThe name of the API being used for code generation
formatRequiredThe format of the API description to use for code generation
templateRequiredThe template to use for code generation
bodyRequiredThe input file to use for code generation
dlOptional DefaultValueOptional

Example Usage

    TestHelper.getFilePath('url', function(data) {
        var name = 'name';
    var format = Object.keys(format)[0];
    var template = Object.keys(template)[0];
    var body = data;
    var dl = 192;

        controller.usingFileAsString(name, format, template, body, dl, function(error, response, context) {

        });
    });

Errors

Error CodeError Description
401Unauthorized: Access is denied due to invalid credentials.
412Precondition Failed

Back to List of Controllers

Class: APITransformerController

Get singleton instance

The singleton instance of the APITransformerController class can be accessed from the API Client.

var controller = lib.APITransformerController;

Method: convertFileDownloadedFromDescriptionURLToFormat

Download API description from the given URL and convert it to the given format. The API description format of the provided file will be detected automatically. The converted file is returned as the response.

function convertFileDownloadedFromDescriptionURLToFormat(format, descriptionUrl, callback)

Parameters

ParameterTagsDescription
formatRequiredThe API format to convert to
descriptionUrlRequiredThe URL where the API description will be downloaded from

Example Usage

    var format = Object.keys(format_transformer)[0];
    var descriptionUrl = 'descriptionUrl';

    TestHelper.getFileContents('url', function(data) {
        controller.convertFileDownloadedFromDescriptionURLToFormat(format, descriptionUrl, function(error, response, context) {

        });
    });

Errors

Error CodeError Description
400Bad Request

Method: convertUploadedFileToFormat

Upload a file and convert it to the given format. The API description format of the uploaded file will be detected automatically. The converted file is returned as the response.

function convertUploadedFileToFormat(format, file, callback)

Parameters

ParameterTagsDescription
formatRequiredThe API format to convert to
fileRequiredThe input file to convert

Example Usage

    TestHelper.getFilePath('url', function(data) {
        var format = Object.keys(format_transformer)[0];
    var file = data;

        controller.convertUploadedFileToFormat(format, file, function(error, response, context) {

        });
    });

Errors

Error CodeError Description
400Bad Request

Method: convertAnUploadedAPIDescriptionToFormatUsingAPIsApiIntegrationKey

Convert an API from the user's account using the API's Api Integration Key. The converted file is returned as the response.

Note: This endpoint does not require Basic Authentication.

function convertAnUploadedAPIDescriptionToFormatUsingAPIsApiIntegrationKey(format, apikey, callback)

Parameters

ParameterTagsDescription
formatRequiredThe API format to convert to
apikeyRequiredApikey of an already uploaded API Description on APIMATIC

Example Usage

    var format = Object.keys(format_transformer)[0];
    var apikey = 'apikey';

    TestHelper.getFileContents('url', function(data) {
        controller.convertAnUploadedAPIDescriptionToFormatUsingAPIsApiIntegrationKey(format, apikey, function(error, response, context) {

        });
    });

Errors

Error CodeError Description
400Bad Request

Back to List of Controllers

Class: APIDescriptionValidationController

Get singleton instance

The singleton instance of the APIDescriptionValidationController class can be accessed from the API Client.

var controller = lib.APIDescriptionValidationController;

Method: validateAnAPIDescriptionFromUri

This endpoint can be used to validate an API description document on the fly from its public Uri, and see detailed error messages along with any warnings or useful information. This endpoint is useful for API descriptions with relative links e.g., includes (RAML) and paths (swagger).

function validateAnAPIDescriptionFromUri(descriptionUrl, callback)

Parameters

ParameterTagsDescription
descriptionUrlRequiredThe absolute public Uri for an API description doucment

Example Usage

    var descriptionUrl = 'descriptionUrl';

    controller.validateAnAPIDescriptionFromUri(descriptionUrl, function(error, response, context) {

    
    });

Method: validateAPreConfiguredAPIDescription

This endpoint can be used to validate a pre-configured API description and see detailed error messages along with any warnings or useful information.

function validateAPreConfiguredAPIDescription(apikey, callback)

Parameters

ParameterTagsDescription
apikeyRequiredThe API Key of a pre-configured API description from APIMATIC

Example Usage

    var apikey = 'apikey';

    controller.validateAPreConfiguredAPIDescription(apikey, function(error, response, context) {

    
    });

Method: validateAnAPIDescription

This endpoint can be used to validate an API description document on the fly and see detailed error messages along with any warnings or useful information.

function validateAnAPIDescription(body, callback)

Parameters

ParameterTagsDescription
bodyRequiredThe input file to use for validation

Example Usage

    TestHelper.getFilePath('url', function(data) {
        var body = data;

        controller.validateAnAPIDescription(body, function(error, response, context) {

        });
    });

Back to List of Controllers