Skip to content

Commit

Permalink
Merge pull request #44 from Azure/az/fixes-12-4
Browse files Browse the repository at this point in the history
Fixed handling of YAML files in Swagger UI, and the absence of spec.
  • Loading branch information
azaslonov authored Dec 5, 2024
2 parents c68eb97 + dcf167f commit 88377d1
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
4 changes: 4 additions & 0 deletions src/routes/Main/ApiDetail/Options.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ const Options: FC<{ api: Api; version?: string; definition?: string, environment

const downloadUrl = await apiService.getSpecificationLink(api.name, version, definition);

if (!downloadUrl) {
return;
}

setSchemaUrl(downloadUrl);
};

Expand Down
5 changes: 3 additions & 2 deletions src/routes/Main/Swagger/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ const Swagger = () => {
if (!version || !definition) return;

const downloadUrl = await apiService.getSpecificationLink(name, version, definition);
const apiSpecification = await fetch(downloadUrl).then((r) => r.json());
const downloadResult = await fetch(downloadUrl);
const content: any = await downloadResult.text();

setSpecification(apiSpecification);
setSpecification(content);
setIsLoading(false);
};

Expand Down
21 changes: 14 additions & 7 deletions src/services/httpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,23 @@ export class HttpClient implements IHttpClient {

const response = await fetch(requestUrl, { method, headers });

if (accessToken && (response.status === 401 || response.status == 403)) {
localStorage.setItem("MS_APIC_DEVPORTAL_isRestricted", "true");
return;
} else if (!response.ok) {
alert("Something went wrong");
return;
switch (response.status) {
case 401:
case 403:
if (accessToken) {
localStorage.setItem("MS_APIC_DEVPORTAL_isRestricted", "true");
return null;
}
break;

case 404:
return null;

default:
break;
}

const dataJson = await response.json();

return dataJson;
}
}
2 changes: 1 addition & 1 deletion src/util/useApiService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class ApiService {
`apis/${apiName}/versions/${versionName}/definitions/${definitionName}:exportSpecification`,
Method.POST
);
return response.value;
return response?.value;
}

public async getEnvironment(environmentId: string) {
Expand Down

0 comments on commit 88377d1

Please sign in to comment.