diff --git a/services/sonar/sonar-coverage.service.js b/services/sonar/sonar-coverage.service.js index cd6351e58e9e3..74b7579eaf782 100644 --- a/services/sonar/sonar-coverage.service.js +++ b/services/sonar/sonar-coverage.service.js @@ -1,6 +1,11 @@ +import { pathParam } from '../index.js' import { coveragePercentage } from '../color-formatters.js' import SonarBase from './sonar-base.js' -import { documentation, keywords, queryParamSchema } from './sonar-helpers.js' +import { + documentation, + queryParamSchema, + openApiQueryParams, +} from './sonar-helpers.js' export default class SonarCoverage extends SonarBase { static category = 'coverage' @@ -11,22 +16,29 @@ export default class SonarCoverage extends SonarBase { queryParamSchema, } - static examples = [ - { - title: 'Sonar Coverage', - namedParams: { - component: 'org.ow2.petals:petals-se-ase', - branch: 'master', + static openApi = { + '/sonar/coverage/{component}': { + get: { + summary: 'Sonar Coverage', + description: documentation, + parameters: [ + pathParam({ name: 'component', example: 'swellaby:letra' }), + ...openApiQueryParams, + ], }, - queryParams: { - server: 'http://sonar.petalslink.com', - sonarVersion: '4.2', + }, + '/sonar/coverage/{component}/{branch}': { + get: { + summary: 'Sonar Coverage (branch)', + description: documentation, + parameters: [ + pathParam({ name: 'component', example: 'swellaby:letra' }), + pathParam({ name: 'branch', example: 'master' }), + ...openApiQueryParams, + ], }, - staticPreview: this.render({ coverage: 63 }), - keywords, - documentation, }, - ] + } static defaultBadgeData = { label: 'coverage' } diff --git a/services/sonar/sonar-documented-api-density.service.js b/services/sonar/sonar-documented-api-density.service.js index 6e79354164dd2..69c1ccd861b87 100644 --- a/services/sonar/sonar-documented-api-density.service.js +++ b/services/sonar/sonar-documented-api-density.service.js @@ -1,9 +1,10 @@ +import { pathParam } from '../index.js' import SonarBase from './sonar-base.js' import { queryParamSchema, + openApiQueryParams, getLabel, positiveMetricColorScale, - keywords, documentation, } from './sonar-helpers.js' @@ -18,22 +19,31 @@ export default class SonarDocumentedApiDensity extends SonarBase { queryParamSchema, } - static examples = [ - { - title: 'Sonar Documented API Density', - namedParams: { - component: 'org.ow2.petals:petals-se-ase', - branch: 'master', + static get openApi() { + const routes = {} + routes[`/sonar/${metric}/{component}`] = { + get: { + summary: 'Sonar Documented API Density', + description: documentation, + parameters: [ + pathParam({ name: 'component', example: 'swellaby:letra' }), + ...openApiQueryParams, + ], }, - queryParams: { - server: 'http://sonar.petalslink.com', - sonarVersion: '4.2', + } + routes[`/sonar/${metric}/{component}/{branch}`] = { + get: { + summary: 'Sonar Documented API Density (branch)', + description: documentation, + parameters: [ + pathParam({ name: 'component', example: 'swellaby:letra' }), + pathParam({ name: 'branch', example: 'master' }), + ...openApiQueryParams, + ], }, - staticPreview: this.render({ density: 82 }), - keywords, - documentation, - }, - ] + } + return routes + } static defaultBadgeData = { label: getLabel({ metric }) } diff --git a/services/sonar/sonar-fortify-rating.service.js b/services/sonar/sonar-fortify-rating.service.js index bc2e220ee8f98..c7ebb38938b87 100644 --- a/services/sonar/sonar-fortify-rating.service.js +++ b/services/sonar/sonar-fortify-rating.service.js @@ -1,5 +1,10 @@ +import { pathParam } from '../index.js' import SonarBase from './sonar-base.js' -import { queryParamSchema, keywords, documentation } from './sonar-helpers.js' +import { + queryParamSchema, + openApiQueryParams, + documentation, +} from './sonar-helpers.js' const colorMap = { 0: 'red', @@ -10,6 +15,13 @@ const colorMap = { 5: 'brightgreen', } +const description = `
+Note that the Fortify Security Rating badge will only work on Sonar instances that have the Fortify SonarQube Plugin installed. +The badge is not available for projects analyzed on SonarCloud.io +
+${documentation} +` + export default class SonarFortifyRating extends SonarBase { static category = 'analysis' @@ -19,26 +31,29 @@ export default class SonarFortifyRating extends SonarBase { queryParamSchema, } - static examples = [ - { - title: 'Sonar Fortify Security Rating', - namedParams: { - component: 'org.ow2.petals:petals-se-ase', + static openApi = { + '/sonar/fortify-security-rating/{component}': { + get: { + summary: 'Sonar Fortify Security Rating', + description, + parameters: [ + pathParam({ name: 'component', example: 'swellaby:letra' }), + ...openApiQueryParams, + ], }, - queryParams: { - server: 'http://sonar.petalslink.com', - sonarVersion: '4.2', + }, + '/sonar/fortify-security-rating/{component}/{branch}': { + get: { + summary: 'Sonar Fortify Security Rating (branch)', + description, + parameters: [ + pathParam({ name: 'component', example: 'swellaby:letra' }), + pathParam({ name: 'branch', example: 'master' }), + ...openApiQueryParams, + ], }, - staticPreview: this.render({ rating: 4 }), - keywords, - documentation: `- Note that the Fortify Security Rating badge will only work on Sonar instances that have the Fortify SonarQube Plugin installed. - The badge is not available for projects analyzed on SonarCloud.io -
- ${documentation} - `, }, - ] + } static defaultBadgeData = { label: 'fortify-security-rating' } diff --git a/services/sonar/sonar-generic.tester.js b/services/sonar/sonar-generic.tester.js index 66f47b266213a..d95eda3f9ef54 100644 --- a/services/sonar/sonar-generic.tester.js +++ b/services/sonar/sonar-generic.tester.js @@ -4,9 +4,7 @@ export const t = await createServiceTester() t.create('Security Rating') .timeout(10000) - .get( - '/security_rating/com.luckybox:luckybox.json?server=https://sonarcloud.io', - ) + .get('/security_rating/WebExtensions.Net.json?server=https://sonarcloud.io') .expectBadge({ label: 'security rating', message: isMetric, @@ -16,7 +14,7 @@ t.create('Security Rating') t.create('Security Rating (branch)') .timeout(10000) .get( - '/security_rating/com.luckybox:luckybox/master.json?server=https://sonarcloud.io', + '/security_rating/WebExtensions.Net/main.json?server=https://sonarcloud.io', ) .expectBadge({ label: 'security rating', diff --git a/services/sonar/sonar-helpers.js b/services/sonar/sonar-helpers.js index b9fb0d8da2680..f0b805c087832 100644 --- a/services/sonar/sonar-helpers.js +++ b/services/sonar/sonar-helpers.js @@ -1,4 +1,5 @@ import Joi from 'joi' +import { queryParams } from '../index.js' import { colorScale } from '../color-formatters.js' import { optionalUrl } from '../validators.js' @@ -40,6 +41,11 @@ const queryParamSchema = Joi.object({ server: optionalUrl.required(), }).required() +const openApiQueryParams = queryParams( + { name: 'server', example: 'https://sonarcloud.io', required: true }, + { name: 'sonarVersion', example: '4.2' }, +) + const queryParamWithFormatSchema = Joi.object({ sonarVersion: sonarVersionSchema, server: optionalUrl.required(), @@ -61,6 +67,7 @@ export { getLabel, isLegacyVersion, queryParamSchema, + openApiQueryParams, queryParamWithFormatSchema, negativeMetricColorScale, positiveMetricColorScale, diff --git a/services/sonar/sonar-quality-gate.service.js b/services/sonar/sonar-quality-gate.service.js index 525b4dc5d041a..58eead9dd1fdf 100644 --- a/services/sonar/sonar-quality-gate.service.js +++ b/services/sonar/sonar-quality-gate.service.js @@ -1,5 +1,10 @@ +import { pathParam } from '../index.js' import SonarBase from './sonar-base.js' -import { documentation, keywords, queryParamSchema } from './sonar-helpers.js' +import { + documentation, + queryParamSchema, + openApiQueryParams, +} from './sonar-helpers.js' export default class SonarQualityGate extends SonarBase { static category = 'analysis' @@ -10,23 +15,29 @@ export default class SonarQualityGate extends SonarBase { queryParamSchema, } - static examples = [ - { - title: 'Sonar Quality Gate', - namedParams: { - component: 'swellaby:azdo-shellcheck', - metric: 'quality_gate', - branch: 'master', + static openApi = { + '/sonar/quality_gate/{component}': { + get: { + summary: 'Sonar Quality Gate', + description: documentation, + parameters: [ + pathParam({ name: 'component', example: 'swellaby:azdo-shellcheck' }), + ...openApiQueryParams, + ], }, - queryParams: { - server: 'https://sonarcloud.io', - sonarVersion: '4.2', + }, + '/sonar/quality_gate/{component}/{branch}': { + get: { + summary: 'Sonar Quality Gate (branch)', + description: documentation, + parameters: [ + pathParam({ name: 'component', example: 'swellaby:azdo-shellcheck' }), + pathParam({ name: 'branch', example: 'master' }), + ...openApiQueryParams, + ], }, - staticPreview: this.render({ qualityState: 'OK' }), - keywords, - documentation, }, - ] + } static defaultBadgeData = { label: 'quality gate' } diff --git a/services/sonar/sonar-tech-debt.service.js b/services/sonar/sonar-tech-debt.service.js index f9182ca6e9477..8c3c98ad30d13 100644 --- a/services/sonar/sonar-tech-debt.service.js +++ b/services/sonar/sonar-tech-debt.service.js @@ -1,10 +1,11 @@ +import { pathParam } from '../index.js' import SonarBase from './sonar-base.js' import { negativeMetricColorScale, getLabel, documentation, - keywords, queryParamSchema, + openApiQueryParams, } from './sonar-helpers.js' export default class SonarTechDebt extends SonarBase { @@ -16,26 +17,29 @@ export default class SonarTechDebt extends SonarBase { queryParamSchema, } - static examples = [ - { - title: 'Sonar Tech Debt', - namedParams: { - component: 'org.ow2.petals:petals-se-ase', - metric: 'tech_debt', - branch: 'master', + static openApi = { + '/sonar/tech_debt/{component}': { + get: { + summary: 'Sonar Tech Debt', + description: documentation, + parameters: [ + pathParam({ name: 'component', example: 'swellaby:letra' }), + ...openApiQueryParams, + ], }, - queryParams: { - server: 'http://sonar.petalslink.com', - sonarVersion: '4.2', + }, + '/sonar/tech_debt/{component}/{branch}': { + get: { + summary: 'Sonar Tech Debt (branch)', + description: documentation, + parameters: [ + pathParam({ name: 'component', example: 'swellaby:letra' }), + pathParam({ name: 'branch', example: 'master' }), + ...openApiQueryParams, + ], }, - staticPreview: this.render({ - debt: 1, - metric: 'tech_debt', - }), - keywords, - documentation, }, - ] + } static defaultBadgeData = { label: 'tech debt' } diff --git a/services/sonar/sonar-tests.service.js b/services/sonar/sonar-tests.service.js index 6cbf153850a9c..dd1c5ae9982c5 100644 --- a/services/sonar/sonar-tests.service.js +++ b/services/sonar/sonar-tests.service.js @@ -1,5 +1,7 @@ +import { pathParam } from '../index.js' import { testResultQueryParamSchema, + testResultOpenApiQueryParams, renderTestResultBadge, documentation as testResultsDocumentation, } from '../test-results.js' @@ -7,8 +9,8 @@ import { metric as metricCount } from '../text-formatters.js' import SonarBase from './sonar-base.js' import { documentation, - keywords, queryParamSchema, + openApiQueryParams, getLabel, } from './sonar-helpers.js' @@ -20,34 +22,35 @@ class SonarTestsSummary extends SonarBase { queryParamSchema: queryParamSchema.concat(testResultQueryParamSchema), } - static examples = [ - { - title: 'Sonar Tests', - namedParams: { - component: 'org.ow2.petals:petals-se-ase', - branch: 'master', + static openApi = { + '/sonar/tests/{component}': { + get: { + summary: 'Sonar Tests', + description: `${documentation} + ${testResultsDocumentation} + `, + parameters: [ + pathParam({ name: 'component', example: 'swellaby:letra' }), + ...openApiQueryParams, + ...testResultOpenApiQueryParams, + ], }, - queryParams: { - server: 'http://sonar.petalslink.com', - sonarVersion: '4.2', - compact_message: null, - passed_label: 'passed', - failed_label: 'failed', - skipped_label: 'skipped', + }, + '/sonar/tests/{component}/{branch}': { + get: { + summary: 'Sonar Tests (branch)', + description: `${documentation} + ${testResultsDocumentation} + `, + parameters: [ + pathParam({ name: 'component', example: 'swellaby:letra' }), + pathParam({ name: 'branch', example: 'master' }), + ...openApiQueryParams, + ...testResultOpenApiQueryParams, + ], }, - staticPreview: this.render({ - passed: 5, - failed: 1, - skipped: 0, - total: 6, - isCompact: false, - }), - keywords, - documentation: `${documentation} - ${testResultsDocumentation} - `, }, - ] + } static defaultBadgeData = { label: 'tests', @@ -138,64 +141,97 @@ class SonarTests extends SonarBase { queryParamSchema, } - static examples = [ - { - title: 'Sonar Test Count', - pattern: - ':metric(total_tests|skipped_tests|test_failures|test_errors)/:component/:branch*', - namedParams: { - component: 'org.ow2.petals:petals-log', - metric: 'total_tests', - branch: 'master', + static openApi = { + '/sonar/{metric}/{component}': { + get: { + summary: 'Sonar Test Count', + description: documentation, + parameters: [ + pathParam({ + name: 'metric', + example: 'total_tests', + schema: { + type: 'string', + enum: [ + 'total_tests', + 'skipped_tests', + 'test_failures', + 'test_errors', + ], + }, + }), + pathParam({ name: 'component', example: 'swellaby:letra' }), + ...openApiQueryParams, + ], }, - queryParams: { - server: 'http://sonar.petalslink.com', - sonarVersion: '4.2', + }, + '/sonar/{metric}/{component}/{branch}': { + get: { + summary: 'Sonar Test Count (branch)', + description: documentation, + parameters: [ + pathParam({ + name: 'metric', + example: 'total_tests', + schema: { + type: 'string', + enum: [ + 'total_tests', + 'skipped_tests', + 'test_failures', + 'test_errors', + ], + }, + }), + pathParam({ name: 'component', example: 'swellaby:letra' }), + pathParam({ name: 'branch', example: 'master' }), + ...openApiQueryParams, + ], }, - staticPreview: this.render({ - metric: 'total_tests', - value: 131, - }), - keywords, - documentation, }, - { - title: 'Sonar Test Execution Time', - pattern: 'test_execution_time/:component/:branch*', - namedParams: { - component: 'swellaby:azure-pipelines-templates', - branch: 'master', + '/sonar/test_execution_time/{component}': { + get: { + summary: 'Sonar Test Execution Time', + description: documentation, + parameters: [ + pathParam({ name: 'component', example: 'swellaby:letra' }), + ...openApiQueryParams, + ], }, - queryParams: { - server: 'https://sonarcloud.io', - sonarVersion: '4.2', + }, + '/sonar/test_execution_time/{component}/{branch}': { + get: { + summary: 'Sonar Test Execution Time (branch)', + description: documentation, + parameters: [ + pathParam({ name: 'component', example: 'swellaby:letra' }), + pathParam({ name: 'branch', example: 'master' }), + ...openApiQueryParams, + ], }, - staticPreview: this.render({ - metric: 'test_execution_time', - value: 2, - }), - keywords, - documentation, }, - { - title: 'Sonar Test Success Rate', - pattern: 'test_success_density/:component/:branch*', - namedParams: { - component: 'swellaby:azure-pipelines-templates', - branch: 'master', + '/sonar/test_success_density/{component}': { + get: { + summary: 'Sonar Test Success Rate', + description: documentation, + parameters: [ + pathParam({ name: 'component', example: 'swellaby:letra' }), + ...openApiQueryParams, + ], }, - queryParams: { - server: 'https://sonarcloud.io', - sonarVersion: '4.2', + }, + '/sonar/test_success_density/{component}/{branch}': { + get: { + summary: 'Sonar Test Success Rate (branch)', + description: documentation, + parameters: [ + pathParam({ name: 'component', example: 'swellaby:letra' }), + pathParam({ name: 'branch', example: 'master' }), + ...openApiQueryParams, + ], }, - staticPreview: this.render({ - metric: 'test_success_density', - value: 100, - }), - keywords, - documentation, }, - ] + } static defaultBadgeData = { label: 'tests', diff --git a/services/sonar/sonar-tests.tester.js b/services/sonar/sonar-tests.tester.js index 5e7762115a4d8..2aa1428244226 100644 --- a/services/sonar/sonar-tests.tester.js +++ b/services/sonar/sonar-tests.tester.js @@ -26,9 +26,7 @@ const isMetricAllowZero = Joi.alternatives( t.create('Tests') .timeout(10000) - .get( - '/tests/swellaby:azure-pipelines-templates.json?server=https://sonarcloud.io', - ) + .get('/tests/WebExtensions.Net.json?server=https://sonarcloud.io') .expectBadge({ label: 'tests', message: isDefaultTestTotals, @@ -36,9 +34,7 @@ t.create('Tests') t.create('Tests (branch)') .timeout(10000) - .get( - '/tests/swellaby:azure-pipelines-templates/master.json?server=https://sonarcloud.io', - ) + .get('/tests/WebExtensions.Net/main.json?server=https://sonarcloud.io') .expectBadge({ label: 'tests', message: isDefaultTestTotals, @@ -83,7 +79,7 @@ t.create('Tests (legacy API supported)') t.create('Tests with compact message') .timeout(10000) - .get('/tests/swellaby:azure-pipelines-templates.json', { + .get('/tests/WebExtensions.Net.json', { qs: { compact_message: null, server: 'https://sonarcloud.io', @@ -93,7 +89,7 @@ t.create('Tests with compact message') t.create('Tests with custom labels') .timeout(10000) - .get('/tests/swellaby:azure-pipelines-templates.json', { + .get('/tests/WebExtensions.Net.json', { qs: { server: 'https://sonarcloud.io', passed_label: 'good', @@ -105,7 +101,7 @@ t.create('Tests with custom labels') t.create('Tests with compact message and custom labels') .timeout(10000) - .get('/tests/swellaby:azure-pipelines-templates.json', { + .get('/tests/WebExtensions.Net.json', { qs: { server: 'https://sonarcloud.io', compact_message: null, diff --git a/services/sonar/sonar-violations.service.js b/services/sonar/sonar-violations.service.js index a8b20b76bc878..50b79bc777508 100644 --- a/services/sonar/sonar-violations.service.js +++ b/services/sonar/sonar-violations.service.js @@ -1,11 +1,12 @@ +import { pathParam, queryParam } from '../index.js' import { colorScale } from '../color-formatters.js' import { metric } from '../text-formatters.js' import SonarBase from './sonar-base.js' import { getLabel, documentation, - keywords, queryParamWithFormatSchema, + openApiQueryParams, } from './sonar-helpers.js' const violationsColorScale = colorScale( @@ -31,50 +32,57 @@ export default class SonarViolations extends SonarBase { queryParamSchema: queryParamWithFormatSchema, } - static examples = [ - { - title: 'Sonar Violations (short format)', - namedParams: { - component: 'swellaby:azdo-shellcheck', - metric: 'violations', - branch: 'master', + static openApi = { + '/sonar/{metric}/{component}': { + get: { + summary: 'Sonar Violations', + description: documentation, + parameters: [ + pathParam({ + name: 'metric', + example: 'violations', + schema: { type: 'string', enum: this.getEnum('metric') }, + }), + pathParam({ name: 'component', example: 'swellaby:letra' }), + ...openApiQueryParams, + queryParam({ + name: 'format', + example: 'long', + schema: { + type: 'string', + enum: ['short', 'long'], + }, + description: 'If not specified, the default is `short`.', + }), + ], }, - queryParams: { - server: 'https://sonarcloud.io', - format: 'short', - sonarVersion: '4.2', - }, - staticPreview: this.render({ - violations: 0, - metricName: 'violations', - format: 'short', - }), - keywords, - documentation, }, - { - title: 'Sonar Violations (long format)', - namedParams: { - component: 'org.ow2.petals:petals-se-ase', - metric: 'violations', - branch: 'master', - }, - queryParams: { - server: 'http://sonar.petalslink.com', - format: 'long', + '/sonar/{metric}/{component}/{branch}': { + get: { + summary: 'Sonar Violations (branch)', + description: documentation, + parameters: [ + pathParam({ + name: 'metric', + example: 'violations', + schema: { type: 'string', enum: this.getEnum('metric') }, + }), + pathParam({ name: 'component', example: 'swellaby:letra' }), + pathParam({ name: 'branch', example: 'master' }), + ...openApiQueryParams, + queryParam({ + name: 'format', + example: 'long', + schema: { + type: 'string', + enum: ['short', 'long'], + }, + description: 'If not specified, the default is `short`.', + }), + ], }, - staticPreview: this.render({ - violations: { - info_violations: 2, - minor_violations: 1, - }, - metricName: 'violations', - format: 'long', - }), - keywords, - documentation, }, - ] + } static defaultBadgeData = { label: 'violations' }