ConstraintsServiceApi.ts•13.1 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 { Constraint } from '../models/Constraint';
import { CreateConstraintRequest } from '../models/CreateConstraintRequest';
import { UpdateConstraintRequest } from '../models/UpdateConstraintRequest';
/**
* no description
*/
export class ConstraintsServiceApiRequestFactory extends BaseAPIRequestFactory {
/**
* @param namespaceKey
* @param segmentKey
* @param createConstraintRequest
*/
public async createConstraint(namespaceKey: string, segmentKey: string, createConstraintRequest: CreateConstraintRequest, _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("ConstraintsServiceApi", "createConstraint", "namespaceKey");
}
// verify required parameter 'segmentKey' is not null or undefined
if (segmentKey === null || segmentKey === undefined) {
throw new RequiredError("ConstraintsServiceApi", "createConstraint", "segmentKey");
}
// verify required parameter 'createConstraintRequest' is not null or undefined
if (createConstraintRequest === null || createConstraintRequest === undefined) {
throw new RequiredError("ConstraintsServiceApi", "createConstraint", "createConstraintRequest");
}
// Path Params
const localVarPath = '/api/v1/namespaces/{namespaceKey}/segments/{segmentKey}/constraints'
.replace('{' + 'namespaceKey' + '}', encodeURIComponent(String(namespaceKey)))
.replace('{' + 'segmentKey' + '}', encodeURIComponent(String(segmentKey)));
// 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(createConstraintRequest, "CreateConstraintRequest", ""),
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 segmentKey
* @param id
*/
public async deleteConstraint(namespaceKey: string, segmentKey: 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("ConstraintsServiceApi", "deleteConstraint", "namespaceKey");
}
// verify required parameter 'segmentKey' is not null or undefined
if (segmentKey === null || segmentKey === undefined) {
throw new RequiredError("ConstraintsServiceApi", "deleteConstraint", "segmentKey");
}
// verify required parameter 'id' is not null or undefined
if (id === null || id === undefined) {
throw new RequiredError("ConstraintsServiceApi", "deleteConstraint", "id");
}
// Path Params
const localVarPath = '/api/v1/namespaces/{namespaceKey}/segments/{segmentKey}/constraints/{id}'
.replace('{' + 'namespaceKey' + '}', encodeURIComponent(String(namespaceKey)))
.replace('{' + 'segmentKey' + '}', encodeURIComponent(String(segmentKey)))
.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 segmentKey
* @param id
* @param updateConstraintRequest
*/
public async updateConstraint(namespaceKey: string, segmentKey: string, id: string, updateConstraintRequest: UpdateConstraintRequest, _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("ConstraintsServiceApi", "updateConstraint", "namespaceKey");
}
// verify required parameter 'segmentKey' is not null or undefined
if (segmentKey === null || segmentKey === undefined) {
throw new RequiredError("ConstraintsServiceApi", "updateConstraint", "segmentKey");
}
// verify required parameter 'id' is not null or undefined
if (id === null || id === undefined) {
throw new RequiredError("ConstraintsServiceApi", "updateConstraint", "id");
}
// verify required parameter 'updateConstraintRequest' is not null or undefined
if (updateConstraintRequest === null || updateConstraintRequest === undefined) {
throw new RequiredError("ConstraintsServiceApi", "updateConstraint", "updateConstraintRequest");
}
// Path Params
const localVarPath = '/api/v1/namespaces/{namespaceKey}/segments/{segmentKey}/constraints/{id}'
.replace('{' + 'namespaceKey' + '}', encodeURIComponent(String(namespaceKey)))
.replace('{' + 'segmentKey' + '}', encodeURIComponent(String(segmentKey)))
.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(updateConstraintRequest, "UpdateConstraintRequest", ""),
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 ConstraintsServiceApiResponseProcessor {
/**
* 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 createConstraint
* @throws ApiException if the response code was not in [200, 299]
*/
public async createConstraintWithHttpInfo(response: ResponseContext): Promise<HttpInfo<Constraint >> {
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
if (isCodeInRange("200", response.httpStatusCode)) {
const body: Constraint = ObjectSerializer.deserialize(
ObjectSerializer.parse(await response.body.text(), contentType),
"Constraint", ""
) as Constraint;
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: Constraint = ObjectSerializer.deserialize(
ObjectSerializer.parse(await response.body.text(), contentType),
"Constraint", ""
) as Constraint;
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 deleteConstraint
* @throws ApiException if the response code was not in [200, 299]
*/
public async deleteConstraintWithHttpInfo(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 updateConstraint
* @throws ApiException if the response code was not in [200, 299]
*/
public async updateConstraintWithHttpInfo(response: ResponseContext): Promise<HttpInfo<Constraint >> {
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
if (isCodeInRange("200", response.httpStatusCode)) {
const body: Constraint = ObjectSerializer.deserialize(
ObjectSerializer.parse(await response.body.text(), contentType),
"Constraint", ""
) as Constraint;
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: Constraint = ObjectSerializer.deserialize(
ObjectSerializer.parse(await response.body.text(), contentType),
"Constraint", ""
) as Constraint;
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);
}
}