VariantsServiceApi.ts•12.8 kB
// TODO: better import syntax?
import {BaseAPIRequestFactory, RequiredError, COLLECTION_FORMATS} from './baseapi';
import {Configuration} from '../configuration';
import {RequestContext, HttpMethod, ResponseContext, HttpFile, HttpInfo} from '../http/http';
import {ObjectSerializer} from '../models/ObjectSerializer';
import {ApiException} from './exception';
import {canConsumeForm, isCodeInRange} from '../util';
import {SecurityAuthentication} from '../auth/auth';
import { CreateVariantRequest } from '../models/CreateVariantRequest';
import { UpdateVariantRequest } from '../models/UpdateVariantRequest';
import { Variant } from '../models/Variant';
/**
* no description
*/
export class VariantsServiceApiRequestFactory extends BaseAPIRequestFactory {
/**
* @param namespaceKey
* @param flagKey
* @param createVariantRequest
*/
public async createVariant(namespaceKey: string, flagKey: string, createVariantRequest: CreateVariantRequest, _options?: Configuration): Promise<RequestContext> {
let _config = _options || this.configuration;
// verify required parameter 'namespaceKey' is not null or undefined
if (namespaceKey === null || namespaceKey === undefined) {
throw new RequiredError("VariantsServiceApi", "createVariant", "namespaceKey");
}
// verify required parameter 'flagKey' is not null or undefined
if (flagKey === null || flagKey === undefined) {
throw new RequiredError("VariantsServiceApi", "createVariant", "flagKey");
}
// verify required parameter 'createVariantRequest' is not null or undefined
if (createVariantRequest === null || createVariantRequest === undefined) {
throw new RequiredError("VariantsServiceApi", "createVariant", "createVariantRequest");
}
// Path Params
const localVarPath = '/api/v1/namespaces/{namespaceKey}/flags/{flagKey}/variants'
.replace('{' + 'namespaceKey' + '}', encodeURIComponent(String(namespaceKey)))
.replace('{' + 'flagKey' + '}', encodeURIComponent(String(flagKey)));
// 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(createVariantRequest, "CreateVariantRequest", ""),
contentType
);
requestContext.setBody(serializedBody);
let authMethod: SecurityAuthentication | undefined;
// Apply auth methods
authMethod = _config.authMethods["bearerAuth"]
if (authMethod?.applySecurityAuthentication) {
await authMethod?.applySecurityAuthentication(requestContext);
}
const defaultAuth: SecurityAuthentication | undefined = _config?.authMethods?.default
if (defaultAuth?.applySecurityAuthentication) {
await defaultAuth?.applySecurityAuthentication(requestContext);
}
return requestContext;
}
/**
* @param namespaceKey
* @param flagKey
* @param id
*/
public async deleteVariant(namespaceKey: string, flagKey: string, id: string, _options?: Configuration): Promise<RequestContext> {
let _config = _options || this.configuration;
// verify required parameter 'namespaceKey' is not null or undefined
if (namespaceKey === null || namespaceKey === undefined) {
throw new RequiredError("VariantsServiceApi", "deleteVariant", "namespaceKey");
}
// verify required parameter 'flagKey' is not null or undefined
if (flagKey === null || flagKey === undefined) {
throw new RequiredError("VariantsServiceApi", "deleteVariant", "flagKey");
}
// verify required parameter 'id' is not null or undefined
if (id === null || id === undefined) {
throw new RequiredError("VariantsServiceApi", "deleteVariant", "id");
}
// Path Params
const localVarPath = '/api/v1/namespaces/{namespaceKey}/flags/{flagKey}/variants/{id}'
.replace('{' + 'namespaceKey' + '}', encodeURIComponent(String(namespaceKey)))
.replace('{' + 'flagKey' + '}', encodeURIComponent(String(flagKey)))
.replace('{' + 'id' + '}', encodeURIComponent(String(id)));
// Make Request Context
const requestContext = _config.baseServer.makeRequestContext(localVarPath, HttpMethod.DELETE);
requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
let authMethod: SecurityAuthentication | undefined;
// Apply auth methods
authMethod = _config.authMethods["bearerAuth"]
if (authMethod?.applySecurityAuthentication) {
await authMethod?.applySecurityAuthentication(requestContext);
}
const defaultAuth: SecurityAuthentication | undefined = _config?.authMethods?.default
if (defaultAuth?.applySecurityAuthentication) {
await defaultAuth?.applySecurityAuthentication(requestContext);
}
return requestContext;
}
/**
* @param namespaceKey
* @param flagKey
* @param id
* @param updateVariantRequest
*/
public async updateVariant(namespaceKey: string, flagKey: string, id: string, updateVariantRequest: UpdateVariantRequest, _options?: Configuration): Promise<RequestContext> {
let _config = _options || this.configuration;
// verify required parameter 'namespaceKey' is not null or undefined
if (namespaceKey === null || namespaceKey === undefined) {
throw new RequiredError("VariantsServiceApi", "updateVariant", "namespaceKey");
}
// verify required parameter 'flagKey' is not null or undefined
if (flagKey === null || flagKey === undefined) {
throw new RequiredError("VariantsServiceApi", "updateVariant", "flagKey");
}
// verify required parameter 'id' is not null or undefined
if (id === null || id === undefined) {
throw new RequiredError("VariantsServiceApi", "updateVariant", "id");
}
// verify required parameter 'updateVariantRequest' is not null or undefined
if (updateVariantRequest === null || updateVariantRequest === undefined) {
throw new RequiredError("VariantsServiceApi", "updateVariant", "updateVariantRequest");
}
// Path Params
const localVarPath = '/api/v1/namespaces/{namespaceKey}/flags/{flagKey}/variants/{id}'
.replace('{' + 'namespaceKey' + '}', encodeURIComponent(String(namespaceKey)))
.replace('{' + 'flagKey' + '}', encodeURIComponent(String(flagKey)))
.replace('{' + 'id' + '}', encodeURIComponent(String(id)));
// Make Request Context
const requestContext = _config.baseServer.makeRequestContext(localVarPath, HttpMethod.PUT);
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(updateVariantRequest, "UpdateVariantRequest", ""),
contentType
);
requestContext.setBody(serializedBody);
let authMethod: SecurityAuthentication | undefined;
// Apply auth methods
authMethod = _config.authMethods["bearerAuth"]
if (authMethod?.applySecurityAuthentication) {
await authMethod?.applySecurityAuthentication(requestContext);
}
const defaultAuth: SecurityAuthentication | undefined = _config?.authMethods?.default
if (defaultAuth?.applySecurityAuthentication) {
await defaultAuth?.applySecurityAuthentication(requestContext);
}
return requestContext;
}
}
export class VariantsServiceApiResponseProcessor {
/**
* 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 createVariant
* @throws ApiException if the response code was not in [200, 299]
*/
public async createVariantWithHttpInfo(response: ResponseContext): Promise<HttpInfo<Variant >> {
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
if (isCodeInRange("200", response.httpStatusCode)) {
const body: Variant = ObjectSerializer.deserialize(
ObjectSerializer.parse(await response.body.text(), contentType),
"Variant", ""
) as Variant;
return new HttpInfo(response.httpStatusCode, response.headers, response.body, body);
}
// Work around for missing responses in specification, e.g. for petstore.yaml
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
const body: Variant = ObjectSerializer.deserialize(
ObjectSerializer.parse(await response.body.text(), contentType),
"Variant", ""
) as Variant;
return new HttpInfo(response.httpStatusCode, response.headers, response.body, body);
}
throw new ApiException<string | Blob | undefined>(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 deleteVariant
* @throws ApiException if the response code was not in [200, 299]
*/
public async deleteVariantWithHttpInfo(response: ResponseContext): Promise<HttpInfo<void >> {
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
if (isCodeInRange("200", response.httpStatusCode)) {
return new HttpInfo(response.httpStatusCode, response.headers, response.body, undefined);
}
// 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 new HttpInfo(response.httpStatusCode, response.headers, response.body, body);
}
throw new ApiException<string | Blob | undefined>(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 updateVariant
* @throws ApiException if the response code was not in [200, 299]
*/
public async updateVariantWithHttpInfo(response: ResponseContext): Promise<HttpInfo<Variant >> {
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
if (isCodeInRange("200", response.httpStatusCode)) {
const body: Variant = ObjectSerializer.deserialize(
ObjectSerializer.parse(await response.body.text(), contentType),
"Variant", ""
) as Variant;
return new HttpInfo(response.httpStatusCode, response.headers, response.body, body);
}
// Work around for missing responses in specification, e.g. for petstore.yaml
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
const body: Variant = ObjectSerializer.deserialize(
ObjectSerializer.parse(await response.body.text(), contentType),
"Variant", ""
) as Variant;
return new HttpInfo(response.httpStatusCode, response.headers, response.body, body);
}
throw new ApiException<string | Blob | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny(), response.headers);
}
}