MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / parseSpecObject

Function parseSpecObject

packages/plugins/openapi/src/sdk/parse.ts:102–127  ·  view source on GitHub ↗
(text: string)

Source from the content-addressed store, hash-verified

100
101/** Parse JSON or YAML text into an object without applying OpenAPI version validation. */
102export const parseSpecObject = (text: string): Effect.Effect<OpenAPI.Document, OpenApiParseError> =>
103 Effect.gen(function* () {
104 const trimmed = text.trim();
105 if (trimmed.length === 0) {
106 return yield* new OpenApiParseError({
107 message: "OpenAPI document is empty",
108 });
109 }
110
111 const parsed = yield* parseJsonLike(trimmed).pipe(
112 Effect.mapError(
113 () =>
114 new OpenApiParseError({
115 message: "Failed to parse OpenAPI document",
116 }),
117 ),
118 );
119
120 if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
121 return yield* new OpenApiParseError({
122 message: "OpenAPI document must parse to an object",
123 });
124 }
125
126 return parsed as OpenAPI.Document;
127 });
128
129const parseJsonText = Schema.decodeUnknownEffect(Schema.fromJsonString(Schema.Unknown));
130

Callers 2

plugin.tsFile · 0.90
parse.tsFile · 0.85

Calls 1

parseJsonLikeFunction · 0.70

Tested by

no test coverage detected