/** * 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 { GenerateSdkViaUrlRequest, generateSdkViaUrlRequestSchema, } from '../models/generateSdkViaUrlRequest.js'; import { Platforms, platformsSchema } from '../models/platforms.js'; import { UserCodeGeneration, userCodeGenerationSchema, } from '../models/userCodeGeneration.js'; import { array, string } from '../schema.js'; import { BaseController } from './baseController.js'; import { BadRequestResponseSdkError } from '../errors/badRequestResponseSdkError.js'; import { ProblemDetailsError } from '../errors/problemDetailsError.js'; import { UnauthorizedResponseError } from '../errors/unauthorizedResponseError.js'; export class CodeGenerationExternalApisController extends BaseController { /** * 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. * * @param accept Must be set to 'application/json' to ensure JSON response format * @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). * @param template The structure contains platforms that APIMatic CodeGen can generate SDKs and Docs * in. * @return Response from the API call */ async generateSdkViaFile( accept: Accept, file: FileWrapper, template: Platforms, queryParameters?: Record, requestOptions?: RequestOptions ): Promise> { const req = this.createRequest( 'POST', '/code-generations/generate-via-file' ); const mapped = req.prepareArgs({ accept: [accept, acceptSchema], template: [template, platformsSchema], }); req.header('Accept', mapped.accept); req.query(queryParameters); req.formData({ file: file, template: mapped.template }); req.throwOn(400, BadRequestResponseSdkError, 'Bad Request'); req.throwOn(401, UnauthorizedResponseError, 'Unauthorized'); req.throwOn(403, ProblemDetailsError, 'Subscription Issue'); req.authenticate([{ authorization: true }]); return req.callAsJson(userCodeGenerationSchema, requestOptions); } /** * 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. * * @param body Request Body * @return Response from the API call */ async generateSdkViaUrl( body: GenerateSdkViaUrlRequest, requestOptions?: RequestOptions ): Promise> { const req = this.createRequest( 'POST', '/code-generations/generate-via-url' ); const mapped = req.prepareArgs({ body: [body, generateSdkViaUrlRequestSchema], }); req.header( 'Content-Type', 'application/vnd.apimatic.userCodeGenerationDto.v1+json' ); req.json(mapped.body); req.authenticate([{ authorization: true }]); return req.callAsJson(userCodeGenerationSchema, requestOptions); } /** * Download the SDK generated via the Generate SDK endpoints. * * @param codegenId The ID of code generation received in the response of the [Generate SDK Via * File]($e/Code%20Generation%20-%20External%20APIs/Generate%20SDK%20via%20File) or * [Generate SDK Via URL ]($e/Code%20Generation%20- * %20External%20APIs/Generate%20SDK%20via%20URL) calls. * @return Response from the API call */ async downloadSdk( codegenId: string, requestOptions?: RequestOptions ): Promise> { const req = this.createRequest('GET'); const mapped = req.prepareArgs({ codegenId: [codegenId, string()] }); req.appendTemplatePath`/code-generations/${mapped.codegenId}/generated-sdk`; req.authenticate([{ authorization: true }]); return req.callAsStream(requestOptions); } /** * Get a list of all SDK generations performed with external APIs via the Generate SDK endpoints. * * @return Response from the API call */ async listAllCodeGenerations( requestOptions?: RequestOptions ): Promise> { const req = this.createRequest('GET', '/code-generations'); req.authenticate([{ authorization: true }]); return req.callAsJson(array(userCodeGenerationSchema), requestOptions); } /** * Download the API Specification file used as input for a specific SDK generation performed via the * Generate SDK endpoints. * * @param codegenId 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]($e/Code%20Generation%20-%20External%20APIs/Generate%20SDK%20via%20File) or * [Generate SDK Via URL ]($e/Code%20Generation%20- * %20External%20APIs/Generate%20SDK%20via%20URL) calls * @return Response from the API call */ async downloadInputFile( codegenId: string, requestOptions?: RequestOptions ): Promise> { const req = this.createRequest('GET'); const mapped = req.prepareArgs({ codegenId: [codegenId, string()] }); req.appendTemplatePath`/code-generations/${mapped.codegenId}/input-file`; req.authenticate([{ authorization: true }]); return req.callAsStream(requestOptions); } /** * Get details on an SDK generation performed for an external API via the Generate SDK endpoints. * * @param codegenId The ID of the code generation to fetch. The code generation ID is received in the * response of the [Generate SDK Via File]($e/Code%20Generation%20- * %20External%20APIs/Generate%20SDK%20via%20File) or [Generate SDK Via URL * ]($e/Code%20Generation%20-%20External%20APIs/Generate%20SDK%20via%20URL) calls. * @return Response from the API call */ async getACodeGeneration( codegenId: string, requestOptions?: RequestOptions ): Promise> { const req = this.createRequest('GET'); const mapped = req.prepareArgs({ codegenId: [codegenId, string()] }); req.appendTemplatePath`/code-generations/${mapped.codegenId}`; req.authenticate([{ authorization: true }]); return req.callAsJson(userCodeGenerationSchema, requestOptions); } /** * Delete an SDK generation performed for an API via the Generate SDK endpoints. * * @param codegenId The ID of the code generation to delete. The code generation ID is received in the * response of the [Generate SDK Via File]($e/Code%20Generation%20- * %20External%20APIs/Generate%20SDK%20via%20File) or [Generate SDK Via URL * ]($e/Code%20Generation%20-%20External%20APIs/Generate%20SDK%20via%20URL) calls. * @return Response from the API call */ async deleteCodeGenerationForExternalApis( codegenId: string, requestOptions?: RequestOptions ): Promise> { const req = this.createRequest('DELETE'); const mapped = req.prepareArgs({ codegenId: [codegenId, string()] }); req.appendTemplatePath`/code-generations/${mapped.codegenId}`; req.authenticate([{ authorization: true }]); return req.call(requestOptions); } }