(text: string)
| 100 | |
| 101 | /** Parse JSON or YAML text into an object without applying OpenAPI version validation. */ |
| 102 | export 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 | |
| 129 | const parseJsonText = Schema.decodeUnknownEffect(Schema.fromJsonString(Schema.Unknown)); |
| 130 |
no test coverage detected