Merge pull request #10975 from dweber019/fix/api-docs-async-api-url-ref

fix: add fetch resolver to use urls with \$ref
This commit is contained in:
Patrik Oldsberg
2022-04-22 09:44:59 +02:00
committed by GitHub
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>
);
};