/**
* Apimatic APILib
*
* This file was automatically generated by APIMATIC v3.0 ( https://www.apimatic.io ).
*/
import { ApiResponse, FileWrapper, RequestOptions } from '../core.js';
import { Accept, acceptSchema } from '../models/accept.js';
import { Accept2, accept2Schema } from '../models/accept2.js';
import { ApiEntity, apiEntitySchema } from '../models/apiEntity.js';
import { ContentType, contentTypeSchema } from '../models/contentType.js';
import { ExportFormats, exportFormatsSchema } from '../models/exportFormats.js';
import {
ImportApiVersionViaUrlRequest,
importApiVersionViaUrlRequestSchema,
} from '../models/importApiVersionViaUrlRequest.js';
import {
ImportApiViaUrlRequest,
importApiViaUrlRequestSchema,
} from '../models/importApiViaUrlRequest.js';
import {
InplaceImportApiViaUrlRequest,
inplaceImportApiViaUrlRequestSchema,
} from '../models/inplaceImportApiViaUrlRequest.js';
import { string } from '../schema.js';
import { BaseController } from './baseController.js';
import { ApiError } from '@apimatic/core';
export class ApisManagementController extends BaseController {
/**
* Import an API into the APIMatic Dashboard by uploading the API specification file.
*
* You can also specify [API Metadata](https://docs.apimatic.io/manage-apis/apimatic-metadata) while
* importing the API using this endpoint. When specifying Metadata, the uploaded file will be a zip
* file containing the API specification file and the `APIMATIC-META` json file.
*
* @param contentType
* @param file The API specification file.
The type of the specification file should be
* any of the [supported formats](https://docs.apimatic.io/api-
* transformer/overview-transformer#supported-input-formats).
* @return Response from the API call
*/
async importApiViaFile(
contentType: ContentType,
file: FileWrapper,
requestOptions?: RequestOptions
): Promise> {
const req = this.createRequest('POST', '/api-entities/import-via-file');
const mapped = req.prepareArgs({
contentType: [contentType, contentTypeSchema],
});
req.header('Content-Type', mapped.contentType);
req.formData({ file: file });
req.throwOn(400, ApiError, 'Bad Request');
req.throwOn(412, ApiError, 'Precondition Failed');
req.throwOn(422, ApiError, 'Unprocessable Entity');
req.throwOn(500, ApiError, 'Internal Server Error');
req.authenticate([{ authorization: true }]);
return req.callAsJson(apiEntitySchema, requestOptions);
}
/**
* Import an API into the APIMatic Dashboard by providing the URL of the API specification file.
*
* You can also specify [API Metadata](https://docs.apimatic.io/manage-apis/apimatic-metadata) while
* importing the API using this endpoint. When specifying Metadata, the URL provided will be that of a
* zip file containing the API specification file and the `APIMATIC-META` json file.
*
* @param body Request Body
* @return Response from the API call
*/
async importApiViaUrl(
body: ImportApiViaUrlRequest,
requestOptions?: RequestOptions
): Promise> {
const req = this.createRequest('POST', '/api-entities/import-via-url');
const mapped = req.prepareArgs({
body: [body, importApiViaUrlRequestSchema],
});
req.header(
'Content-Type',
'application/vnd.apimatic.apiEntityUrlImportDto.v1+json'
);
req.json(mapped.body);
req.throwOn(400, ApiError, 'Bad Request');
req.throwOn(412, ApiError, 'Precondition Failed');
req.throwOn(422, ApiError, 'Unprocessable Entity');
req.throwOn(500, ApiError, 'Internal Server Error');
req.authenticate([{ authorization: true }]);
return req.callAsJson(apiEntitySchema, requestOptions);
}
/**
* Import a new version for an API, against an existing API Group, by uploading the API specification
* file.
*
* You can also specify [API Metadata](https://docs.apimatic.io/manage-apis/apimatic-metadata) while
* importing the API version using this endpoint. When specifying Metadata, the uploaded file will be a
* zip file containing the API specification file and the `APIMATIC-META` json file.
*
* @param apiGroupId The ID of the API Group for which to import a new API version.
* @param accept
* @param versionOverride The version number with which the new API version will be imported. This
* version number will override the version specified in the API specification
* file.
APIMatic recommends versioning the API with the [versioning
* scheme](https://docs.apimatic.io/define-apis/basic-settings/#version)
* documented in the docs.
* @param file The API specification file.
The type of the specification file should
* be any of the [supported formats](https://docs.apimatic.io/api-
* transformer/overview-transformer#supported-input-formats).
* @return Response from the API call
*/
async importNewApiVersionViaFile(
apiGroupId: string,
accept: Accept,
versionOverride: string,
file: FileWrapper,
requestOptions?: RequestOptions
): Promise> {
const req = this.createRequest('POST');
const mapped = req.prepareArgs({
apiGroupId: [apiGroupId, string()],
accept: [accept, acceptSchema],
versionOverride: [versionOverride, string()],
});
req.header('Accept', mapped.accept);
req.formData({ version_override: mapped.versionOverride, file: file });
req.appendTemplatePath`/api-groups/${mapped.apiGroupId}/api-entities/import-via-file`;
req.authenticate([{ authorization: true }]);
return req.callAsJson(apiEntitySchema, requestOptions);
}
/**
* Import a new version for an API, against an existing API Group, by providing the URL of the API
* specification file.
*
* You can also specify [API Metadata](https://docs.apimatic.io/manage-apis/apimatic-metadata) while
* importing the API version using this endpoint. When specifying Metadata, the URL provided will be
* that of a zip file containing the API specification file and the `APIMATIC-META` json file.
*
* @param apiGroupId The ID of the API Group for which to import a new API
* version.
* @param accept
* @param body Request Body
* @return Response from the API call
*/
async importNewApiVersionViaUrl(
apiGroupId: string,
accept: Accept,
body: ImportApiVersionViaUrlRequest,
requestOptions?: RequestOptions
): Promise> {
const req = this.createRequest('POST');
const mapped = req.prepareArgs({
apiGroupId: [apiGroupId, string()],
accept: [accept, acceptSchema],
body: [body, importApiVersionViaUrlRequestSchema],
});
req.header('Accept', mapped.accept);
req.header(
'Content-Type',
'application/vnd.apimatic.apiGroupApiEntityUrlImportDto.v1+json'
);
req.json(mapped.body);
req.appendTemplatePath`/api-groups/${mapped.apiGroupId}/api-entities/import-via-url`;
req.authenticate([{ authorization: true }]);
return req.callAsJson(apiEntitySchema, requestOptions);
}
/**
* Replace an API version of an API Group, by uploading the API specification file that will replace
* the current version.
*
* You can also specify [API Metadata](https://docs.apimatic.io/manage-apis/apimatic-metadata) while
* importing the API version using this endpoint. When specifying Metadata, the uploaded file will be a
* zip file containing the API specification file and the `APIMATIC-META` json file.
*
* @param apiEntityId The ID of the API Entity to replace.
* @param accept
* @param file The API specification file.
The type of the specification file should be
* any of the [supported formats](https://docs.apimatic.io/api-
* transformer/overview-transformer#supported-input-formats).
* @return Response from the API call
*/
async inplaceApiImportViaFile(
apiEntityId: string,
accept: Accept2,
file: FileWrapper,
requestOptions?: RequestOptions
): Promise> {
const req = this.createRequest('PUT');
const mapped = req.prepareArgs({
apiEntityId: [apiEntityId, string()],
accept: [accept, accept2Schema],
});
req.header('Accept', mapped.accept);
req.formData({ file: file });
req.appendTemplatePath`/api-entities/${mapped.apiEntityId}/import-via-file`;
req.authenticate([{ authorization: true }]);
return req.call(requestOptions);
}
/**
* Replace an API version of an API Group, by providing the URL of the API specification file that will
* replace the current version.
*
* You can also specify [API Metadata](https://docs.apimatic.io/manage-apis/apimatic-metadata) while
* importing the API version using this endpoint. When specifying Metadata, the URL provided will be
* that of a zip file containing the API specification file and the `APIMATIC-META` json file.
*
* @param apiEntityId The ID of the API Entity to replace.
* @param body Request Body
* @return Response from the API call
*/
async inplaceApiImportViaUrl(
apiEntityId: string,
body: InplaceImportApiViaUrlRequest,
requestOptions?: RequestOptions
): Promise> {
const req = this.createRequest('PUT');
const mapped = req.prepareArgs({
apiEntityId: [apiEntityId, string()],
body: [body, inplaceImportApiViaUrlRequestSchema],
});
req.header(
'Content-Type',
'application/vnd.apimatic.apiEntityUrlImportDto.v1+json'
);
req.json(mapped.body);
req.appendTemplatePath`/api-entities/${mapped.apiEntityId}/import-via-url`;
req.authenticate([{ authorization: true }]);
return req.call(requestOptions);
}
/**
* Fetch an API Entity.
*
* @param apiEntityId The ID of the API Entity to fetch.
* @return Response from the API call
*/
async fetchApiEntity(
apiEntityId: string,
requestOptions?: RequestOptions
): Promise> {
const req = this.createRequest('GET');
const mapped = req.prepareArgs({ apiEntityId: [apiEntityId, string()] });
req.appendTemplatePath`/api-entities/${mapped.apiEntityId}`;
req.authenticate([{ authorization: true }]);
return req.callAsJson(apiEntitySchema, requestOptions);
}
/**
* Download the API Specification file for a an API Version in any of the API Specification formats
* supported by APIMatic.
*
* @param apiEntityId The ID of the API Entity to download.
* @param format The format in which to download the API.
The format can be any of the
* [supported formats](https://docs.apimatic.io/api-transformer/overview-
* transformer#supported-input-formats).
* @return Response from the API call
*/
async downloadApiSpecification(
apiEntityId: string,
format: ExportFormats,
requestOptions?: RequestOptions
): Promise> {
const req = this.createRequest('GET');
const mapped = req.prepareArgs({
apiEntityId: [apiEntityId, string()],
format: [format, exportFormatsSchema],
});
req.query('format', mapped.format);
req.appendTemplatePath`/api-entities/${mapped.apiEntityId}/api-description`;
req.authenticate([{ authorization: true }]);
return req.callAsStream(requestOptions);
}
}