Skip to content

Commit

Permalink
Changes for the abstraction libs
Browse files Browse the repository at this point in the history
  • Loading branch information
andrueastman committed Apr 21, 2022
1 parent 4607207 commit 373ff2d
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 33 deletions.
2 changes: 1 addition & 1 deletion packages/abstractions/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@microsoft/kiota-abstractions",
"version": "1.0.0-preview.2",
"version": "1.0.0-preview.3",
"description": "Core abstractions for kiota generated libraries in TypeScript and JavaScript",
"main": "dist/cjs/src/index.js",
"files": [
Expand Down
9 changes: 9 additions & 0 deletions packages/abstractions/src/commonRequestConfiguration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { RequestOption } from "./requestOption";

/** Configuration for the request such as headers, query parameters, and middleware options. */
export class CommonRequestConfiguration {
/** Request headers */
public headers?: Record<string, string> | undefined;
/** Request options */
public options?: RequestOption[] | undefined;
}
1 change: 1 addition & 0 deletions packages/abstractions/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export * from "./apiClientBuilder";
export * from "./apiError";
export * from "./authentication";
export * from "./dateOnly";
export * from "./commonRequestConfiguration";
export * from "./duration";
export * from "./getPathParameters";
export * from "./httpMethod";
Expand Down
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"]);
});
});
26 changes: 13 additions & 13 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 './singleValueLegacyExtendedProperty'
export * from './messageRuleActions'
export * from './inferenceClassification'
export * from './messageRule'
export * from './recipient'
export * from './extension'
export * from './dateTimeTimeZone'
export * from './mailFolder'
export * from './attachment'
export * from './singleValueLegacyExtendedProperty'
export * from './internetMessageHeader'
export * from './followupFlag'
export * from './itemBody'
export * from './messageRulePredicates'
export * from './sizeRange'
export * from './messageRule'
export * from './multiValueLegacyExtendedProperty'
export * from './mailFolder'
export * from './recipient'
export * from './messageRulePredicates'
export * from './dateTimeTimeZone'
export * from './extension'
export * from './inferenceClassificationOverride'
export * from './internetMessageHeader'
export * from './inferenceClassification'
export * from './emailAddress'
2 changes: 1 addition & 1 deletion packages/test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"dependencies": {
"@azure/identity": "2.0.4",
"@microsoft/kiota-abstractions": "1.0.0-preview.2",
"@microsoft/kiota-abstractions": "1.0.0-preview.3",
"@microsoft/kiota-authentication-azure": "1.0.0-preview.1",
"@microsoft/kiota-http-fetchlibrary": "1.0.0-preview.2",
"@microsoft/kiota-serialization-json": "1.0.0-preview.2",
Expand Down

0 comments on commit 373ff2d

Please sign in to comment.