diff --git a/services/wordpress/wordpress-base.js b/services/wordpress/wordpress-base.js index 24ecd4ca20ed6e5cde96b122b6c6bc3d2792d283..edb5ca0ff4463c62fe9295b78a3ca39ca185483b 100644 --- a/services/wordpress/wordpress-base.js +++ b/services/wordpress/wordpress-base.js @@ -85,7 +85,7 @@ export class BaseWordpress extends BaseJsonService { } } -export const documentation = ` +export const description = ` <p> These badges rely on an API that is no longer supported by Wordpress. You are still free to use them, simply bear in mind that Shields.io cannot guarantee diff --git a/services/wordpress/wordpress-downloads.service.js b/services/wordpress/wordpress-downloads.service.js index aeb2aeac89da17a7b1f1bf9f0dbe7fe41df55a2d..b1b2c09d001ead9c754f9f63e945a0e5b4eff371 100644 --- a/services/wordpress/wordpress-downloads.service.js +++ b/services/wordpress/wordpress-downloads.service.js @@ -1,6 +1,7 @@ import Joi from 'joi' import { renderDownloadsBadge } from '../downloads.js' -import { documentation, BaseWordpress } from './wordpress-base.js' +import { pathParams } from '../index.js' +import { description, BaseWordpress } from './wordpress-base.js' const dateSchema = Joi.object() .pattern(Joi.date().iso(), Joi.number().integer()) @@ -52,14 +53,28 @@ function DownloadsForExtensionType(extensionType) { pattern: ':interval(dd|dw|dm|dy|dt)/:slug', } - static examples = [ - { - title: `WordPress ${capt} Downloads`, - namedParams: { interval: 'dm', slug: exampleSlug }, - staticPreview: this.render({ interval: 'dm', downloads: 200000 }), - documentation, - }, - ] + static get openApi() { + const key = `/wordpress/${extensionType}/{interval}/{slug}` + const route = {} + route[key] = { + get: { + summary: `WordPress ${capt} Downloads`, + description, + parameters: pathParams( + { + name: 'interval', + example: 'dm', + schema: { type: 'string', enum: this.getEnum('interval') }, + }, + { + name: 'slug', + example: exampleSlug, + }, + ), + }, + } + return route + } static defaultBadgeData = { label: 'downloads' } @@ -114,14 +129,21 @@ function InstallsForExtensionType(extensionType) { pattern: ':slug', } - static examples = [ - { - title: `WordPress ${capt} Active Installs`, - namedParams: { slug: exampleSlug }, - staticPreview: renderDownloadsBadge({ downloads: 300000 }), - documentation, - }, - ] + static get openApi() { + const key = `/wordpress/${extensionType}/installs/{slug}` + const route = {} + route[key] = { + get: { + summary: `WordPress ${capt} Active Installs`, + description, + parameters: pathParams({ + name: 'slug', + example: exampleSlug, + }), + }, + } + return route + } static defaultBadgeData = { label: 'active installs' } diff --git a/services/wordpress/wordpress-last-update.service.js b/services/wordpress/wordpress-last-update.service.js index a714ed9a90d82871cb200b38d8c084c71cca4942..3e0d96d856051e08c6b3ca28ef50a38105515c20 100644 --- a/services/wordpress/wordpress-last-update.service.js +++ b/services/wordpress/wordpress-last-update.service.js @@ -1,9 +1,9 @@ import dayjs from 'dayjs' import customParseFormat from 'dayjs/plugin/customParseFormat.js' -import { InvalidResponse } from '../index.js' +import { InvalidResponse, pathParams } from '../index.js' import { formatDate } from '../text-formatters.js' import { age as ageColor } from '../color-formatters.js' -import { documentation, BaseWordpress } from './wordpress-base.js' +import { description, BaseWordpress } from './wordpress-base.js' dayjs.extend(customParseFormat) const extensionData = { @@ -32,14 +32,21 @@ function LastUpdateForType(extensionType) { pattern: ':slug', } - static examples = [ - { - title: `WordPress ${capt} Last Updated`, - namedParams: { slug: exampleSlug }, - staticPreview: this.render({ lastUpdated: '2020-08-11' }), - documentation, - }, - ] + static get openApi() { + const key = `/wordpress/${extensionType}/last-updated/{slug}` + const route = {} + route[key] = { + get: { + summary: `WordPress ${capt} Last Updated`, + description, + parameters: pathParams({ + name: 'slug', + example: exampleSlug, + }), + }, + } + return route + } static defaultBadgeData = { label: 'last updated' } diff --git a/services/wordpress/wordpress-platform.service.js b/services/wordpress/wordpress-platform.service.js index b5e4e037f4852eabfb9204be9e9e3bba03b3fdf9..ccef31406ea461fae620f10eda391702aacd1965 100644 --- a/services/wordpress/wordpress-platform.service.js +++ b/services/wordpress/wordpress-platform.service.js @@ -1,7 +1,7 @@ -import { NotFound } from '../index.js' +import { NotFound, pathParams } from '../index.js' import { addv } from '../text-formatters.js' import { version as versionColor } from '../color-formatters.js' -import { documentation, BaseWordpress } from './wordpress-base.js' +import { description, BaseWordpress } from './wordpress-base.js' import { versionColorForWordpressVersion } from './wordpress-version-color.js' const extensionData = { @@ -28,14 +28,21 @@ function WordpressRequiresVersion(extensionType) { pattern: ':slug', } - static examples = [ - { - title: `WordPress ${capt}: Required WP Version`, - namedParams: { slug: exampleSlug }, - staticPreview: this.render({ wordpressVersion: '4.8' }), - documentation, - }, - ] + static get openApi() { + const key = `/wordpress/${extensionType}/wp-version/{slug}` + const route = {} + route[key] = { + get: { + summary: `WordPress ${capt}: Required WP Version`, + description, + parameters: pathParams({ + name: 'slug', + example: exampleSlug, + }), + }, + } + return route + } static defaultBadgeData = { label: 'wordpress' } @@ -71,16 +78,18 @@ class WordpressPluginTestedVersion extends BaseWordpress { pattern: ':slug', } - static examples = [ - { - title: 'WordPress Plugin: Tested WP Version', - namedParams: { slug: 'bbpress' }, - staticPreview: this.renderStaticPreview({ - testedVersion: '4.9.8', - }), - documentation, + static openApi = { + '/wordpress/plugin/tested/{slug}': { + get: { + summary: 'WordPress Plugin: Tested WP Version', + description, + parameters: pathParams({ + name: 'slug', + example: 'bbpress', + }), + }, }, - ] + } static defaultBadgeData = { label: 'wordpress' } @@ -125,14 +134,21 @@ function RequiresPHPVersionForType(extensionType) { pattern: ':slug', } - static examples = [ - { - title: `WordPress ${capt} Required PHP Version`, - namedParams: { slug: exampleSlug }, - staticPreview: this.render({ version: '5.5' }), - documentation, - }, - ] + static get openApi() { + const key = `/wordpress/${extensionType}/required-php/{slug}` + const route = {} + route[key] = { + get: { + summary: `WordPress ${capt} Required PHP Version`, + description, + parameters: pathParams({ + name: 'slug', + example: exampleSlug, + }), + }, + } + return route + } static defaultBadgeData = { label: 'php' } diff --git a/services/wordpress/wordpress-rating.service.js b/services/wordpress/wordpress-rating.service.js index af2e41d55775c289b360b966eac5ce69e8812c7f..9c43c00c76351f2fd860ea4be03f310ac4273885 100644 --- a/services/wordpress/wordpress-rating.service.js +++ b/services/wordpress/wordpress-rating.service.js @@ -1,6 +1,7 @@ -import { starRating, metric } from '../text-formatters.js' import { floorCount } from '../color-formatters.js' -import { documentation, BaseWordpress } from './wordpress-base.js' +import { pathParams } from '../index.js' +import { starRating, metric } from '../text-formatters.js' +import { description, BaseWordpress } from './wordpress-base.js' const extensionData = { plugin: { @@ -30,17 +31,21 @@ function RatingForExtensionType(extensionType) { pattern: ':slug', } - static examples = [ - { - title: `WordPress ${capt} Rating`, - namedParams: { slug: exampleSlug }, - staticPreview: this.render({ - rating: 80, - numRatings: 100, - }), - documentation, - }, - ] + static get openApi() { + const key = `/wordpress/${extensionType}/rating/{slug}` + const route = {} + route[key] = { + get: { + summary: `WordPress ${capt} Rating`, + description, + parameters: pathParams({ + name: 'slug', + example: exampleSlug, + }), + }, + } + return route + } static render({ rating, numRatings }) { const scaledAndRounded = ((rating / 100) * 5).toFixed(1) @@ -71,17 +76,21 @@ function StarsForExtensionType(extensionType) { pattern: '(stars|r)/:slug', } - static examples = [ - { - title: `WordPress ${capt} Rating`, - pattern: 'stars/:slug', - namedParams: { slug: exampleSlug }, - staticPreview: this.render({ - rating: 80, - }), - documentation, - }, - ] + static get openApi() { + const key = `/wordpress/${extensionType}/stars/{slug}` + const route = {} + route[key] = { + get: { + summary: `WordPress ${capt} Stars`, + description, + parameters: pathParams({ + name: 'slug', + example: exampleSlug, + }), + }, + } + return route + } static render({ rating }) { const scaled = (rating / 100) * 5 diff --git a/services/wordpress/wordpress-version.service.js b/services/wordpress/wordpress-version.service.js index f3015bfa3cca3e8f299f56d176a144d484f32ad3..8e7432bf1639311a14ab11bb0f18fdea289a9cfe 100644 --- a/services/wordpress/wordpress-version.service.js +++ b/services/wordpress/wordpress-version.service.js @@ -1,6 +1,7 @@ +import { pathParams } from '../index.js' import { addv } from '../text-formatters.js' import { version as versionColor } from '../color-formatters.js' -import { documentation, BaseWordpress } from './wordpress-base.js' +import { description, BaseWordpress } from './wordpress-base.js' function VersionForExtensionType(extensionType) { const { capt, exampleSlug } = { @@ -24,14 +25,21 @@ function VersionForExtensionType(extensionType) { pattern: ':slug', } - static examples = [ - { - title: `WordPress ${capt} Version`, - namedParams: { slug: exampleSlug }, - staticPreview: this.render({ version: 2.5 }), - documentation, - }, - ] + static get openApi() { + const key = `/wordpress/${extensionType}/v/{slug}` + const route = {} + route[key] = { + get: { + summary: `WordPress ${capt} Version`, + description, + parameters: pathParams({ + name: 'slug', + example: exampleSlug, + }), + }, + } + return route + } static defaultBadgeData = { label: extensionType }