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

Function parseSpecObject

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

Source from the content-addressed store, hash-verified

157
158/** Parse JSON or YAML text into an object without applying OpenAPI version validation. */
159export const parseSpecObject = (text: string): Effect.Effect<OpenAPI.Document, OpenApiParseError> =>
160 Effect.gen(function* () {
161 const trimmed = text.trim();
162 if (trimmed.length === 0) {
163 return yield* new OpenApiParseError({
164 message: "OpenAPI document is empty",
165 });
166 }
167
168 if (trimmed.length > MAX_SPEC_TEXT_CHARS) {
169 return yield* new OpenApiParseError({
170 message: specTooLargeMessage(trimmed.length, MAX_SPEC_TEXT_CHARS),
171 });
172 }
173 if (trimmed.startsWith("{") || trimmed.startsWith("[")) {
174 if (trimmed.length > MAX_JSON_SPEC_CHARS) {
175 return yield* new OpenApiParseError({
176 message: specTooLargeMessage(trimmed.length, MAX_JSON_SPEC_CHARS),
177 });
178 }
179 } else {
180 const lines = countLines(trimmed);
181 if (lines > MAX_YAML_SPEC_LINES) {
182 return yield* new OpenApiParseError({
183 message: specTooDenseMessage(lines),
184 });
185 }
186 }
187
188 const parsed = yield* parseJsonLike(trimmed).pipe(
189 Effect.mapError(
190 () =>
191 new OpenApiParseError({
192 message: "Failed to parse OpenAPI document",
193 }),
194 ),
195 );
196
197 if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
198 return yield* new OpenApiParseError({
199 message: "OpenAPI document must parse to an object",
200 });
201 }
202
203 return parsed as OpenAPI.Document;
204 });
205
206const parseJsonText = Schema.decodeUnknownEffect(Schema.fromJsonString(Schema.Unknown));
207

Callers 2

plugin.tsFile · 0.90
parse.tsFile · 0.85

Calls 4

specTooLargeMessageFunction · 0.85
countLinesFunction · 0.85
specTooDenseMessageFunction · 0.85
parseJsonLikeFunction · 0.70

Tested by

no test coverage detected