Skip to content

Commit

Permalink
Support YAML remote schema (#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-lee authored Sep 3, 2024
1 parent b2da1a3 commit 5cc376d
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/zudoku/src/lib/oas/parser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,17 @@ const parseSchemaInput = async (
);
}

const schemaText = await response.text();

try {
return (await response.json()) as JSONSchema;
if (schemaText.trim().startsWith("{")) {
return JSON.parse(schemaText) as JSONSchema;
} else {
const yaml = await import("yaml");
return yaml.parse(schemaText) as JSONSchema;
}
} catch (err) {
throw new GraphQLError("Fetched invalid JSON schema", {
throw new GraphQLError("Fetched invalid schema", {
originalError: err,
});
}
Expand Down

0 comments on commit 5cc376d

Please sign in to comment.