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

Generating import file for postman #770

Closed
wants to merge 14 commits into from
Prev Previous commit
Next Next commit
chore: fix content type
Signed-off-by: Tokesh <tokesh789@gmail.com>
Tokesh committed Jan 7, 2025
commit 14292d4216677f287c9ccae5b6821245dd417022
28 changes: 6 additions & 22 deletions tools/src/tester/PostmanManager.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import fs from 'fs';

Check failure on line 1 in tools/src/tester/PostmanManager.ts

GitHub Actions / lint

Missing license header

export class PostmanManager {
private readonly collection: any;
private readonly collectionPath: string;

constructor(collectionPath: string = './postman_collection.json') {

Check failure on line 7 in tools/src/tester/PostmanManager.ts

GitHub Actions / lint

Parameter name `collectionPath` must match one of the following formats: snake_case, UPPER_CASE
this.collectionPath = collectionPath;
this.collection = {
info: {
@@ -15,49 +15,33 @@
};
}

addToCollection(

Check failure on line 18 in tools/src/tester/PostmanManager.ts

GitHub Actions / lint

Class Method name `addToCollection` must match one of the following formats: snake_case
url: string | undefined,
method: string,
path: string,
headers: Record<string, any> | undefined,
params: Record<string, any>,
body: any,
contentType: string

Check failure on line 25 in tools/src/tester/PostmanManager.ts

GitHub Actions / lint

Parameter name `contentType` must match one of the following formats: snake_case, UPPER_CASE
): void {
const bodyContent = body
? (() => {
switch (contentType) {
case 'application/json':
return { mode: 'raw', raw: JSON.stringify(body) };
case 'text/plain':
return { mode: 'raw', raw: body.toString() };
case 'application/x-www-form-urlencoded':
return {
mode: 'urlencoded',
urlencoded: Object.entries(body).map(([key, value]) => ({ key, value: value.toString() })),
};
default:
throw new Error(`Unsupported content type: ${contentType}`);
}
})()
: undefined;

const item = {
name: path,
request: {
method,
header: Object.entries(headers || {}).map(([key, value]) => ({ key, value })),

Check failure on line 31 in tools/src/tester/PostmanManager.ts

GitHub Actions / lint

Prefer using nullish coalescing operator (`??`) instead of a logical or (`||`), as it is a safer operator
url: {
raw: `${url}${path}`,
path: path.split('/').filter(Boolean),
query: Object.entries(params).map(([key, value]) => ({ key, value: value.toString() })),
query: Object.entries(params).map(([key, value]) => ({ key, value: value as string })),
},
body: bodyContent,
body: body

Check failure on line 37 in tools/src/tester/PostmanManager.ts

GitHub Actions / lint

Unexpected any value in conditional. An explicit comparison or type cast is required
? { mode: contentType === 'application/json' ? 'raw' : 'formdata', raw: JSON.stringify(body) }
: undefined,
},
};

this.collection.item.push(item);
}
}

saveCollection(): void {
fs.writeFileSync(this.collectionPath, JSON.stringify(this.collection, null, 2));

Unchanged files with check annotations Beta

}
}
getUrl(): string | undefined {

Check failure on line 224 in tools/src/OpenSearchHttpClient.ts

GitHub Actions / lint

Class Method name `getUrl` must match one of the following formats: snake_case
if(this._opts != null && !this._opts.url) return this._opts.url ;

Check failure on line 225 in tools/src/OpenSearchHttpClient.ts

GitHub Actions / lint

Expected space(s) after "if"

Check failure on line 225 in tools/src/OpenSearchHttpClient.ts

GitHub Actions / lint

Unexpected nullable string value in conditional. Please handle the nullish/empty cases explicitly
return DEFAULT_URL;
}
private readonly logger: Logger
private readonly postmanManager: PostmanManager;
constructor (client: OpenSearchHttpClient, logger: Logger, collectionPath: string = './postman_collection.json') {

Check failure on line 28 in tools/src/tester/ChapterReader.ts

GitHub Actions / lint

Parameter name `collectionPath` must match one of the following formats: snake_case, UPPER_CASE
this._client = client
this.logger = logger
this.postmanManager = new PostmanManager(collectionPath);