Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aligns request options with configuration revamp #146

Merged
merged 4 commits into from
Apr 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions packages/abstractions/src/requestInformation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,15 @@ export class RequestInformation {
public getRequestOptions() {
return this._requestOptions;
}
public addRequestOptions(...options: RequestOption[]) {
/** Adds the headers for the request. */
public addRequestHeaders(source: Record<string, string> | undefined) {
if (!source) return;
for (const key in source) {
this.headers[key] = source[key];
}
}
/** Adds the request options for the request. */
public addRequestOptions(options: RequestOption[] | undefined) {
if (!options || options.length === 0) return;
options.forEach((option) => {
this._requestOptions[option.getKey()] = option;
Expand Down Expand Up @@ -129,7 +137,10 @@ export class RequestInformation {
* Sets the query string parameters from a raw object.
* @param parameters the parameters.
*/
public setQueryStringParametersFromRawObject = (q: object): void => {
public setQueryStringParametersFromRawObject = (
q: object | undefined
): void => {
if (!q) return;
Object.entries(q).forEach(([k, v]) => {
let key = k;
if ((q as any).getQueryParameter) {
Expand Down
41 changes: 25 additions & 16 deletions packages/abstractions/test/common/requestInformation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,22 @@ const assert = chai.assert;

import { RequestInformation } from "../../src";

class GetQueryParameters
{
select?: string[];
count?: boolean;
filter?: string;
orderby?: string[];
search?: string;
getQueryParameter(originalName:string) : string {
switch(originalName.toLowerCase()) {
case 'select': return '%24select';
case 'count': return '%24count';
case 'filter': return '%24filter';
case 'orderby': return '%24orderby';
case 'search': return '%24search';
default: return originalName;
}
class GetQueryParameters {
select?: string[];
count?: boolean;
filter?: string;
orderby?: string[];
search?: string;
getQueryParameter(originalName: string): string {
switch (originalName.toLowerCase()) {
case 'select': return '%24select';
case 'count': return '%24count';
case 'filter': return '%24filter';
case 'orderby': return '%24orderby';
case 'search': return '%24search';
default: return originalName;
}
}
}

describe("RequestInformation", () => {
Expand All @@ -54,4 +53,14 @@ describe("RequestInformation", () => {
assert.equal(requestInformation.URL,
"http://localhost/me?%24select=id,displayName");
});

it("Adds headers to requestInformation", () => {
const requestInformation = new RequestInformation();
requestInformation.pathParameters["baseurl"] = baseUrl;
requestInformation.urlTemplate = "http://localhost/me{?%24select}";
const headers: Record<string, string> = { ConsistencyLevel: "eventual" };
requestInformation.addRequestHeaders(headers);
assert.isNotEmpty(requestInformation.headers);
assert.equal("eventual", requestInformation.headers["ConsistencyLevel"]);
});
});
22 changes: 11 additions & 11 deletions packages/test/generatedCode/models/microsoft/graph/index.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
export * from './entity'
export * from './outlookItem'
export * from './emailAddress'
export * from './followupFlag'
export * from './itemBody'
export * from './inferenceClassificationOverride'
export * from './message'
export * from './messageRulePredicates'
export * from './messageRuleActions'
export * from './inferenceClassification'
export * from './messageRule'
export * from './mailFolder'
export * from './dateTimeTimeZone'
export * from './inferenceClassificationOverride'
export * from './attachment'
export * from './singleValueLegacyExtendedProperty'
export * from './internetMessageHeader'
export * from './recipient'
export * from './sizeRange'
export * from './inferenceClassification'
export * from './followupFlag'
export * from './multiValueLegacyExtendedProperty'
export * from './mailFolder'
export * from './recipient'
export * from './messageRulePredicates'
export * from './dateTimeTimeZone'
export * from './message'
export * from './itemBody'
export * from './extension'
export * from './messageRule'
export * from './internetMessageHeader'
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import {InferenceClassification} from '../../../models/microsoft/graph/';
import {createInferenceClassificationFromDiscriminatorValue} from '../../../models/microsoft/graph/createInferenceClassificationFromDiscriminatorValue';
import {InferenceClassificationRequestBuilderDeleteRequestConfiguration} from './inferenceClassificationRequestBuilderDeleteRequestConfiguration';
import {InferenceClassificationRequestBuilderGetRequestConfiguration} from './inferenceClassificationRequestBuilderGetRequestConfiguration';
import {InferenceClassificationRequestBuilderPatchRequestConfiguration} from './inferenceClassificationRequestBuilderPatchRequestConfiguration';
import {InferenceClassificationOverrideItemRequestBuilder} from './overrides/item/inferenceClassificationOverrideItemRequestBuilder';
import {OverridesRequestBuilder} from './overrides/overridesRequestBuilder';
import {getPathParameters, HttpMethod, Parsable, ParsableFactory, RequestAdapter, RequestInformation, RequestOption, ResponseHandler} from '@microsoft/kiota-abstractions';
Expand All @@ -24,88 +27,83 @@ export class InferenceClassificationRequestBuilder {
public constructor(pathParameters: Record<string, unknown> | string | undefined, requestAdapter: RequestAdapter) {
if(!pathParameters) throw new Error("pathParameters cannot be undefined");
if(!requestAdapter) throw new Error("requestAdapter cannot be undefined");
this.urlTemplate = "{+baseurl}/users/{user%2Did}/inferenceClassification{?select}";
this.urlTemplate = "{+baseurl}/users/{user%2Did}/inferenceClassification{?%24select}";
const urlTplParams = getPathParameters(pathParameters);
this.pathParameters = urlTplParams;
this.requestAdapter = requestAdapter;
};
/**
* Relevance classification of the user's messages based on explicit designations which override inferred relevance or importance.
* @param headers Request headers
* @param options Request options
* @param requestConfiguration Configuration for the request such as headers, query parameters, and middleware options.
* @returns a RequestInformation
*/
public createDeleteRequestInformation(headers?: Record<string, string> | undefined, options?: RequestOption[] | undefined) : RequestInformation {
public createDeleteRequestInformation(requestConfiguration?: InferenceClassificationRequestBuilderDeleteRequestConfiguration | undefined) : RequestInformation {
const requestInfo = new RequestInformation();
requestInfo.urlTemplate = this.urlTemplate;
requestInfo.pathParameters = this.pathParameters;
requestInfo.httpMethod = HttpMethod.DELETE;
if(headers) requestInfo.headers = headers;
options && requestInfo.addRequestOptions(...options);
if (requestConfiguration) {
requestInfo.addRequestHeaders(requestConfiguration.headers);
requestInfo.addRequestOptions(requestConfiguration.options);
}
return requestInfo;
};
/**
* Relevance classification of the user's messages based on explicit designations which override inferred relevance or importance.
* @param headers Request headers
* @param options Request options
* @param queryParameters Request query parameters
* @param requestConfiguration Configuration for the request such as headers, query parameters, and middleware options.
* @returns a RequestInformation
*/
public createGetRequestInformation(queryParameters?: {
select?: string[]
} | undefined, headers?: Record<string, string> | undefined, options?: RequestOption[] | undefined) : RequestInformation {
public createGetRequestInformation(requestConfiguration?: InferenceClassificationRequestBuilderGetRequestConfiguration | undefined) : RequestInformation {
const requestInfo = new RequestInformation();
requestInfo.urlTemplate = this.urlTemplate;
requestInfo.pathParameters = this.pathParameters;
requestInfo.httpMethod = HttpMethod.GET;
if(headers) requestInfo.headers = headers;
queryParameters && requestInfo.setQueryStringParametersFromRawObject(queryParameters);
options && requestInfo.addRequestOptions(...options);
if (requestConfiguration) {
requestInfo.addRequestHeaders(requestConfiguration.headers);
requestInfo.setQueryStringParametersFromRawObject(requestConfiguration.queryParameters);
requestInfo.addRequestOptions(requestConfiguration.options);
}
return requestInfo;
};
/**
* Relevance classification of the user's messages based on explicit designations which override inferred relevance or importance.
* @param body
* @param headers Request headers
* @param options Request options
* @param requestConfiguration Configuration for the request such as headers, query parameters, and middleware options.
* @returns a RequestInformation
*/
public createPatchRequestInformation(body: InferenceClassification | undefined, headers?: Record<string, string> | undefined, options?: RequestOption[] | undefined) : RequestInformation {
public createPatchRequestInformation(body: InferenceClassification | undefined, requestConfiguration?: InferenceClassificationRequestBuilderPatchRequestConfiguration | undefined) : RequestInformation {
if(!body) throw new Error("body cannot be undefined");
const requestInfo = new RequestInformation();
requestInfo.urlTemplate = this.urlTemplate;
requestInfo.pathParameters = this.pathParameters;
requestInfo.httpMethod = HttpMethod.PATCH;
if(headers) requestInfo.headers = headers;
if (requestConfiguration) {
requestInfo.addRequestHeaders(requestConfiguration.headers);
requestInfo.addRequestOptions(requestConfiguration.options);
}
requestInfo.setContentFromParsable(this.requestAdapter, "application/json", body);
options && requestInfo.addRequestOptions(...options);
return requestInfo;
};
/**
* Relevance classification of the user's messages based on explicit designations which override inferred relevance or importance.
* @param headers Request headers
* @param options Request options
* @param requestConfiguration Configuration for the request such as headers, query parameters, and middleware options.
* @param responseHandler Response handler to use in place of the default response handling provided by the core service
*/
public delete(headers?: Record<string, string> | undefined, options?: RequestOption[] | undefined, responseHandler?: ResponseHandler | undefined) : Promise<void> {
public delete(requestConfiguration?: InferenceClassificationRequestBuilderDeleteRequestConfiguration | undefined, responseHandler?: ResponseHandler | undefined) : Promise<void> {
const requestInfo = this.createDeleteRequestInformation(
headers, options
requestConfiguration
);
return this.requestAdapter?.sendNoResponseContentAsync(requestInfo, responseHandler, undefined) ?? Promise.reject(new Error('http core is null'));
};
/**
* Relevance classification of the user's messages based on explicit designations which override inferred relevance or importance.
* @param headers Request headers
* @param options Request options
* @param queryParameters Request query parameters
* @param requestConfiguration Configuration for the request such as headers, query parameters, and middleware options.
* @param responseHandler Response handler to use in place of the default response handling provided by the core service
* @returns a Promise of InferenceClassification
*/
public get(queryParameters?: {
select?: string[]
} | undefined, headers?: Record<string, string> | undefined, options?: RequestOption[] | undefined, responseHandler?: ResponseHandler | undefined) : Promise<InferenceClassification | undefined> {
public get(requestConfiguration?: InferenceClassificationRequestBuilderGetRequestConfiguration | undefined, responseHandler?: ResponseHandler | undefined) : Promise<InferenceClassification | undefined> {
const requestInfo = this.createGetRequestInformation(
queryParameters, headers, options
requestConfiguration
);
return this.requestAdapter?.sendAsync<InferenceClassification>(requestInfo, createInferenceClassificationFromDiscriminatorValue, responseHandler, undefined) ?? Promise.reject(new Error('http core is null'));
};
Expand All @@ -117,20 +115,19 @@ export class InferenceClassificationRequestBuilder {
public overridesById(id: string) : InferenceClassificationOverrideItemRequestBuilder {
if(!id) throw new Error("id cannot be undefined");
const urlTplParams = getPathParameters(this.pathParameters);
urlTplParams["inferenceClassificationOverride_id"] = id
urlTplParams["inferenceClassificationOverride%2Did"] = id
return new InferenceClassificationOverrideItemRequestBuilder(urlTplParams, this.requestAdapter);
};
/**
* Relevance classification of the user's messages based on explicit designations which override inferred relevance or importance.
* @param body
* @param headers Request headers
* @param options Request options
* @param requestConfiguration Configuration for the request such as headers, query parameters, and middleware options.
* @param responseHandler Response handler to use in place of the default response handling provided by the core service
*/
public patch(body: InferenceClassification | undefined, headers?: Record<string, string> | undefined, options?: RequestOption[] | undefined, responseHandler?: ResponseHandler | undefined) : Promise<void> {
public patch(body: InferenceClassification | undefined, requestConfiguration?: InferenceClassificationRequestBuilderPatchRequestConfiguration | undefined, responseHandler?: ResponseHandler | undefined) : Promise<void> {
if(!body) throw new Error("body cannot be undefined");
const requestInfo = this.createPatchRequestInformation(
body, headers, options
body, requestConfiguration
);
return this.requestAdapter?.sendNoResponseContentAsync(requestInfo, responseHandler, undefined) ?? Promise.reject(new Error('http core is null'));
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import {RequestOption} from '@microsoft/kiota-abstractions';

/** Configuration for the request such as headers, query parameters, and middleware options. */
export class InferenceClassificationRequestBuilderDeleteRequestConfiguration {
/** Request headers */
public headers?: Record<string, string> | undefined;
/** Request options */
public options?: RequestOption[] | undefined;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

/** Relevance classification of the user's messages based on explicit designations which override inferred relevance or importance. */
export class InferenceClassificationRequestBuilderGetQueryParameters {
/** Select properties to be returned */
public select?: string[] | undefined;
/**
* Maps the query parameters names to their encoded names for the URI template parsing.
* @param originalName The original query parameter name in the class.
* @returns a string
*/
public getQueryParameter(originalName: string | undefined) : string {
if(!originalName) throw new Error("originalName cannot be undefined");
switch(originalName) {
case "select": return "%24select";
default: return originalName;
}
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import {InferenceClassificationRequestBuilderGetQueryParameters} from './inferenceClassificationRequestBuilderGetQueryParameters';
import {RequestOption} from '@microsoft/kiota-abstractions';

/** Configuration for the request such as headers, query parameters, and middleware options. */
export class InferenceClassificationRequestBuilderGetRequestConfiguration {
/** Request headers */
public headers?: Record<string, string> | undefined;
/** Request options */
public options?: RequestOption[] | undefined;
/** Request query parameters */
public queryParameters?: InferenceClassificationRequestBuilderGetQueryParameters | undefined;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import {RequestOption} from '@microsoft/kiota-abstractions';

/** Configuration for the request such as headers, query parameters, and middleware options. */
export class InferenceClassificationRequestBuilderPatchRequestConfiguration {
/** Request headers */
public headers?: Record<string, string> | undefined;
/** Request options */
public options?: RequestOption[] | undefined;
}
Loading