catalog-backend: fixed validation of fullTextFilterFields
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-catalog-backend': patch
|
||||
---
|
||||
|
||||
Fixed validation of the `fullTextFilterFields` query parameter.
|
||||
@@ -1,28 +0,0 @@
|
||||
import { parseStringParam } from './common';
|
||||
|
||||
/*
|
||||
* Copyright 2023 The Backstage Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
export function parseFullTextFilterFields(params: Record<string, unknown>) {
|
||||
const fullTextFilterFields = parseStringParam(
|
||||
params.fullTextFilterFields,
|
||||
'fullTextFilterFields',
|
||||
);
|
||||
if (!fullTextFilterFields) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return fullTextFilterFields.split(',');
|
||||
}
|
||||
@@ -28,11 +28,11 @@ describe('parseQueryEntitiesParams', () => {
|
||||
const validRequest = {
|
||||
authorizationToken: 'to_not_be_returned',
|
||||
fields: ['kind'],
|
||||
limit: '3',
|
||||
limit: 3,
|
||||
filter: ['a=1', 'b=2'],
|
||||
orderField: ['metadata.name,desc'],
|
||||
fullTextFilterTerm: 'query',
|
||||
fullTextFilterFields: 'metadata.name,metadata.namespace',
|
||||
fullTextFilterFields: ['metadata.name', 'metadata.namespace'],
|
||||
};
|
||||
const parsedObj = parseQueryEntitiesParams(
|
||||
validRequest,
|
||||
@@ -65,9 +65,7 @@ describe('parseQueryEntitiesParams', () => {
|
||||
{ filter: 3 },
|
||||
{ orderField: ['metadata.uid,diagonal'] },
|
||||
{ fields: [4] },
|
||||
{ fullTextFilterTerm: [] },
|
||||
{ fullTextFilterFields: 3 },
|
||||
])('should throw if some parameter is not valid %p', params => {
|
||||
])('should throw if some parameter is not valid %p', (params: any) => {
|
||||
expect(() => parseQueryEntitiesParams(params)).toThrow();
|
||||
});
|
||||
});
|
||||
@@ -83,7 +81,7 @@ describe('parseQueryEntitiesParams', () => {
|
||||
const validRequest = {
|
||||
authorizationToken: 'to_not_be_returned',
|
||||
fields: ['kind'],
|
||||
limit: '3',
|
||||
limit: 3,
|
||||
cursor: encodeCursor(cursor),
|
||||
};
|
||||
const parsedObj = parseQueryEntitiesParams(
|
||||
@@ -103,10 +101,10 @@ describe('parseQueryEntitiesParams', () => {
|
||||
const validRequest = {
|
||||
authorizationToken: 'to_not_be_returned',
|
||||
fields: ['kind'],
|
||||
limit: '3',
|
||||
limit: 3,
|
||||
cursor: encodeCursor(cursor),
|
||||
filter: ['a=1', 'b=2'],
|
||||
orderField: 'orderField,desc',
|
||||
orderField: ['orderField,desc'],
|
||||
query: 'query',
|
||||
};
|
||||
const parsedObj = parseQueryEntitiesParams(
|
||||
@@ -128,7 +126,7 @@ describe('parseQueryEntitiesParams', () => {
|
||||
|
||||
it.each([{ cursor: [] }, { fields: [4] }])(
|
||||
'should throw if some parameter is not valid %p',
|
||||
params => {
|
||||
(params: any) => {
|
||||
expect(() => parseQueryEntitiesParams(params)).toThrow();
|
||||
},
|
||||
);
|
||||
|
||||
@@ -20,19 +20,19 @@ import {
|
||||
QueryEntitiesRequest,
|
||||
} from '../../catalog/types';
|
||||
import { decodeCursor } from '../util';
|
||||
import { parseStringParam } from './common';
|
||||
import { parseEntityFilterParams } from './parseEntityFilterParams';
|
||||
import { parseEntityOrderFieldParams } from './parseEntityOrderFieldParams';
|
||||
import { parseEntityTransformParams } from './parseEntityTransformParams';
|
||||
import { parseFullTextFilterFields } from './parseFullTextFilterFields';
|
||||
import { spec } from '../../schema/openapi.generated';
|
||||
import { internal } from '@backstage/backend-openapi-utils';
|
||||
|
||||
export function parseQueryEntitiesParams(
|
||||
params: Record<string, unknown>,
|
||||
params: internal.QuerySchema<typeof spec, '/entities/by-query', 'get'>,
|
||||
): Omit<QueryEntitiesRequest, 'authorizationToken' | 'limit'> {
|
||||
const fields = parseEntityTransformParams(params);
|
||||
const cursor = parseStringParam(params.cursor, 'cursor');
|
||||
if (cursor) {
|
||||
const decodedCursor = decodeCursor(cursor);
|
||||
|
||||
if (params.cursor) {
|
||||
const decodedCursor = decodeCursor(params.cursor);
|
||||
const response: Omit<QueryEntitiesCursorRequest, 'authorizationToken'> = {
|
||||
cursor: decodedCursor,
|
||||
fields,
|
||||
@@ -41,12 +41,6 @@ export function parseQueryEntitiesParams(
|
||||
}
|
||||
|
||||
const filter = parseEntityFilterParams(params);
|
||||
const fullTextFilterTerm = parseStringParam(
|
||||
params.fullTextFilterTerm,
|
||||
'fullTextFilterTerm',
|
||||
);
|
||||
const fullTextFilterFields = parseFullTextFilterFields(params);
|
||||
|
||||
const orderFields = parseEntityOrderFieldParams(params);
|
||||
|
||||
const response: Omit<QueryEntitiesInitialRequest, 'authorizationToken'> = {
|
||||
@@ -54,8 +48,8 @@ export function parseQueryEntitiesParams(
|
||||
filter,
|
||||
orderFields,
|
||||
fullTextFilter: {
|
||||
term: fullTextFilterTerm || '',
|
||||
fields: fullTextFilterFields,
|
||||
term: params.fullTextFilterTerm || '',
|
||||
fields: params.fullTextFilterFields,
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user