/** * Apimatic APILib * * This file was automatically generated by APIMATIC v3.0 ( https://www.apimatic.io ). */ import { ApiResponse, FileWrapper, RequestOptions } from '../core.js'; import { ContentType, contentTypeSchema } from '../models/contentType.js'; import { SdkGenerationAsyncResponse, sdkGenerationAsyncResponseSchema, } from '../models/sdkGenerationAsyncResponse.js'; import { SdkGenerationStatusResponse, sdkGenerationStatusResponseSchema, } from '../models/sdkGenerationStatusResponse.js'; import { SdkLanguages, sdkLanguagesSchema } from '../models/sdkLanguages.js'; import { StabilityLevelTag, stabilityLevelTagSchema, } from '../models/stabilityLevelTag.js'; import { optional, string } from '../schema.js'; import { BaseController } from './baseController.js'; import { InternalServerErrorResponseError } from '../errors/internalServerErrorResponseError.js'; import { ProblemDetailsError } from '../errors/problemDetailsError.js'; import { UnauthorizedResponseError } from '../errors/unauthorizedResponseError.js'; export class V2SdkGenerationController extends BaseController { /** * Create an async V2 SDK Generation request by providing a Build Input * * @param contentType * @param file The input file to the SDK Generator. Must contain the build * file or a spec folder containing the API Specification. * @param language Languages for which SDKs can be generated. * @param stability The stability level of the generated SDK. * @param xApiMaticCallbackUrl Optional header containing callback url. This url will be * called by the server once the SDK generation completes * @return Response from the API call */ async generateV2SdkViaBuildInputAsync( contentType: ContentType, file: FileWrapper, language: SdkLanguages, stability: StabilityLevelTag, xApiMaticCallbackUrl?: string, requestOptions?: RequestOptions ): Promise> { const req = this.createRequest('POST', '/sdk/v2'); const mapped = req.prepareArgs({ contentType: [contentType, contentTypeSchema], language: [language, sdkLanguagesSchema], stability: [stability, stabilityLevelTagSchema], xApiMaticCallbackUrl: [xApiMaticCallbackUrl, optional(string())], }); req.header('Content-Type', mapped.contentType); req.header('X-APIMatic-CallbackUrl', mapped.xApiMaticCallbackUrl); req.formData({ file: file, language: mapped.language, stability: mapped.stability, }); req.throwOn(400, ProblemDetailsError, 'Bad Request'); req.throwOn(401, UnauthorizedResponseError, 'Unauthorized'); req.throwOn(500, InternalServerErrorResponseError, 'Internal Server Error'); req.authenticate([{ authorization: true }]); return req.callAsJson(sdkGenerationAsyncResponseSchema, requestOptions); } /** * Get the status of a V2 SDK generation request * * @param id * @return Response from the API call */ async getV2SdkGenerationStatus( id: string, requestOptions?: RequestOptions ): Promise> { const req = this.createRequest('GET'); const mapped = req.prepareArgs({ id: [id, string()] }); req.appendTemplatePath`/sdk/v2/${mapped.id}/status`; req.throwOn(400, ProblemDetailsError, 'Bad Request'); req.throwOn(401, UnauthorizedResponseError, 'Unauthorized'); req.throwOn(500, InternalServerErrorResponseError, 'Internal Server Error'); req.authenticate([{ authorization: true }]); return req.callAsJson(sdkGenerationStatusResponseSchema, requestOptions); } /** * Downloads the V2 SDK artifacts. The endpoint returns a zip file containing the generated SDK. * * @param id * @return Response from the API call */ async downloadGeneratedV2Sdk( id: string, requestOptions?: RequestOptions ): Promise> { const req = this.createRequest('GET'); const mapped = req.prepareArgs({ id: [id, string()] }); req.appendTemplatePath`/sdk/v2/${mapped.id}/download`; req.throwOn(400, ProblemDetailsError, 'Bad Request'); req.throwOn(401, UnauthorizedResponseError, 'Unauthorized'); req.throwOn(500, InternalServerErrorResponseError, 'Internal Server Error'); req.authenticate([{ authorization: true }]); return req.callAsStream(requestOptions); } }