// TODO: better import syntax? import {BaseAPIRequestFactory, RequiredError} from './baseapi'; import {Configuration} from '../configuration'; import {RequestContext, HttpMethod, ResponseContext, HttpFile} from '../http/http'; import {ObjectSerializer} from '../models/ObjectSerializer'; import {ApiException} from './exception'; import {canConsumeForm, isCodeInRange} from '../util'; import {SecurityAuthentication} from '../auth/auth'; import { CreateAccountRequest } from '../models/CreateAccountRequest'; import { ErrorResponses } from '../models/ErrorResponses'; import { LoginRequest } from '../models/LoginRequest'; import { TokenResponse } from '../models/TokenResponse'; /** * no description */ export class AuthApiRequestFactory extends BaseAPIRequestFactory { /** * User Account Login * Login to an existing user account. * @param loginRequest */ public async accountLogin(loginRequest?: LoginRequest, _options?: Configuration): Promise { let _config = _options || this.configuration; // Path Params const localVarPath = '/auth/login'; // Make Request Context const requestContext = _config.baseServer.makeRequestContext(localVarPath, HttpMethod.POST); requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8") // Body Params const contentType = ObjectSerializer.getPreferredMediaType([ "application/json" ]); requestContext.setHeaderParam("Content-Type", contentType); const serializedBody = ObjectSerializer.stringify( ObjectSerializer.serialize(loginRequest, "LoginRequest", ""), contentType ); requestContext.setBody(serializedBody); const defaultAuth: SecurityAuthentication | undefined = _options?.authMethods?.default || this.configuration?.authMethods?.default if (defaultAuth?.applySecurityAuthentication) { await defaultAuth?.applySecurityAuthentication(requestContext); } return requestContext; } /** * Email address must be unique. After successful registration, an email is sent to verify the account. * Creates a new user account. * @param createAccountRequest */ public async createAccount(createAccountRequest?: CreateAccountRequest, _options?: Configuration): Promise { let _config = _options || this.configuration; // Path Params const localVarPath = '/auth/register'; // Make Request Context const requestContext = _config.baseServer.makeRequestContext(localVarPath, HttpMethod.POST); requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8") // Body Params const contentType = ObjectSerializer.getPreferredMediaType([ "application/json" ]); requestContext.setHeaderParam("Content-Type", contentType); const serializedBody = ObjectSerializer.stringify( ObjectSerializer.serialize(createAccountRequest, "CreateAccountRequest", ""), contentType ); requestContext.setBody(serializedBody); const defaultAuth: SecurityAuthentication | undefined = _options?.authMethods?.default || this.configuration?.authMethods?.default if (defaultAuth?.applySecurityAuthentication) { await defaultAuth?.applySecurityAuthentication(requestContext); } return requestContext; } } export class AuthApiResponseProcessor { /** * Unwraps the actual response sent by the server from the response context and deserializes the response content * to the expected objects * * @params response Response returned by the server for a request to accountLogin * @throws ApiException if the response code was not in [200, 299] */ public async accountLogin(response: ResponseContext): Promise { const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]); if (isCodeInRange("201", response.httpStatusCode)) { const body: TokenResponse = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "TokenResponse", "" ) as TokenResponse; return body; } if (isCodeInRange("0", response.httpStatusCode)) { const body: ErrorResponses = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "ErrorResponses", "" ) as ErrorResponses; throw new ApiException(0, "", body, response.headers); } // Work around for missing responses in specification, e.g. for petstore.yaml if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) { const body: TokenResponse = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "TokenResponse", "" ) as TokenResponse; return body; } throw new ApiException(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny(), response.headers); } /** * Unwraps the actual response sent by the server from the response context and deserializes the response content * to the expected objects * * @params response Response returned by the server for a request to createAccount * @throws ApiException if the response code was not in [200, 299] */ public async createAccount(response: ResponseContext): Promise { const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]); if (isCodeInRange("201", response.httpStatusCode)) { return; } if (isCodeInRange("0", response.httpStatusCode)) { const body: ErrorResponses = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "ErrorResponses", "" ) as ErrorResponses; throw new ApiException(0, "", body, response.headers); } // Work around for missing responses in specification, e.g. for petstore.yaml if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) { const body: void = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "void", "" ) as void; return body; } throw new ApiException(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny(), response.headers); } }