Skip to content

Commit b5d1a69

Browse files
committed
microsoft: parse Graph spec with the lean OpenAPI parser to fit the Workers isolate
The full Graph OpenAPI document (37MB, ~16.5k operations) parsed through the bespoke eemeli/yaml `YAML.parse` builds a full CST that peaks ~720MB heap and OOMs the 128MB Cloudflare Workers isolate (measured on a real isolate: HTTP 503, outcome=exceededMemory). Delegate the parse to the OpenAPI SDK's `parse`, which uses js-yaml's `load` and does not inline `$ref`s. It peaks ~315MB heap and returns HTTP 200 in-band on the same isolate. `parse` already validates an OpenAPI 3.x object, so the redundant object/version checks are dropped. `YAML.stringify` is retained for emitting the small filtered preset spec, which never touches the 37MB document.
1 parent 5f08d68 commit b5d1a69

1 file changed

Lines changed: 13 additions & 17 deletions

File tree

  • packages/plugins/microsoft/src/sdk

packages/plugins/microsoft/src/sdk/graph.ts

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { AuthTemplateSlug } from "@executor-js/sdk/core";
77
import {
88
AuthenticationSchema,
99
OpenApiParseError,
10+
parse as parseOpenApiDocument,
1011
type Authentication,
1112
type OpenApiIntegrationConfig,
1213
type ParsedDocument,
@@ -538,26 +539,21 @@ export const fetchMicrosoftGraphPermissionsReference = Effect.fn(
538539
const parseMicrosoftGraphOpenApiDocument = (
539540
specText: string,
540541
): Effect.Effect<MicrosoftGraphOpenApiDocument, OpenApiParseError> =>
541-
Effect.gen(function* () {
542-
const parsed = yield* Effect.try({
543-
try: () => YAML.parse(specText) as unknown,
544-
catch: () =>
542+
// Delegate to the OpenAPI SDK's lean js-yaml parser. The bespoke eemeli/yaml
543+
// `YAML.parse` this replaced built a full CST that peaks ~720MB heap on the
544+
// 37MB Graph spec and OOMs the 128MB Cloudflare Workers isolate (measured:
545+
// HTTP 503, outcome=exceededMemory). The SDK parser peaks ~315MB and runs
546+
// in-band on Workers. `parse` already validates an OpenAPI 3.x object and
547+
// does not inline `$ref`s, so peak memory stays bounded for big specs.
548+
parseOpenApiDocument(specText).pipe(
549+
Effect.mapError(
550+
() =>
545551
new OpenApiParseError({
546552
message: "Failed to parse Microsoft Graph OpenAPI document",
547553
}),
548-
});
549-
if (!isRecord(parsed)) {
550-
return yield* new OpenApiParseError({
551-
message: "Microsoft Graph OpenAPI document must be an object",
552-
});
553-
}
554-
if (typeof parsed.openapi !== "string" || !parsed.openapi.startsWith("3.")) {
555-
return yield* new OpenApiParseError({
556-
message: "Microsoft Graph OpenAPI document must be OpenAPI 3.x",
557-
});
558-
}
559-
return parsed as MicrosoftGraphOpenApiDocument;
560-
});
554+
),
555+
Effect.map((doc) => doc as MicrosoftGraphOpenApiDocument),
556+
);
561557

562558
export const buildFilteredMicrosoftGraphOpenApiSpecFromDocument = (
563559
parsed: MicrosoftGraphOpenApiDocument,

0 commit comments

Comments
 (0)