updated react-openapi
This commit is contained in:
17
react-openapi/src/spec-loader.ts
Normal file
17
react-openapi/src/spec-loader.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import * as yaml from "js-yaml";
|
||||
import type { OpenApiSpec } from "./types";
|
||||
|
||||
export async function loadSpec(url: string): Promise<OpenApiSpec> {
|
||||
const response = await fetch(url);
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to fetch spec: ${response.status} ${response.statusText}`);
|
||||
}
|
||||
const text = await response.text();
|
||||
|
||||
const parsed = yaml.load(text);
|
||||
if (!parsed || typeof parsed !== "object") {
|
||||
throw new Error("Spec is empty or not an object");
|
||||
}
|
||||
|
||||
return parsed as OpenApiSpec;
|
||||
}
|
||||
Reference in New Issue
Block a user