Skip to content

Latest commit

 

History

History
307 lines (226 loc) · 10.1 KB

code-generation-external-apis.md

File metadata and controls

307 lines (226 loc) · 10.1 KB

Code Generation - External APIs

const codeGenerationExternalApisController = new CodeGenerationExternalApisController(client);

Class Name

CodeGenerationExternalApisController

Methods

Generate SDK Via File

Generate an SDK for an API by by uploading the API specification file.

This endpoint generates and then uploads the generated SDK to APIMatic's cloud storage. An ID for the generation performed is returned as part of the response.

This endpoint does not import an API into APIMatic.

async generateSDKViaFile(
  file: FileWrapper,
  template: Platforms,
  requestOptions?: RequestOptions
): Promise<ApiResponse<UserCodeGeneration>>

Parameters

Parameter Type Tags Description
file FileWrapper Form, Required The API specification file.
The type of the specification file should be any of the supported formats.
template Platforms Form, Required The structure contains platforms that APIMatic CodeGen can generate SDKs and Docs in.
requestOptions RequestOptions | undefined Optional Pass additional request options.

Response Type

UserCodeGeneration

Example Usage

const contentType = null;
const file = new FileWrapper(fs.createReadStream('dummy_file'));
const template = 'PHP_GENERIC_LIB';
try {
  const { result, ...httpResponse } = await codeGenerationExternalApisController.generateSDKViaFile(file, template);
  // Get more response info...
  // const { statusCode, headers } = httpResponse;
} catch(error) {
  if (error instanceof ApiError) {
    const errors = error.result;
    // const { statusCode, headers } = error;
  }
}

Generate SDK Via URL

Generate an SDK for an API by providing the URL of the API specification file.

This endpoint generates and then uploads the generated SDK to APIMatic's cloud storage. An ID for the generation performed is returned as part of the response.

This endpoint does not import an API into APIMatic.

async generateSDKViaURL(
  body: GenerateSdkViaUrlRequest,
  requestOptions?: RequestOptions
): Promise<ApiResponse<UserCodeGeneration>>

Parameters

Parameter Type Tags Description
body GenerateSdkViaUrlRequest Body, Required Request Body
requestOptions RequestOptions | undefined Optional Pass additional request options.

Response Type

UserCodeGeneration

Example Usage

const contentType = null;
const body: GenerateSdkViaUrlRequest = {
  url: 'http://petstore.swagger.io/v2/swagger.json',
  template: 'CS_NET_STANDARD_LIB',
};

try {
  const { result, ...httpResponse } = await codeGenerationExternalApisController.generateSDKViaURL(body);
  // Get more response info...
  // const { statusCode, headers } = httpResponse;
} catch(error) {
  if (error instanceof ApiError) {
    const errors = error.result;
    // const { statusCode, headers } = error;
  }
}

Download SDK

Download the SDK generated via the Generate SDK endpoints.

async downloadSDK(
  codegenId: string,
  requestOptions?: RequestOptions
): Promise<ApiResponse<NodeJS.ReadableStream | Blob>>

Parameters

Parameter Type Tags Description
codegenId string Template, Required The ID of code generation received in the response of the Generate SDK Via File or Generate SDK Via URL calls.
requestOptions RequestOptions | undefined Optional Pass additional request options.

Response Type

NodeJS.ReadableStream | Blob

Example Usage

const codegenId = 'codegen_id6';
try {
  const { result, ...httpResponse } = await codeGenerationExternalApisController.downloadSDK(codegenId);
  // Get more response info...
  // const { statusCode, headers } = httpResponse;
} catch(error) {
  if (error instanceof ApiError) {
    const errors = error.result;
    // const { statusCode, headers } = error;
  }
}

List All Code Generations

Get a list of all SDK generations performed with external APIs via the Generate SDK endpoints.

async listAllCodeGenerations(
  requestOptions?: RequestOptions
): Promise<ApiResponse<UserCodeGeneration[]>>

Parameters

Parameter Type Tags Description
requestOptions RequestOptions | undefined Optional Pass additional request options.

Response Type

UserCodeGeneration[]

Example Usage

try {
  const { result, ...httpResponse } = await codeGenerationExternalApisController.listAllCodeGenerations();
  // Get more response info...
  // const { statusCode, headers } = httpResponse;
} catch(error) {
  if (error instanceof ApiError) {
    const errors = error.result;
    // const { statusCode, headers } = error;
  }
}

Download Input File

Download the API Specification file used as input for a specific SDK generation performed via the Generate SDK endpoints.

async downloadInputFile(
  codegenId: string,
  requestOptions?: RequestOptions
): Promise<ApiResponse<NodeJS.ReadableStream | Blob>>

Parameters

Parameter Type Tags Description
codegenId string Template, Required The ID of the code generation to download the API specification for. The code generation ID is received in the response of the Generate SDK Via File or Generate SDK Via URL calls
requestOptions RequestOptions | undefined Optional Pass additional request options.

Response Type

NodeJS.ReadableStream | Blob

Example Usage

const codegenId = 'codegen_id6';
try {
  const { result, ...httpResponse } = await codeGenerationExternalApisController.downloadInputFile(codegenId);
  // Get more response info...
  // const { statusCode, headers } = httpResponse;
} catch(error) {
  if (error instanceof ApiError) {
    const errors = error.result;
    // const { statusCode, headers } = error;
  }
}

Get a Code Generation

Get details on an SDK generation performed for an external API via the Generate SDK endpoints.

async getACodeGeneration(
  codegenId: string,
  requestOptions?: RequestOptions
): Promise<ApiResponse<UserCodeGeneration>>

Parameters

Parameter Type Tags Description
codegenId string Template, Required The ID of the code generation to fetch. The code generation ID is received in the response of the Generate SDK Via File or Generate SDK Via URL calls.
requestOptions RequestOptions | undefined Optional Pass additional request options.

Response Type

UserCodeGeneration

Example Usage

const codegenId = 'codegen_id6';
try {
  const { result, ...httpResponse } = await codeGenerationExternalApisController.getACodeGeneration(codegenId);
  // Get more response info...
  // const { statusCode, headers } = httpResponse;
} catch(error) {
  if (error instanceof ApiError) {
    const errors = error.result;
    // const { statusCode, headers } = error;
  }
}

Delete Code Generation 1

Delete an SDK generation performed for an API via the Generate SDK endpoints.

async deleteCodeGeneration1(
  codegenId: string,
  requestOptions?: RequestOptions
): Promise<ApiResponse<void>>

Parameters

Parameter Type Tags Description
codegenId string Template, Required The ID of the code generation to delete. The code generation ID is received in the response of the Generate SDK Via File or Generate SDK Via URL calls.
requestOptions RequestOptions | undefined Optional Pass additional request options.

Response Type

void

Example Usage

const codegenId = 'codegen_id6';
try {
  const { result, ...httpResponse } = await codeGenerationExternalApisController.deleteCodeGeneration1(codegenId);
  // Get more response info...
  // const { statusCode, headers } = httpResponse;
} catch(error) {
  if (error instanceof ApiError) {
    const errors = error.result;
    // const { statusCode, headers } = error;
  }
}