Merge pull request #21964 from backstage/freben/unregister

Fix a bug in `getLocationByRef` that led to invalid backend calls
This commit is contained in:
Fredrik Adelöw
2023-12-21 13:34:58 +01:00
committed by GitHub
6 changed files with 30 additions and 10 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/catalog-client': patch
---
Fix a bug in `getLocationByRef` that led to invalid backend calls
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/repo-tools': patch
---
Updated the OpenAPI template to export the `TypedResponse` interface so that client code can leverage it
@@ -42,7 +42,7 @@ import { createApiRef } from '@backstage/frontend-plugin-api';
/**
* Performs some work.
* @oublic
* @public
*/
export interface WorkApi {
doWork(): Promise<void>;
+5 -5
View File
@@ -43,7 +43,7 @@ import {
QueryEntitiesResponse,
} from './types/api';
import { isQueryEntitiesInitialRequest } from './utils';
import { DefaultApiClient } from './generated';
import { DefaultApiClient, TypedResponse } from './generated';
/**
* A frontend and backend compatible client for communicating with the Backstage
@@ -112,7 +112,7 @@ export class CatalogClient implements CatalogApi {
}
}
const entities: Entity[] = await this.requestRequired(
const entities = await this.requestRequired(
await this.apiClient.getEntities(
{
query: {
@@ -345,8 +345,8 @@ export class CatalogClient implements CatalogApi {
locationRef: string,
options?: CatalogRequestOptions,
): Promise<Location | undefined> {
const all: { data: Location }[] = await this.requestRequired(
await this.apiClient.getLocation({ path: { id: locationRef } }, options),
const all = await this.requestRequired(
await this.apiClient.getLocations({}, options),
);
return all
.map(r => r.data)
@@ -418,7 +418,7 @@ export class CatalogClient implements CatalogApi {
}
}
private async requestRequired<T = any>(response: Response): Promise<T> {
private async requestRequired<T>(response: TypedResponse<T>): Promise<T> {
if (!response.ok) {
throw await ResponseError.fromResponse(response);
}
@@ -35,7 +35,12 @@ import { Location } from '../models/Location.model';
import { RefreshEntityRequest } from '../models/RefreshEntityRequest.model';
import { ValidateEntityRequest } from '../models/ValidateEntityRequest.model';
type TypedResponse<T> = Omit<Response, 'json'> & {
/**
* Wraps the Response type to convey a type on the json call.
*
* @public
*/
export type TypedResponse<T> = Omit<Response, 'json'> & {
json: () => Promise<T>;
};
@@ -9,7 +9,12 @@ import * as parser from 'uri-template';
import { {{classname}} } from '{{filename}}.model{{importFileExtension}}';
{{/imports}}
type TypedResponse<T> = Omit<Response, 'json'> & {
/**
* Wraps the Response type to convey a type on the json call.
*
* @public
*/
export type TypedResponse<T> = Omit<Response, 'json'> & {
json: () => Promise<T>;
};
@@ -84,9 +89,9 @@ export class {{classname}}Client {
options?: RequestOptions
): Promise<TypedResponse<{{{returnType}}} {{^returnType}}void{{/returnType}}>> {
const baseUrl = await this.discoveryApi.getBaseUrl(pluginId);
const uriTemplate = `{{{path}}}{{#hasQueryParams}}{?{{#queryParams}}{{baseName}}{{#isArray}}{{#isExplode}}*{{/isExplode}}{{/isArray}}{{^-last}},{{/-last}}{{/queryParams}}}{{/hasQueryParams}}`;
const uri = parser.parse(uriTemplate).expand({
{{#pathParams}}
{{baseName}}: request.path.{{paramName}},