fix: add fetch resolver to use an url with \$ref

Signed-off-by: David Weber <david.weber@w3tec.ch>
This commit is contained in:
David Weber
2022-04-20 23:35:25 +02:00
parent b9f7ffb162
commit 433a609a15
2 changed files with 21 additions and 1 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-api-docs': patch
---
Updated the rendering of AsyncApi definitions to be able to resolve absolute HTTP $ref references.
@@ -142,6 +142,21 @@ const useStyles = makeStyles((theme: BackstageTheme) => ({
},
}));
const fetchResolver = {
order: 199, // Use 199 as the built-in http resolver is 200
canRead: /^https?:\/\//,
async read(file: any) {
const response = await fetch(file.url);
return response.text();
},
};
const config = {
parserOptions: {
resolve: { fetch: fetchResolver },
},
};
type Props = {
definition: string;
};
@@ -155,7 +170,7 @@ export const AsyncApiDefinition = ({ definition }: Props): JSX.Element => {
return (
<div className={classNames}>
<AsyncApi schema={definition} />
<AsyncApi schema={definition} config={config} />
</div>
);
};