From 5024688bc3204adbdc526af87b54133be746a22d Mon Sep 17 00:00:00 2001
From: chris48s <chris48s@users.noreply.github.com>
Date: Sun, 24 Dec 2023 20:29:08 +0000
Subject: [PATCH] migrate examples to openApi part 23; affects [wordpress]
 (#9732)

* migrate some services from examples to openApi

* whoops. missed a spot
---
 services/wordpress/wordpress-base.js          |  2 +-
 .../wordpress/wordpress-downloads.service.js  | 56 ++++++++++-----
 .../wordpress-last-update.service.js          | 27 ++++---
 .../wordpress/wordpress-platform.service.js   | 70 ++++++++++++-------
 .../wordpress/wordpress-rating.service.js     | 57 ++++++++-------
 .../wordpress/wordpress-version.service.js    | 26 ++++---
 6 files changed, 150 insertions(+), 88 deletions(-)

diff --git a/services/wordpress/wordpress-base.js b/services/wordpress/wordpress-base.js
index 24ecd4ca20..edb5ca0ff4 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 aeb2aeac89..b1b2c09d00 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 a714ed9a90..3e0d96d856 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 b5e4e037f4..ccef31406e 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 af2e41d557..9c43c00c76 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 f3015bfa3c..8e7432bf16 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 }
 
-- 
GitLab