Skip to content
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
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@
"fix": "npm run fix:lint && npm run reformat",
"fix:lint": "eslint . --fix",
"reformat": "prettier --write .",
"generate": "./scripts/generate.sh && npm run generate:arguments",
"generate": "npm run generate:api && npm run generate:arguments",
"generate:api": "./scripts/generate.sh",
"generate:arguments": "tsx scripts/generateArguments.ts",
"test": "vitest --project eslint-rules --project unit-and-integration --coverage",
"pretest:accuracy": "npm run build",
Expand Down
10 changes: 7 additions & 3 deletions scripts/apply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ async function main(): Promise<void> {
path: string;
method: string;
operationId: string;
methodName: string;
requiredParams: boolean;
tag: string;
hasResponseBody: boolean;
Expand All @@ -45,7 +46,9 @@ async function main(): Promise<void> {
for (const path in openapi.paths) {
for (const method in openapi.paths[path]) {
// @ts-expect-error This is a workaround for the OpenAPI types
const operation = openapi.paths[path][method] as OpenAPIV3_1.OperationObject;
const operation = openapi.paths[path][method] as OpenAPIV3_1.OperationObject & {
"x-xgen-operation-id-override": string;
};

if (!operation.operationId || !operation.tags?.length) {
continue;
Expand Down Expand Up @@ -81,6 +84,7 @@ async function main(): Promise<void> {
operations.push({
path,
method: method.toUpperCase(),
methodName: operation["x-xgen-operation-id-override"] || operation.operationId || "",
operationId: operation.operationId || "",
requiredParams,
hasResponseBody,
Expand All @@ -91,9 +95,9 @@ async function main(): Promise<void> {

const operationOutput = operations
.map((operation) => {
const { operationId, method, path, requiredParams, hasResponseBody } = operation;
const { methodName, operationId, method, path, requiredParams, hasResponseBody } = operation;
return `// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
async ${operationId}(options${requiredParams ? "" : "?"}: FetchOptions<operations["${operationId}"]>) {
async ${methodName}(options${requiredParams ? "" : "?"}: FetchOptions<operations["${operationId}"]>) {
const { ${hasResponseBody ? `data, ` : ``}error, response } = await this.client.${method}("${path}", options);
if (error) {
throw ApiClientError.fromError(response, error);
Expand Down
6 changes: 3 additions & 3 deletions scripts/cleanupAtlasTestLeftovers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function isOlderThanTwoHours(date: string): boolean {
}

async function findTestOrganization(client: ApiClient): Promise<AtlasOrganization> {
const orgs = await client.listOrganizations();
const orgs = await client.listOrgs();
const testOrg = orgs?.results?.find((org) => org.name === "MongoDB MCP Test");

if (!testOrg) {
Expand All @@ -23,7 +23,7 @@ async function findTestOrganization(client: ApiClient): Promise<AtlasOrganizatio
}

async function findAllTestProjects(client: ApiClient, orgId: string): Promise<Group[]> {
const projects = await client.listOrganizationProjects({
const projects = await client.getOrgGroups({
params: {
path: {
orgId,
Expand Down Expand Up @@ -101,7 +101,7 @@ async function main(): Promise<void> {

// Try to delete the project
try {
await apiClient.deleteProject({
await apiClient.deleteGroup({
params: {
path: {
groupId: project.id,
Expand Down
37 changes: 22 additions & 15 deletions scripts/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ async function readStdin(): Promise<string> {

function filterOpenapi(openapi: OpenAPIV3_1.Document): OpenAPIV3_1.Document {
const allowedOperations = [
"listProjects",
"listOrganizations",
"getProject",
"createProject",
"deleteProject",
"listGroups",
"listOrgs",
"getGroup",
"createGroup",
"deleteGroup",
"listClusters",
"listFlexClusters",
"getCluster",
Expand All @@ -32,28 +32,35 @@ function filterOpenapi(openapi: OpenAPIV3_1.Document): OpenAPIV3_1.Document {
"createFlexCluster",
"deleteCluster",
"deleteFlexCluster",
"listClustersForAllProjects",
"listClusterDetails",
"createDatabaseUser",
"deleteDatabaseUser",
"listDatabaseUsers",
"listProjectIpAccessLists",
"createProjectIpAccessList",
"deleteProjectIpAccessList",
"listOrganizationProjects",
"listAccessListEntries",
"createAccessListEntry",
"deleteAccessListEntry",
"getOrgGroups",
"listAlerts",
"listDropIndexes",
"listDropIndexSuggestions",
"listClusterSuggestedIndexes",
"listSchemaAdvice",
"listSlowQueries",
"listSlowQueryLogs",
];

const filteredPaths = {};

for (const path in openapi.paths) {
const filteredMethods = {} as OpenAPIV3_1.PathItemObject;
for (const method in openapi.paths[path]) {
// @ts-expect-error This is a workaround for the OpenAPI types
if (allowedOperations.includes((openapi.paths[path][method] as { operationId: string }).operationId)) {
// @ts-expect-error This is a workaround for the OpenAPI types
for (const [method, operation] of Object.entries(openapi.paths[path])) {
const op = operation as OpenAPIV3_1.OperationObject & {
"x-xgen-operation-id-override": string;
};
if (
op.operationId &&
(allowedOperations.includes(op.operationId) ||
allowedOperations.includes(op["x-xgen-operation-id-override"]))
) {
// @ts-expect-error This is a workaround for the OpenAPI types
filteredMethods[method] = openapi.paths[path][method] as OpenAPIV3_1.OperationObject;
}
Expand Down
2 changes: 1 addition & 1 deletion src/common/atlas/accessListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export async function makeCurrentIpAccessListEntry(
export async function ensureCurrentIpInAccessList(apiClient: ApiClient, projectId: string): Promise<boolean> {
const entry = await makeCurrentIpAccessListEntry(apiClient, projectId, DEFAULT_ACCESS_LIST_COMMENT);
try {
await apiClient.createProjectIpAccessList({
await apiClient.createAccessListEntry({
params: { path: { groupId: projectId } },
body: [entry],
});
Expand Down
56 changes: 30 additions & 26 deletions src/common/atlas/apiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ export class ApiClient {

// DO NOT EDIT. This is auto-generated code.
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
async listClustersForAllProjects(options?: FetchOptions<operations["listClustersForAllProjects"]>) {
async listClusterDetails(options?: FetchOptions<operations["listClusterDetails"]>) {
const { data, error, response } = await this.client.GET("/api/atlas/v2/clusters", options);
if (error) {
throw ApiClientError.fromError(response, error);
Expand All @@ -316,7 +316,7 @@ export class ApiClient {
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
async listProjects(options?: FetchOptions<operations["listProjects"]>) {
async listGroups(options?: FetchOptions<operations["listGroups"]>) {
const { data, error, response } = await this.client.GET("/api/atlas/v2/groups", options);
if (error) {
throw ApiClientError.fromError(response, error);
Expand All @@ -325,7 +325,7 @@ export class ApiClient {
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
async createProject(options: FetchOptions<operations["createProject"]>) {
async createGroup(options: FetchOptions<operations["createGroup"]>) {
const { data, error, response } = await this.client.POST("/api/atlas/v2/groups", options);
if (error) {
throw ApiClientError.fromError(response, error);
Expand All @@ -334,15 +334,15 @@ export class ApiClient {
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
async deleteProject(options: FetchOptions<operations["deleteProject"]>) {
async deleteGroup(options: FetchOptions<operations["deleteGroup"]>) {
const { error, response } = await this.client.DELETE("/api/atlas/v2/groups/{groupId}", options);
if (error) {
throw ApiClientError.fromError(response, error);
}
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
async getProject(options: FetchOptions<operations["getProject"]>) {
async getGroup(options: FetchOptions<operations["getGroup"]>) {
const { data, error, response } = await this.client.GET("/api/atlas/v2/groups/{groupId}", options);
if (error) {
throw ApiClientError.fromError(response, error);
Expand All @@ -351,7 +351,7 @@ export class ApiClient {
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
async listProjectIpAccessLists(options: FetchOptions<operations["listProjectIpAccessLists"]>) {
async listAccessListEntries(options: FetchOptions<operations["listGroupAccessListEntries"]>) {
const { data, error, response } = await this.client.GET("/api/atlas/v2/groups/{groupId}/accessList", options);
if (error) {
throw ApiClientError.fromError(response, error);
Expand All @@ -360,7 +360,7 @@ export class ApiClient {
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
async createProjectIpAccessList(options: FetchOptions<operations["createProjectIpAccessList"]>) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[q] what happened to all these delete ones, are they unused?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm checking

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is to do with x-xgen-operation-id-override

async createAccessListEntry(options: FetchOptions<operations["createGroupAccessListEntry"]>) {
const { data, error, response } = await this.client.POST("/api/atlas/v2/groups/{groupId}/accessList", options);
if (error) {
throw ApiClientError.fromError(response, error);
Expand All @@ -369,7 +369,7 @@ export class ApiClient {
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
async deleteProjectIpAccessList(options: FetchOptions<operations["deleteProjectIpAccessList"]>) {
async deleteAccessListEntry(options: FetchOptions<operations["deleteGroupAccessListEntry"]>) {
const { error, response } = await this.client.DELETE(
"/api/atlas/v2/groups/{groupId}/accessList/{entryValue}",
options
Expand All @@ -380,7 +380,7 @@ export class ApiClient {
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
async listAlerts(options: FetchOptions<operations["listAlerts"]>) {
async listAlerts(options: FetchOptions<operations["listGroupAlerts"]>) {
const { data, error, response } = await this.client.GET("/api/atlas/v2/groups/{groupId}/alerts", options);
if (error) {
throw ApiClientError.fromError(response, error);
Expand All @@ -389,7 +389,7 @@ export class ApiClient {
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
async listClusters(options: FetchOptions<operations["listClusters"]>) {
async listClusters(options: FetchOptions<operations["listGroupClusters"]>) {
const { data, error, response } = await this.client.GET("/api/atlas/v2/groups/{groupId}/clusters", options);
if (error) {
throw ApiClientError.fromError(response, error);
Expand All @@ -398,7 +398,7 @@ export class ApiClient {
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
async createCluster(options: FetchOptions<operations["createCluster"]>) {
async createCluster(options: FetchOptions<operations["createGroupCluster"]>) {
const { data, error, response } = await this.client.POST("/api/atlas/v2/groups/{groupId}/clusters", options);
if (error) {
throw ApiClientError.fromError(response, error);
Expand All @@ -407,7 +407,7 @@ export class ApiClient {
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
async deleteCluster(options: FetchOptions<operations["deleteCluster"]>) {
async deleteCluster(options: FetchOptions<operations["deleteGroupCluster"]>) {
const { error, response } = await this.client.DELETE(
"/api/atlas/v2/groups/{groupId}/clusters/{clusterName}",
options
Expand All @@ -418,7 +418,7 @@ export class ApiClient {
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
async getCluster(options: FetchOptions<operations["getCluster"]>) {
async getCluster(options: FetchOptions<operations["getGroupCluster"]>) {
const { data, error, response } = await this.client.GET(
"/api/atlas/v2/groups/{groupId}/clusters/{clusterName}",
options
Expand All @@ -430,7 +430,9 @@ export class ApiClient {
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
async listDropIndexes(options: FetchOptions<operations["listDropIndexes"]>) {
async listDropIndexSuggestions(
options: FetchOptions<operations["listGroupClusterPerformanceAdvisorDropIndexSuggestions"]>
) {
const { data, error, response } = await this.client.GET(
"/api/atlas/v2/groups/{groupId}/clusters/{clusterName}/performanceAdvisor/dropIndexSuggestions",
options
Expand All @@ -442,7 +444,7 @@ export class ApiClient {
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
async listSchemaAdvice(options: FetchOptions<operations["listSchemaAdvice"]>) {
async listSchemaAdvice(options: FetchOptions<operations["listGroupClusterPerformanceAdvisorSchemaAdvice"]>) {
const { data, error, response } = await this.client.GET(
"/api/atlas/v2/groups/{groupId}/clusters/{clusterName}/performanceAdvisor/schemaAdvice",
options
Expand All @@ -454,7 +456,9 @@ export class ApiClient {
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
async listClusterSuggestedIndexes(options: FetchOptions<operations["listClusterSuggestedIndexes"]>) {
async listClusterSuggestedIndexes(
options: FetchOptions<operations["listGroupClusterPerformanceAdvisorSuggestedIndexes"]>
) {
const { data, error, response } = await this.client.GET(
"/api/atlas/v2/groups/{groupId}/clusters/{clusterName}/performanceAdvisor/suggestedIndexes",
options
Expand All @@ -466,7 +470,7 @@ export class ApiClient {
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
async listDatabaseUsers(options: FetchOptions<operations["listDatabaseUsers"]>) {
async listDatabaseUsers(options: FetchOptions<operations["listGroupDatabaseUsers"]>) {
const { data, error, response } = await this.client.GET(
"/api/atlas/v2/groups/{groupId}/databaseUsers",
options
Expand All @@ -478,7 +482,7 @@ export class ApiClient {
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
async createDatabaseUser(options: FetchOptions<operations["createDatabaseUser"]>) {
async createDatabaseUser(options: FetchOptions<operations["createGroupDatabaseUser"]>) {
const { data, error, response } = await this.client.POST(
"/api/atlas/v2/groups/{groupId}/databaseUsers",
options
Expand All @@ -490,7 +494,7 @@ export class ApiClient {
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
async deleteDatabaseUser(options: FetchOptions<operations["deleteDatabaseUser"]>) {
async deleteDatabaseUser(options: FetchOptions<operations["deleteGroupDatabaseUser"]>) {
const { error, response } = await this.client.DELETE(
"/api/atlas/v2/groups/{groupId}/databaseUsers/{databaseName}/{username}",
options
Expand All @@ -501,7 +505,7 @@ export class ApiClient {
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
async listFlexClusters(options: FetchOptions<operations["listFlexClusters"]>) {
async listFlexClusters(options: FetchOptions<operations["listGroupFlexClusters"]>) {
const { data, error, response } = await this.client.GET("/api/atlas/v2/groups/{groupId}/flexClusters", options);
if (error) {
throw ApiClientError.fromError(response, error);
Expand All @@ -510,7 +514,7 @@ export class ApiClient {
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
async createFlexCluster(options: FetchOptions<operations["createFlexCluster"]>) {
async createFlexCluster(options: FetchOptions<operations["createGroupFlexCluster"]>) {
const { data, error, response } = await this.client.POST(
"/api/atlas/v2/groups/{groupId}/flexClusters",
options
Expand All @@ -522,7 +526,7 @@ export class ApiClient {
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
async deleteFlexCluster(options: FetchOptions<operations["deleteFlexCluster"]>) {
async deleteFlexCluster(options: FetchOptions<operations["deleteGroupFlexCluster"]>) {
const { error, response } = await this.client.DELETE(
"/api/atlas/v2/groups/{groupId}/flexClusters/{name}",
options
Expand All @@ -533,7 +537,7 @@ export class ApiClient {
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
async getFlexCluster(options: FetchOptions<operations["getFlexCluster"]>) {
async getFlexCluster(options: FetchOptions<operations["getGroupFlexCluster"]>) {
const { data, error, response } = await this.client.GET(
"/api/atlas/v2/groups/{groupId}/flexClusters/{name}",
options
Expand All @@ -545,7 +549,7 @@ export class ApiClient {
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
async listSlowQueries(options: FetchOptions<operations["listSlowQueries"]>) {
async listSlowQueryLogs(options: FetchOptions<operations["listGroupProcessPerformanceAdvisorSlowQueryLogs"]>) {
const { data, error, response } = await this.client.GET(
"/api/atlas/v2/groups/{groupId}/processes/{processId}/performanceAdvisor/slowQueryLogs",
options
Expand All @@ -557,7 +561,7 @@ export class ApiClient {
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
async listOrganizations(options?: FetchOptions<operations["listOrganizations"]>) {
async listOrgs(options?: FetchOptions<operations["listOrgs"]>) {
const { data, error, response } = await this.client.GET("/api/atlas/v2/orgs", options);
if (error) {
throw ApiClientError.fromError(response, error);
Expand All @@ -566,7 +570,7 @@ export class ApiClient {
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
async listOrganizationProjects(options: FetchOptions<operations["listOrganizationProjects"]>) {
async getOrgGroups(options: FetchOptions<operations["getOrgGroups"]>) {
const { data, error, response } = await this.client.GET("/api/atlas/v2/orgs/{orgId}/groups", options);
if (error) {
throw ApiClientError.fromError(response, error);
Expand Down
Loading
Loading