Skip to content
Draft
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 @@ -17,7 +17,8 @@
"format": "biome format . && prettier --check \"**/*.{md,yml,yaml}\"",
"format:fix": "biome format --write . && prettier --write \"**/*.{md,yml,yaml}\"",
"clean": "rimraf dist",
"build": "yarn clean && tsc && tsup",
"fetch-api-endpoints": "tsx scripts/fetch-api-endpoints.ts",
"build": "(yarn fetch-api-endpoints || echo 'Warning: Failed to fetch API endpoints, using existing file') && yarn clean && tsc && tsup",
"build-bundles": "bun run scripts/build-cli-bundles.ts",
"prepack": "yarn insert-cli-metadata && yarn build && yarn update-docs",
"insert-cli-metadata": "tsx scripts/insert-cli-metadata.ts",
Expand Down
52 changes: 52 additions & 0 deletions scripts/fetch-api-endpoints.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* Fetches the Apify OpenAPI spec and extracts a minimal endpoint catalog
* (method, path, summary) for use by the `apify api --list-endpoints` flag.
*/

import { writeFile } from 'node:fs/promises';

const OPENAPI_URL = 'https://docs.apify.com/api/openapi.json';
const OUTPUT_PATH = new URL('../src/commands/api-endpoints.json', import.meta.url);

interface OpenAPISpec {
paths: Record<string, Record<string, { summary?: string }>>;
}

interface Endpoint {
method: string;
path: string;
summary: string;
}

const HTTP_METHODS = new Set(['get', 'post', 'put', 'patch', 'delete']);

console.log(`Fetching OpenAPI spec from ${OPENAPI_URL}...`);

const response = await fetch(OPENAPI_URL);

if (!response.ok) {
throw new Error(`Failed to fetch OpenAPI spec: ${response.status} ${response.statusText}`);
}

const spec = (await response.json()) as OpenAPISpec;

const endpoints: Endpoint[] = [];

for (const [path, methods] of Object.entries(spec.paths)) {
for (const [method, details] of Object.entries(methods)) {
if (HTTP_METHODS.has(method)) {
endpoints.push({
method: method.toUpperCase(),
path,
summary: details.summary || '',
});
}
}
}

// Sort by path, then method
endpoints.sort((a, b) => a.path.localeCompare(b.path) || a.method.localeCompare(b.method));

await writeFile(OUTPUT_PATH, `${JSON.stringify(endpoints, null, '\t')}\n`);

console.log(`Extracted ${endpoints.length} endpoints to ${OUTPUT_PATH.pathname}`);
2 changes: 2 additions & 0 deletions src/commands/_register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { ActorGetValueCommand } from './actor/get-value.js';
import { ActorPushDataCommand } from './actor/push-data.js';
import { ActorSetValueCommand } from './actor/set-value.js';
import { ActorsIndexCommand } from './actors/_index.js';
import { ApiCommand } from './api.js';
import { AuthIndexCommand } from './auth/_index.js';
import { BuildsIndexCommand } from './builds/_index.js';
import { TopLevelCallCommand } from './call.js';
Expand Down Expand Up @@ -49,6 +50,7 @@ export const apifyCommands = [
TelemetryIndexCommand,

// top-level
ApiCommand,
TopLevelCallCommand,
UpgradeCommand,
InstallCommand,
Expand Down
Loading
Loading