Skip to content

Commit

Permalink
try with xhr
Browse files Browse the repository at this point in the history
  • Loading branch information
DominikB2014 committed Aug 23, 2024
1 parent f6ce47b commit 164d8d4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 56,070 deletions.
19 changes: 19 additions & 0 deletions src/build/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,22 @@ export const resolveRemoteApiSpec = async (): Promise<DeRefedOpenAPI> => {
);
return response.json() as Promise<DeRefedOpenAPI>;
};

export const resolveSpecWithXHR = new Promise<DeRefedOpenAPI>((resolve, reject) => {
const xhr = new XMLHttpRequest();
xhr.onreadystatechange = () => {
if (xhr.readyState === XMLHttpRequest.DONE) {
return resolve(JSON.parse(xhr.responseText) as DeRefedOpenAPI);
}
if (xhr.readyState === XMLHttpRequest.UNSENT) {
return reject('Failed to fetch schema');
}
return undefined;
};
xhr.open(
'GET',
`https://raw.githubusercontent.com/getsentry/sentry-api-schema/${SENTRY_API_SCHEMA_SHA}/openapi-derefed.json`,
true
);
xhr.send(null);
});
12 changes: 8 additions & 4 deletions src/components/api-docs/apiDocs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import {Fragment, useEffect, useState} from 'react';
import {LoadingArticle} from 'apps/changelog/src/client/components/article';
import {OpenAPIV3_1} from 'openapi-types';
import {API, APICategory} from 'src/build/resolveOpenAPI';
// import {resolveRemoteApiSpec} from 'src/build/shared';
import SwaggerUI, {SwaggerUIProps} from 'swagger-ui-react';

import {LOCAL_API_SPEC} from './localApiSpec';
import {resolveRemoteApiSpec} from 'sentry-docs/build/shared';

import {HTTPSnippetGenerators} from './plugins';
import {getSnippetConfig} from './settings';

Expand Down Expand Up @@ -77,10 +79,12 @@ export function ApiDocs({api}: Props) {
const [apiSpec, setApiSpec] = useState<OpenApiSpec | null>(null);

useEffect(() => {
const fetchApiSpec = () => {
const fetchApiSpec = async () => {
// this is temporary, for demo purposed
const spec = LOCAL_API_SPEC as any as OpenApiSpec;
// const spec = (await resolveRemoteApiSpec()) as any as OpenApiSpec;
const spec = (await resolveRemoteApiSpec()) as any as OpenApiSpec;

// eslint-disable-next-line no-console
console.log('resolving spec', spec);
setApiSpec(spec);
};

Expand Down
Loading

0 comments on commit 164d8d4

Please sign in to comment.