NamespacesServiceApi.ts•17.5 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 { CreateNamespaceRequest } from '../models/CreateNamespaceRequest';
import { Namespace } from '../models/Namespace';
import { NamespaceList } from '../models/NamespaceList';
import { UpdateNamespaceRequest } from '../models/UpdateNamespaceRequest';
/**
* no description
*/
export class NamespacesServiceApiRequestFactory extends BaseAPIRequestFactory {
/**
* @param createNamespaceRequest
*/
public async createNamespace(createNamespaceRequest: CreateNamespaceRequest, _options?: Configuration): Promise<RequestContext> {
let _config = _options || this.configuration;
// verify required parameter 'createNamespaceRequest' is not null or undefined
if (createNamespaceRequest === null || createNamespaceRequest === undefined) {
throw new RequiredError("NamespacesServiceApi", "createNamespace", "createNamespaceRequest");
}
// Path Params
const localVarPath = '/api/v1/namespaces';
// 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(createNamespaceRequest, "CreateNamespaceRequest", ""),
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 key
* @param force
*/
public async deleteNamespace(key: string, force?: boolean, _options?: Configuration): Promise<RequestContext> {
let _config = _options || this.configuration;
// verify required parameter 'key' is not null or undefined
if (key === null || key === undefined) {
throw new RequiredError("NamespacesServiceApi", "deleteNamespace", "key");
}
// Path Params
const localVarPath = '/api/v1/namespaces/{key}'
.replace('{' + 'key' + '}', encodeURIComponent(String(key)));
// Make Request Context
const requestContext = _config.baseServer.makeRequestContext(localVarPath, HttpMethod.DELETE);
requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
// Query Params
if (force !== undefined) {
requestContext.setQueryParam("force", ObjectSerializer.serialize(force, "boolean", ""));
}
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 key
* @param reference
*/
public async getNamespace(key: string, reference?: string, _options?: Configuration): Promise<RequestContext> {
let _config = _options || this.configuration;
// verify required parameter 'key' is not null or undefined
if (key === null || key === undefined) {
throw new RequiredError("NamespacesServiceApi", "getNamespace", "key");
}
// Path Params
const localVarPath = '/api/v1/namespaces/{key}'
.replace('{' + 'key' + '}', encodeURIComponent(String(key)));
// Make Request Context
const requestContext = _config.baseServer.makeRequestContext(localVarPath, HttpMethod.GET);
requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
// Query Params
if (reference !== undefined) {
requestContext.setQueryParam("reference", ObjectSerializer.serialize(reference, "string", ""));
}
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 limit
* @param offset
* @param pageToken
* @param reference
*/
public async listNamespaces(limit?: number, offset?: number, pageToken?: string, reference?: string, _options?: Configuration): Promise<RequestContext> {
let _config = _options || this.configuration;
// Path Params
const localVarPath = '/api/v1/namespaces';
// Make Request Context
const requestContext = _config.baseServer.makeRequestContext(localVarPath, HttpMethod.GET);
requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
// Query Params
if (limit !== undefined) {
requestContext.setQueryParam("limit", ObjectSerializer.serialize(limit, "number", "int32"));
}
// Query Params
if (offset !== undefined) {
requestContext.setQueryParam("offset", ObjectSerializer.serialize(offset, "number", "int32"));
}
// Query Params
if (pageToken !== undefined) {
requestContext.setQueryParam("pageToken", ObjectSerializer.serialize(pageToken, "string", ""));
}
// Query Params
if (reference !== undefined) {
requestContext.setQueryParam("reference", ObjectSerializer.serialize(reference, "string", ""));
}
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 key
* @param updateNamespaceRequest
*/
public async updateNamespace(key: string, updateNamespaceRequest: UpdateNamespaceRequest, _options?: Configuration): Promise<RequestContext> {
let _config = _options || this.configuration;
// verify required parameter 'key' is not null or undefined
if (key === null || key === undefined) {
throw new RequiredError("NamespacesServiceApi", "updateNamespace", "key");
}
// verify required parameter 'updateNamespaceRequest' is not null or undefined
if (updateNamespaceRequest === null || updateNamespaceRequest === undefined) {
throw new RequiredError("NamespacesServiceApi", "updateNamespace", "updateNamespaceRequest");
}
// Path Params
const localVarPath = '/api/v1/namespaces/{key}'
.replace('{' + 'key' + '}', encodeURIComponent(String(key)));
// 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(updateNamespaceRequest, "UpdateNamespaceRequest", ""),
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 NamespacesServiceApiResponseProcessor {
/**
* 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 createNamespace
* @throws ApiException if the response code was not in [200, 299]
*/
public async createNamespaceWithHttpInfo(response: ResponseContext): Promise<HttpInfo<Namespace >> {
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
if (isCodeInRange("200", response.httpStatusCode)) {
const body: Namespace = ObjectSerializer.deserialize(
ObjectSerializer.parse(await response.body.text(), contentType),
"Namespace", ""
) as Namespace;
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: Namespace = ObjectSerializer.deserialize(
ObjectSerializer.parse(await response.body.text(), contentType),
"Namespace", ""
) as Namespace;
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 deleteNamespace
* @throws ApiException if the response code was not in [200, 299]
*/
public async deleteNamespaceWithHttpInfo(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 getNamespace
* @throws ApiException if the response code was not in [200, 299]
*/
public async getNamespaceWithHttpInfo(response: ResponseContext): Promise<HttpInfo<Namespace >> {
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
if (isCodeInRange("200", response.httpStatusCode)) {
const body: Namespace = ObjectSerializer.deserialize(
ObjectSerializer.parse(await response.body.text(), contentType),
"Namespace", ""
) as Namespace;
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: Namespace = ObjectSerializer.deserialize(
ObjectSerializer.parse(await response.body.text(), contentType),
"Namespace", ""
) as Namespace;
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 listNamespaces
* @throws ApiException if the response code was not in [200, 299]
*/
public async listNamespacesWithHttpInfo(response: ResponseContext): Promise<HttpInfo<NamespaceList >> {
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
if (isCodeInRange("200", response.httpStatusCode)) {
const body: NamespaceList = ObjectSerializer.deserialize(
ObjectSerializer.parse(await response.body.text(), contentType),
"NamespaceList", ""
) as NamespaceList;
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: NamespaceList = ObjectSerializer.deserialize(
ObjectSerializer.parse(await response.body.text(), contentType),
"NamespaceList", ""
) as NamespaceList;
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 updateNamespace
* @throws ApiException if the response code was not in [200, 299]
*/
public async updateNamespaceWithHttpInfo(response: ResponseContext): Promise<HttpInfo<Namespace >> {
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
if (isCodeInRange("200", response.httpStatusCode)) {
const body: Namespace = ObjectSerializer.deserialize(
ObjectSerializer.parse(await response.body.text(), contentType),
"Namespace", ""
) as Namespace;
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: Namespace = ObjectSerializer.deserialize(
ObjectSerializer.parse(await response.body.text(), contentType),
"Namespace", ""
) as Namespace;
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);
}
}