From 6823d38ddfb5164b2f4387a99fea4dbed495274f Mon Sep 17 00:00:00 2001 From: chris48s Date: Mon, 21 Aug 2023 11:08:27 +0100 Subject: [PATCH] migrate `examples` to `openApi` part 4; affects [ecologi elm flathub gem gitter GithubTotalDiscussions greasyfork hackage hackernews homebrew] (#9430) * migrate some services from examples to openApi * improve and de-dupe service titles * revert changes to homebrew --- services/ecologi/ecologi-carbon.service.js | 18 ++++++++----- services/ecologi/ecologi-trees.service.js | 18 ++++++++----- services/elm-package/elm-package.service.js | 24 ++++++++++++----- services/flathub/flathub-downloads.service.js | 18 +++++++------ services/flathub/flathub.service.js | 18 +++++++------ services/gem/gem-owner.service.js | 19 ++++++++------ .../github-discussions-total.service.js | 26 ++++++++++++------- services/gitter/gitter.service.js | 25 +++++++++++------- .../greasyfork/greasyfork-license.service.js | 18 ++++++++----- .../greasyfork/greasyfork-rating.service.js | 17 +++++++----- .../greasyfork/greasyfork-version.service.js | 17 +++++++----- services/hackage/hackage-deps.service.js | 18 ++++++++----- services/hackage/hackage-version.service.js | 18 ++++++++----- .../hackernews-user-karma.service.js | 18 ++++++++----- services/homebrew/homebrew-cask.service.js | 18 ++++++++----- services/homebrew/homebrew-version.service.js | 18 ++++++++----- 16 files changed, 190 insertions(+), 118 deletions(-) diff --git a/services/ecologi/ecologi-carbon.service.js b/services/ecologi/ecologi-carbon.service.js index 01d878780fe63..3f90ad1c32879 100644 --- a/services/ecologi/ecologi-carbon.service.js +++ b/services/ecologi/ecologi-carbon.service.js @@ -1,7 +1,7 @@ import Joi from 'joi' import { metric } from '../text-formatters.js' import { floorCount } from '../color-formatters.js' -import { BaseJsonService } from '../index.js' +import { BaseJsonService, pathParams } from '../index.js' const apiSchema = Joi.object({ total: Joi.number().positive().required(), @@ -10,13 +10,17 @@ const apiSchema = Joi.object({ export default class EcologiCarbonOffset extends BaseJsonService { static category = 'other' static route = { base: 'ecologi/carbon', pattern: ':username' } - static examples = [ - { - title: 'Ecologi (Carbon Offset)', - namedParams: { username: 'ecologi' }, - staticPreview: this.render({ count: 15.05 }), + static openApi = { + '/ecologi/carbon/{username}': { + get: { + summary: 'Ecologi (Carbon Offset)', + parameters: pathParams({ + name: 'username', + example: 'ecologi', + }), + }, }, - ] + } static defaultBadgeData = { label: 'carbon offset' } diff --git a/services/ecologi/ecologi-trees.service.js b/services/ecologi/ecologi-trees.service.js index 0d4225bb17c1c..724a4105528a3 100644 --- a/services/ecologi/ecologi-trees.service.js +++ b/services/ecologi/ecologi-trees.service.js @@ -2,7 +2,7 @@ import Joi from 'joi' import { metric } from '../text-formatters.js' import { floorCount } from '../color-formatters.js' import { nonNegativeInteger } from '../validators.js' -import { BaseJsonService } from '../index.js' +import { BaseJsonService, pathParams } from '../index.js' const apiSchema = Joi.object({ total: nonNegativeInteger, @@ -11,13 +11,17 @@ const apiSchema = Joi.object({ export default class EcologiTrees extends BaseJsonService { static category = 'other' static route = { base: 'ecologi/trees', pattern: ':username' } - static examples = [ - { - title: 'Ecologi (Trees)', - namedParams: { username: 'ecologi' }, - staticPreview: this.render({ count: 250 }), + static openApi = { + '/ecologi/trees/{username}': { + get: { + summary: 'Ecologi (Trees)', + parameters: pathParams({ + name: 'username', + example: 'ecologi', + }), + }, }, - ] + } static defaultBadgeData = { label: 'trees' } diff --git a/services/elm-package/elm-package.service.js b/services/elm-package/elm-package.service.js index cf608fd5971e2..efa97a03abfec 100644 --- a/services/elm-package/elm-package.service.js +++ b/services/elm-package/elm-package.service.js @@ -1,20 +1,30 @@ import Joi from 'joi' import { renderVersionBadge } from '../version.js' import { semver } from '../validators.js' -import { BaseJsonService } from '../index.js' +import { BaseJsonService, pathParams } from '../index.js' const schema = Joi.object({ version: semver }).required() export default class ElmPackage extends BaseJsonService { static category = 'version' static route = { base: 'elm-package/v', pattern: ':user/:packageName' } - static examples = [ - { - title: 'Elm package', - namedParams: { user: 'elm', packageName: 'core' }, - staticPreview: this.render({ version: '1.0.2' }), + static openApi = { + '/elm-package/v/{user}/{packageName}': { + get: { + summary: 'Elm package', + parameters: pathParams( + { + name: 'user', + example: 'elm', + }, + { + name: 'packageName', + example: 'core', + }, + ), + }, }, - ] + } static defaultBadgeData = { label: 'elm package' } diff --git a/services/flathub/flathub-downloads.service.js b/services/flathub/flathub-downloads.service.js index 5ba4ed278df1d..2e384e61ca776 100644 --- a/services/flathub/flathub-downloads.service.js +++ b/services/flathub/flathub-downloads.service.js @@ -1,5 +1,5 @@ import Joi from 'joi' -import { BaseJsonService } from '../index.js' +import { BaseJsonService, pathParams } from '../index.js' import { renderDownloadsBadge } from '../downloads.js' const schema = Joi.object({ @@ -9,15 +9,17 @@ const schema = Joi.object({ export default class FlathubDownloads extends BaseJsonService { static category = 'downloads' static route = { base: 'flathub/downloads', pattern: ':packageName' } - static examples = [ - { - title: 'Flathub', - namedParams: { - packageName: 'org.mozilla.firefox', + static openApi = { + '/flathub/downloads/{packageName}': { + get: { + summary: 'Flathub Downloads', + parameters: pathParams({ + name: 'packageName', + example: 'org.mozilla.firefox', + }), }, - staticPreview: renderDownloadsBadge({ downloads: '277136' }), }, - ] + } static defaultBadgeData = { label: 'installs' } diff --git a/services/flathub/flathub.service.js b/services/flathub/flathub.service.js index 69bf99429a2ef..db377aecef544 100644 --- a/services/flathub/flathub.service.js +++ b/services/flathub/flathub.service.js @@ -1,6 +1,6 @@ import Joi from 'joi' import { renderVersionBadge } from '../version.js' -import { BaseJsonService, NotFound } from '../index.js' +import { BaseJsonService, NotFound, pathParams } from '../index.js' const schema = Joi.alternatives() .try( @@ -14,15 +14,17 @@ const schema = Joi.alternatives() export default class Flathub extends BaseJsonService { static category = 'version' static route = { base: 'flathub/v', pattern: ':packageName' } - static examples = [ - { - title: 'Flathub', - namedParams: { - packageName: 'org.mozilla.firefox', + static openApi = { + '/flathub/v/{packageName}': { + get: { + summary: 'Flathub Version', + parameters: pathParams({ + name: 'packageName', + example: 'org.mozilla.firefox', + }), }, - staticPreview: renderVersionBadge({ version: '78.0.2' }), }, - ] + } static defaultBadgeData = { label: 'flathub' } diff --git a/services/gem/gem-owner.service.js b/services/gem/gem-owner.service.js index 50c45e9062901..4c21cdafe7cb0 100644 --- a/services/gem/gem-owner.service.js +++ b/services/gem/gem-owner.service.js @@ -1,21 +1,24 @@ import Joi from 'joi' import { floorCount as floorCountColor } from '../color-formatters.js' import { metric } from '../text-formatters.js' -import { BaseJsonService } from '../index.js' +import { BaseJsonService, pathParams } from '../index.js' const ownerSchema = Joi.array().required() export default class GemOwner extends BaseJsonService { static category = 'other' static route = { base: 'gem/u', pattern: ':user' } - static examples = [ - { - title: 'Gems', - namedParams: { user: 'raphink' }, - staticPreview: this.render({ count: 34 }), - keywords: ['ruby'], + static openApi = { + '/gem/u/{user}': { + get: { + summary: 'Gem Owner', + parameters: pathParams({ + name: 'user', + example: 'raphink', + }), + }, }, - ] + } static defaultBadgeData = { label: 'gems' } diff --git a/services/github/github-discussions-total.service.js b/services/github/github-discussions-total.service.js index 425563c220a90..6812cb4f5285f 100644 --- a/services/github/github-discussions-total.service.js +++ b/services/github/github-discussions-total.service.js @@ -1,5 +1,6 @@ import gql from 'graphql-tag' import Joi from 'joi' +import { pathParams } from '../index.js' import { nonNegativeInteger } from '../validators.js' import { GithubAuthV4Service } from './github-auth-service.js' import { transformErrors } from './github-helpers.js' @@ -21,18 +22,23 @@ export default class GithubTotalDiscussions extends GithubAuthV4Service { pattern: ':user/:repo', } - static examples = [ - { - title: 'GitHub Discussions', - namedParams: { - user: 'vercel', - repo: 'next.js', + static openApi = { + '/github/discussions/{user}/{repo}': { + get: { + summary: 'GitHub Discussions', + parameters: pathParams( + { + name: 'user', + example: 'vercel', + }, + { + name: 'repo', + example: 'next.js', + }, + ), }, - staticPreview: this.render({ - discussions: '6000 total', - }), }, - ] + } static defaultBadgeData = { label: 'discussions', color: 'blue' } diff --git a/services/gitter/gitter.service.js b/services/gitter/gitter.service.js index 55e5d119f7ce7..70abfd96ea500 100644 --- a/services/gitter/gitter.service.js +++ b/services/gitter/gitter.service.js @@ -1,4 +1,4 @@ -import { BaseStaticService } from '../index.js' +import { BaseStaticService, pathParams } from '../index.js' export default class Gitter extends BaseStaticService { static category = 'chat' @@ -8,16 +8,23 @@ export default class Gitter extends BaseStaticService { pattern: ':user/:repo', } - static examples = [ - { - title: 'Gitter', - namedParams: { - user: 'nwjs', - repo: 'nw.js', + static openApi = { + '/gitter/room/{user}/{repo}': { + get: { + summary: 'Gitter', + parameters: pathParams( + { + name: 'user', + example: 'nwjs', + }, + { + name: 'repo', + example: 'nw.js', + }, + ), }, - staticPreview: this.render(), }, - ] + } static defaultBadgeData = { label: 'chat' } diff --git a/services/greasyfork/greasyfork-license.service.js b/services/greasyfork/greasyfork-license.service.js index 895b3a97a6c77..7fd693bf57bdf 100644 --- a/services/greasyfork/greasyfork-license.service.js +++ b/services/greasyfork/greasyfork-license.service.js @@ -1,18 +1,22 @@ import { renderLicenseBadge } from '../licenses.js' -import { InvalidResponse } from '../index.js' +import { InvalidResponse, pathParams } from '../index.js' import BaseGreasyForkService from './greasyfork-base.js' export default class GreasyForkLicense extends BaseGreasyForkService { static category = 'license' static route = { base: 'greasyfork', pattern: 'l/:scriptId' } - static examples = [ - { - title: 'Greasy Fork', - namedParams: { scriptId: '407466' }, - staticPreview: renderLicenseBadge({ licenses: ['MIT'] }), + static openApi = { + '/greasyfork/l/{scriptId}': { + get: { + summary: 'Greasy Fork License', + parameters: pathParams({ + name: 'scriptId', + example: '407466', + }), + }, }, - ] + } static defaultBadgeData = { label: 'license' } diff --git a/services/greasyfork/greasyfork-rating.service.js b/services/greasyfork/greasyfork-rating.service.js index 830d48645d069..39318a6d7dbc6 100644 --- a/services/greasyfork/greasyfork-rating.service.js +++ b/services/greasyfork/greasyfork-rating.service.js @@ -1,3 +1,4 @@ +import { pathParams } from '../index.js' import { floorCount as floorCountColor } from '../color-formatters.js' import { metric } from '../text-formatters.js' import BaseGreasyForkService from './greasyfork-base.js' @@ -6,13 +7,17 @@ export default class GreasyForkRatingCount extends BaseGreasyForkService { static category = 'rating' static route = { base: 'greasyfork', pattern: 'rating-count/:scriptId' } - static examples = [ - { - title: 'Greasy Fork', - namedParams: { scriptId: '407466' }, - staticPreview: this.render({ good: 17, ok: 2, bad: 3 }), + static openApi = { + '/greasyfork/rating-count/{scriptId}': { + get: { + summary: 'Greasy Fork Rating', + parameters: pathParams({ + name: 'scriptId', + example: '407466', + }), + }, }, - ] + } static defaultBadgeData = { label: 'rating' } diff --git a/services/greasyfork/greasyfork-version.service.js b/services/greasyfork/greasyfork-version.service.js index 9759703d6a357..cdb281d56c402 100644 --- a/services/greasyfork/greasyfork-version.service.js +++ b/services/greasyfork/greasyfork-version.service.js @@ -1,3 +1,4 @@ +import { pathParams } from '../index.js' import { renderVersionBadge } from '../version.js' import BaseGreasyForkService from './greasyfork-base.js' @@ -5,13 +6,17 @@ export default class GreasyForkVersion extends BaseGreasyForkService { static category = 'version' static route = { base: 'greasyfork', pattern: 'v/:scriptId' } - static examples = [ - { - title: 'Greasy Fork', - namedParams: { scriptId: '407466' }, - staticPreview: renderVersionBadge({ version: '3.9.3' }), + static openApi = { + '/greasyfork/v/{scriptId}': { + get: { + summary: 'Greasy Fork Version', + parameters: pathParams({ + name: 'scriptId', + example: '407466', + }), + }, }, - ] + } async handle({ scriptId }) { const data = await this.fetch({ scriptId }) diff --git a/services/hackage/hackage-deps.service.js b/services/hackage/hackage-deps.service.js index f3cbd1deb996b..bec34ddd45b7a 100644 --- a/services/hackage/hackage-deps.service.js +++ b/services/hackage/hackage-deps.service.js @@ -1,4 +1,4 @@ -import { BaseService } from '../index.js' +import { BaseService, pathParams } from '../index.js' export default class HackageDeps extends BaseService { static category = 'dependencies' @@ -8,13 +8,17 @@ export default class HackageDeps extends BaseService { pattern: ':packageName', } - static examples = [ - { - title: 'Hackage-Deps', - namedParams: { packageName: 'lens' }, - staticPreview: this.render({ isOutdated: false }), + static openApi = { + '/hackage-deps/v/{packageName}': { + get: { + summary: 'Hackage Dependencies', + parameters: pathParams({ + name: 'packageName', + example: 'lens', + }), + }, }, - ] + } static defaultBadgeData = { label: 'dependencies' } diff --git a/services/hackage/hackage-version.service.js b/services/hackage/hackage-version.service.js index e1333a14e6510..9a586d9e77e72 100644 --- a/services/hackage/hackage-version.service.js +++ b/services/hackage/hackage-version.service.js @@ -1,5 +1,5 @@ import { renderVersionBadge } from '../version.js' -import { BaseService, InvalidResponse } from '../index.js' +import { BaseService, InvalidResponse, pathParams } from '../index.js' export default class HackageVersion extends BaseService { static category = 'version' @@ -9,13 +9,17 @@ export default class HackageVersion extends BaseService { pattern: ':packageName', } - static examples = [ - { - title: 'Hackage', - namedParams: { packageName: 'lens' }, - staticPreview: renderVersionBadge({ version: '4.1.7' }), + static openApi = { + '/hackage/v/{packageName}': { + get: { + summary: 'Hackage Version', + parameters: pathParams({ + name: 'packageName', + example: 'lens', + }), + }, }, - ] + } static defaultBadgeData = { label: 'hackage' } diff --git a/services/hackernews/hackernews-user-karma.service.js b/services/hackernews/hackernews-user-karma.service.js index 8d37f841f37b4..7444662a4ffef 100644 --- a/services/hackernews/hackernews-user-karma.service.js +++ b/services/hackernews/hackernews-user-karma.service.js @@ -1,6 +1,6 @@ import Joi from 'joi' import { metric } from '../text-formatters.js' -import { BaseJsonService, NotFound } from '../index.js' +import { BaseJsonService, NotFound, pathParams } from '../index.js' import { anyInteger } from '../validators.js' const schema = Joi.object({ @@ -17,13 +17,17 @@ export default class HackerNewsUserKarma extends BaseJsonService { pattern: ':id', } - static examples = [ - { - title: 'HackerNews User Karma', - namedParams: { id: 'pg' }, - staticPreview: this.render({ id: 'pg', karma: 15536 }), + static openApi = { + '/hackernews/user-karma/{id}': { + get: { + summary: 'HackerNews User Karma', + parameters: pathParams({ + name: 'id', + example: 'pg', + }), + }, }, - ] + } static defaultBadgeData = { label: 'Karma', diff --git a/services/homebrew/homebrew-cask.service.js b/services/homebrew/homebrew-cask.service.js index bb08a435b4ed1..555b6f76f945a 100644 --- a/services/homebrew/homebrew-cask.service.js +++ b/services/homebrew/homebrew-cask.service.js @@ -1,6 +1,6 @@ import Joi from 'joi' import { renderVersionBadge } from '../version.js' -import { BaseJsonService } from '../index.js' +import { BaseJsonService, pathParams } from '../index.js' const schema = Joi.object({ version: Joi.string().required(), @@ -10,13 +10,17 @@ export default class HomebrewCask extends BaseJsonService { static category = 'version' static route = { base: 'homebrew/cask/v', pattern: ':cask' } - static examples = [ - { - title: 'homebrew cask', - namedParams: { cask: 'iterm2' }, - staticPreview: renderVersionBadge({ version: 'v3.2.5' }), + static openApi = { + '/homebrew/cask/v/{cask}': { + get: { + summary: 'homebrew cask', + parameters: pathParams({ + name: 'cask', + example: 'iterm2', + }), + }, }, - ] + } static defaultBadgeData = { label: 'homebrew cask' } diff --git a/services/homebrew/homebrew-version.service.js b/services/homebrew/homebrew-version.service.js index f32e77e518d76..ffb4e136a4d16 100644 --- a/services/homebrew/homebrew-version.service.js +++ b/services/homebrew/homebrew-version.service.js @@ -1,6 +1,6 @@ import Joi from 'joi' import { renderVersionBadge } from '../version.js' -import { BaseJsonService } from '../index.js' +import { BaseJsonService, pathParams } from '../index.js' const schema = Joi.object({ versions: Joi.object({ @@ -13,13 +13,17 @@ export default class HomebrewVersion extends BaseJsonService { static route = { base: 'homebrew/v', pattern: ':formula' } - static examples = [ - { - title: 'homebrew version', - namedParams: { formula: 'cake' }, - staticPreview: renderVersionBadge({ version: 'v0.32.0' }), + static openApi = { + '/homebrew/v/{formula}': { + get: { + summary: 'homebrew version', + parameters: pathParams({ + name: 'formula', + example: 'cake', + }), + }, }, - ] + } static defaultBadgeData = { label: 'homebrew' }