Skip to content

Commit

Permalink
Merge branch 'main' into remove_browser_field_type
Browse files Browse the repository at this point in the history
  • Loading branch information
lgestc authored Aug 1, 2024
2 parents d520293 + cca1a3c commit 7972fd3
Show file tree
Hide file tree
Showing 9 changed files with 170 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,13 @@ export function mergeTags(

const merged = mergeArrays(tagsArrayOfArrays);

return merged.length > 0 ? merged : undefined;
if (merged.length === 0) {
return;
}

// To streamline API endpoints categorization it's expected that
// tags are sorted alphabetically by name
merged.sort((a, b) => a.name.localeCompare(b.name));

return merged;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { bundleSpecs } from '../bundle_specs';
import { createOASDocument } from '../../create_oas_document';

describe('OpenAPI Bundler - sort tags', () => {
it('sorts tags in the result bundle', async () => {
const spec1 = createOASDocument({
paths: {
'/api/some_api': {
get: {
responses: {},
},
},
},
tags: [
{ name: 'Some tag name', description: 'Some description' },
{ name: '1 tag', description: 'Some description' },
],
});
const spec2 = createOASDocument({
paths: {
'/api/some_api': {
post: {
responses: {},
},
},
},
tags: [{ name: 'Another tag name', description: 'Another description' }],
});
const spec3 = createOASDocument({
paths: {
'/api/some_api': {
put: {
responses: {},
},
},
},
tags: [{ name: 'Spec3 tag name', description: 'Spec3 tag description' }],
});

const [bundledSpec] = Object.values(
await bundleSpecs({
1: spec1,
2: spec2,
3: spec3,
})
);

expect(bundledSpec.tags).toEqual([
{ name: '1 tag', description: 'Some description' },
{ name: 'Another tag name', description: 'Another description' },
{ name: 'Some tag name', description: 'Some description' },
{ name: 'Spec3 tag name', description: 'Spec3 tag description' },
]);
});
});
5 changes: 5 additions & 0 deletions packages/kbn-openapi-bundler/tests/create_oas_document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export function createOASDocument(overrides: {
components?: OpenAPIV3.ComponentsObject;
servers?: OpenAPIV3.ServerObject[];
security?: OpenAPIV3.SecurityRequirementObject[];
tags?: OpenAPIV3.TagObject[];
}): OpenAPIV3.Document {
const document: OpenAPIV3.Document = {
openapi: overrides.openapi ?? '3.0.3',
Expand All @@ -39,5 +40,9 @@ export function createOASDocument(overrides: {
document.security = overrides.security;
}

if (overrides.tags) {
document.tags = overrides.tags;
}

return document;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { mergeSpecs } from '../merge_specs';
import { createOASDocument } from '../../create_oas_document';

describe('OpenAPI Merger - sort tags', () => {
it('sorts tags in the result bundle', async () => {
const spec1 = createOASDocument({
paths: {
'/api/some_api': {
get: {
responses: {},
},
},
},
tags: [
{ name: 'Some tag name', description: 'Some description' },
{ name: '1 tag', description: 'Some description' },
],
});
const spec2 = createOASDocument({
paths: {
'/api/some_api': {
post: {
responses: {},
},
},
},
tags: [{ name: 'Another tag name', description: 'Another description' }],
});
const spec3 = createOASDocument({
paths: {
'/api/some_api': {
put: {
responses: {},
},
},
},
tags: [{ name: 'Spec3 tag name', description: 'Spec3 tag description' }],
});

const [mergedSpec] = Object.values(
await mergeSpecs({
1: spec1,
2: spec2,
3: spec3,
})
);

expect(mergedSpec.tags).toEqual([
{ name: '1 tag', description: 'Some description' },
{ name: 'Another tag name', description: 'Another description' },
{ name: 'Some tag name', description: 'Some description' },
{ name: 'Spec3 tag name', description: 'Spec3 tag description' },
]);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,20 @@ export class MonacoEditorActionsProvider {
} = context;
const { toasts } = notifications;
try {
const requests = await this.getRequests();
if (!requests.length) {
const allRequests = await this.getRequests();
// if any request doesnt have a method then we gonna treat it as a non-valid
// request
const requests = allRequests.filter((request) => request.method);

// If we do have requests but none have methods we are not sending the request
if (allRequests.length > 0 && !requests.length) {
toasts.addWarning(
i18n.translate('console.notification.monaco.error.nonSupportedRequest', {
defaultMessage: 'The selected request is not valid.',
})
);
return;
} else if (!requests.length) {
toasts.add(
i18n.translate('console.notification.monaco.error.noRequestSelectedTitle', {
defaultMessage:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,16 @@ const getInsertText = (
}
let insertText = '';
if (typeof name === 'string') {
insertText = bodyContent.endsWith('"') ? '' : '"';
const bodyContentLines = bodyContent.split('\n');
const currentContentLine = bodyContentLines[bodyContentLines.length - 1];
const incompleteFieldRegex = /.*"[^"]*$/;
if (incompleteFieldRegex.test(currentContentLine)) {
// The cursor is after an unmatched quote (e.g. '..."abc', '..."')
insertText = '';
} else {
// The cursor is at the beginning of a field so the insert text should start with a quote
insertText = '"';
}
if (insertValue && insertValue !== '{' && insertValue !== '[') {
insertText += `${insertValue}"`;
} else {
Expand Down
10 changes: 3 additions & 7 deletions test/functional/apps/console/monaco/_console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { FtrProviderContext } from '../../../ftr_provider_context';
export default function ({ getService, getPageObjects }: FtrProviderContext) {
const retry = getService('retry');
const log = getService('log');
const toasts = getService('toasts');
const browser = getService('browser');
const PageObjects = getPageObjects(['common', 'console', 'header']);
const security = getService('security');
Expand Down Expand Up @@ -57,17 +58,12 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
expect(initialSize.width).to.be.greaterThan(afterSize.width);
});

it('should return statusCode 400 to unsupported HTTP verbs', async () => {
const expectedResponseContains = '"statusCode": 400';
it('should not send request with unsupported HTTP verbs', async () => {
await PageObjects.console.monaco.clearEditorText();
await PageObjects.console.monaco.enterText('OPTIONS /');
await PageObjects.console.clickPlay();
await retry.try(async () => {
const actualResponse = await PageObjects.console.monaco.getOutputText();
log.debug(actualResponse);
expect(actualResponse).to.contain(expectedResponseContains);

expect(await PageObjects.console.hasSuccessBadge()).to.be(false);
expect(await toasts.getCount()).to.equal(1);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export function LogErrorRateChart({ height }: { height: number }) {
type: 'linemark',
color: currentPeriodColor,
title: i18n.translate('xpack.apm.logs.chart.logsErrorRate', {
defaultMessage: 'Log Error Rate',
defaultMessage: 'Log Error %',
}),
},
];
Expand All @@ -80,7 +80,7 @@ export function LogErrorRateChart({ height }: { height: number }) {
<EuiTitle size="xs">
<h2>
{i18n.translate('xpack.apm.logErrorRate', {
defaultMessage: 'Log error rate',
defaultMessage: 'Log error %',
})}
</h2>
</EuiTitle>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ export function getServiceColumns({
name: (
<ColumnHeader
label={i18n.translate('xpack.apm.multiSignal.servicesTable.logErrorRate', {
defaultMessage: 'Log error rate',
defaultMessage: 'Log error %',
})}
formula={getMetricsFormula(ChartMetricType.LOG_ERROR_RATE)}
toolTip={
Expand Down

0 comments on commit 7972fd3

Please sign in to comment.