1
0
mirror of https://github.com/badges/shields.git synced 2025-04-18 19:44:04 +03:00

migrate examples to openApi part 2; affects [archlinux bitcomponents bountysource cdnjs chrome clearlydefined clojars cocoapods coincap] (#9428)

* convert an example that doesn't matter

* migrate some services from examples to openApi

* improve and de-dupe service titles

* revert changes to codefactor
This commit is contained in:
chris48s 2023-08-09 00:57:47 +01:00 committed by GitHub
parent 7d966ab6bd
commit b2f47a3303
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 209 additions and 122 deletions

View File

@ -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({
pkgver: Joi.string().required(),
@ -13,17 +13,27 @@ export default class ArchLinux extends BaseJsonService {
pattern: ':repository/:architecture/:packageName',
}
static examples = [
{
title: 'Arch Linux package',
namedParams: {
architecture: 'x86_64',
repository: 'core',
packageName: 'pacman',
static openApi = {
'/archlinux/v/{repository}/{architecture}/{packageName}': {
get: {
summary: 'Arch Linux package',
parameters: pathParams(
{
name: 'repository',
example: 'core',
},
{
name: 'architecture',
example: 'x86_64',
},
{
name: 'packageName',
example: 'pacman',
},
),
},
staticPreview: renderVersionBadge({ version: '5.1.3' }),
},
]
}
static defaultBadgeData = { label: 'arch linux' }

View File

@ -2,7 +2,7 @@ import Joi from 'joi'
import { metric } from '../text-formatters.js'
import { nonNegativeInteger } from '../validators.js'
import { downloadCount } from '../color-formatters.js'
import { BaseJsonService } from '../index.js'
import { BaseJsonService, pathParams } from '../index.js'
const collectionSchema = Joi.object({
payload: Joi.object({
@ -17,14 +17,23 @@ export default class BitComponents extends BaseJsonService {
pattern: ':owner/:collection',
}
static examples = [
{
title: 'bit',
namedParams: { owner: 'ramda', collection: 'ramda' },
staticPreview: this.render({ count: 330 }),
keywords: ['components'],
static openApi = {
'/bit/collection/total-components/{owner}/{collection}': {
get: {
summary: 'Bit',
parameters: pathParams(
{
name: 'owner',
example: 'ramda',
},
{
name: 'collection',
example: 'ramda',
},
),
},
},
]
}
static defaultBadgeData = { label: 'components' }

View File

@ -1,6 +1,6 @@
import Joi from 'joi'
import { metric } from '../text-formatters.js'
import { BaseJsonService } from '../index.js'
import { BaseJsonService, pathParams } from '../index.js'
const schema = Joi.object({ activity_total: Joi.number().required() })
@ -8,13 +8,17 @@ export default class Bountysource extends BaseJsonService {
static category = 'funding'
static route = { base: 'bountysource/team', pattern: ':team/activity' }
static examples = [
{
title: 'Bountysource',
namedParams: { team: 'mozilla-core' },
staticPreview: this.render({ total: 53000 }),
static openApi = {
'/bountysource/team/{team}/activity': {
get: {
summary: 'Bountysource',
parameters: pathParams({
name: 'team',
example: 'mozilla-core',
}),
},
},
]
}
static defaultBadgeData = { label: 'bounties' }

View File

@ -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 cdnjsSchema = Joi.object({
// optional due to non-standard 'not found' condition
@ -11,12 +11,17 @@ export default class Cdnjs extends BaseJsonService {
static category = 'version'
static route = { base: 'cdnjs/v', pattern: ':library' }
static examples = [
{
namedParams: { library: 'jquery' },
staticPreview: this.render({ version: '1.5.2' }),
static openApi = {
'/cdnjs/v/{library}': {
get: {
summary: 'Cdnjs',
parameters: pathParams({
name: 'library',
example: 'jquery',
}),
},
},
]
}
static defaultBadgeData = { label: 'cdnjs' }

View File

@ -1,18 +1,22 @@
import { currencyFromCode } from '../text-formatters.js'
import { NotFound } from '../index.js'
import { NotFound, pathParams } from '../index.js'
import BaseChromeWebStoreService from './chrome-web-store-base.js'
export default class ChromeWebStorePrice extends BaseChromeWebStoreService {
static category = 'funding'
static route = { base: 'chrome-web-store/price', pattern: ':storeId' }
static examples = [
{
title: 'Chrome Web Store',
namedParams: { storeId: 'ogffaloegjglncjfehdfplabnoondfjo' },
staticPreview: this.render({ priceCurrency: 'USD', price: 0 }),
static openApi = {
'/chrome-web-store/price/{storeId}': {
get: {
summary: 'Chrome Web Store Price',
parameters: pathParams({
name: 'storeId',
example: 'ogffaloegjglncjfehdfplabnoondfjo',
}),
},
},
]
}
static defaultBadgeData = { label: 'price' }

View File

@ -1,18 +1,22 @@
import { renderDownloadsBadge } from '../downloads.js'
import { redirector, NotFound } from '../index.js'
import { redirector, NotFound, pathParams } from '../index.js'
import BaseChromeWebStoreService from './chrome-web-store-base.js'
class ChromeWebStoreUsers extends BaseChromeWebStoreService {
static category = 'downloads'
static route = { base: 'chrome-web-store/users', pattern: ':storeId' }
static examples = [
{
title: 'Chrome Web Store',
namedParams: { storeId: 'ogffaloegjglncjfehdfplabnoondfjo' },
staticPreview: renderDownloadsBadge({ downloads: 573 }),
static openApi = {
'/chrome-web-store/users/{storeId}': {
get: {
summary: 'Chrome Web Store Users',
parameters: pathParams({
name: 'storeId',
example: 'ogffaloegjglncjfehdfplabnoondfjo',
}),
},
},
]
}
static defaultBadgeData = { label: 'users' }

View File

@ -1,18 +1,22 @@
import { renderVersionBadge } from '../version.js'
import { NotFound } from '../index.js'
import { NotFound, pathParams } from '../index.js'
import BaseChromeWebStoreService from './chrome-web-store-base.js'
export default class ChromeWebStoreVersion extends BaseChromeWebStoreService {
static category = 'version'
static route = { base: 'chrome-web-store/v', pattern: ':storeId' }
static examples = [
{
title: 'Chrome Web Store',
namedParams: { storeId: 'ogffaloegjglncjfehdfplabnoondfjo' },
staticPreview: renderVersionBadge({ version: 'v1.1.0' }),
static openApi = {
'/chrome-web-store/v/{storeId}': {
get: {
summary: 'Chrome Web Store Version',
parameters: pathParams({
name: 'storeId',
example: 'ogffaloegjglncjfehdfplabnoondfjo',
}),
},
},
]
}
static defaultBadgeData = { label: 'chrome web store' }

View File

@ -4,7 +4,7 @@ import {
optionalNonNegativeInteger,
} from '../validators.js'
import { floorCount as floorCountColor } from '../color-formatters.js'
import { BaseJsonService, NotFound } from '../index.js'
import { BaseJsonService, NotFound, pathParams } from '../index.js'
const schema = Joi.object({
scores: Joi.object({
@ -24,19 +24,35 @@ export default class ClearlyDefinedService extends BaseJsonService {
pattern: 'score/:type/:provider/:namespace/:name/:revision',
}
static examples = [
{
title: 'ClearlyDefined Score',
namedParams: {
type: 'npm',
provider: 'npmjs',
namespace: '-',
name: 'jquery',
revision: '3.4.1',
static openApi = {
'/clearlydefined/score/{type}/{provider}/{namespace}/{name}/{revision}': {
get: {
summary: 'ClearlyDefined Score',
parameters: pathParams(
{
name: 'type',
example: 'npm',
},
{
name: 'provider',
example: 'npmjs',
},
{
name: 'namespace',
example: '-',
},
{
name: 'name',
example: 'jquery',
},
{
name: 'revision',
example: '3.4.1',
},
),
},
staticPreview: this.render({ score: 88 }),
},
]
}
static defaultBadgeData = { label: 'score' }

View File

@ -1,3 +1,4 @@
import { pathParams } from '../index.js'
import { renderDownloadsBadge } from '../downloads.js'
import { BaseClojarsService } from './clojars-base.js'
@ -5,12 +6,17 @@ export default class ClojarsDownloads extends BaseClojarsService {
static category = 'downloads'
static route = { base: 'clojars/dt', pattern: ':clojar+' }
static examples = [
{
namedParams: { clojar: 'prismic' },
staticPreview: renderDownloadsBadge({ downloads: 117 }),
static openApi = {
'/clojars/dt/{clojar}': {
get: {
summary: 'Clojars Downloads',
parameters: pathParams({
name: 'clojar',
example: 'prismic',
}),
},
},
]
}
static defaultBadgeData = { label: 'downloads' }

View File

@ -1,6 +1,6 @@
import Joi from 'joi'
import { coveragePercentage as coveragePercentageColor } from '../color-formatters.js'
import { BaseJsonService } from '../index.js'
import { BaseJsonService, pathParams } from '../index.js'
const schema = Joi.object({
cocoadocs: Joi.object({
@ -12,13 +12,17 @@ export default class CocoapodsDocs extends BaseJsonService {
static category = 'analysis'
static route = { base: 'cocoapods/metrics/doc-percent', pattern: ':spec' }
static examples = [
{
title: 'Cocoapods doc percentage',
namedParams: { spec: 'AFNetworking' },
staticPreview: this.render({ percentage: 94 }),
static openApi = {
'/cocoapods/metrics/doc-percent/{spec}': {
get: {
summary: 'Cocoapods doc percentage',
parameters: pathParams({
name: 'spec',
example: 'AFNetworking',
}),
},
},
]
}
static defaultBadgeData = { label: 'docs' }

View File

@ -1,16 +1,21 @@
import { pathParams } from '../index.js'
import BaseCocoaPodsService from './cocoapods-base.js'
export default class CocoapodsLicense extends BaseCocoaPodsService {
static category = 'license'
static route = { base: 'cocoapods/l', pattern: ':spec' }
static examples = [
{
title: 'Cocoapods',
namedParams: { spec: 'AFNetworking' },
staticPreview: this.render({ license: 'MIT' }),
static openApi = {
'/cocoapods/l/{spec}': {
get: {
summary: 'Cocoapods License',
parameters: pathParams({
name: 'spec',
example: 'AFNetworking',
}),
},
},
]
}
static defaultBadgeData = { label: 'license' }

View File

@ -1,18 +1,21 @@
import { pathParams } from '../index.js'
import BaseCocoaPodsService from './cocoapods-base.js'
export default class CocoapodsPlatform extends BaseCocoaPodsService {
static category = 'platform-support'
static route = { base: 'cocoapods/p', pattern: ':spec' }
static examples = [
{
title: 'Cocoapods platforms',
namedParams: { spec: 'AFNetworking' },
staticPreview: this.render({
platforms: ['ios', 'osx', 'watchos', 'tvos'],
}),
static openApi = {
'/cocoapods/p/{spec}': {
get: {
summary: 'Cocoapods platforms',
parameters: pathParams({
name: 'spec',
example: 'AFNetworking',
}),
},
},
]
}
static defaultBadgeData = { label: 'platform' }

View File

@ -1,3 +1,4 @@
import { pathParams } from '../index.js'
import { renderVersionBadge } from '../version.js'
import BaseCocoaPodsService from './cocoapods-base.js'
@ -5,13 +6,17 @@ export default class CocoapodsVersion extends BaseCocoaPodsService {
static category = 'version'
static route = { base: 'cocoapods/v', pattern: ':spec' }
static examples = [
{
title: 'Cocoapods',
namedParams: { spec: 'AFNetworking' },
staticPreview: renderVersionBadge({ version: 'v3.2.1' }),
static openApi = {
'/cocoapods/v/{spec}': {
get: {
summary: 'Cocoapods Version',
parameters: pathParams({
name: 'spec',
example: 'AFNetworking',
}),
},
},
]
}
static defaultBadgeData = { label: 'pod' }

View File

@ -1,4 +1,5 @@
import Joi from 'joi'
import { pathParams } from '../index.js'
import { floorCount } from '../color-formatters.js'
import BaseCoincapService from './coincap-base.js'
@ -14,16 +15,17 @@ const schema = Joi.object({
export default class CoincapChangePercent24HrUsd extends BaseCoincapService {
static route = { base: 'coincap/change-percent-24hr', pattern: ':assetId' }
static examples = [
{
title: 'Coincap (Change Percent 24Hr)',
namedParams: { assetId: 'bitcoin' },
staticPreview: this.render({
asset: { name: 'bitcoin', changePercent24Hr: '2.0670573674501840"' },
}),
keywords: ['bitcoin', 'crypto', 'cryptocurrency'],
static openApi = {
'/coincap/change-percent-24hr/{assetId}': {
get: {
summary: 'Coincap (Change Percent 24Hr)',
parameters: pathParams({
name: 'assetId',
example: 'bitcoin',
}),
},
},
]
}
static percentFormat(changePercent24Hr) {
return `${parseInt(changePercent24Hr).toFixed(2)}%`

View File

@ -1,4 +1,5 @@
import Joi from 'joi'
import { pathParams } from '../index.js'
import BaseCoincapService from './coincap-base.js'
const schema = Joi.object({
@ -13,16 +14,17 @@ const schema = Joi.object({
export default class CoincapPriceUsd extends BaseCoincapService {
static route = { base: 'coincap/price-usd', pattern: ':assetId' }
static examples = [
{
title: 'Coincap (Price USD)',
namedParams: { assetId: 'bitcoin' },
staticPreview: this.render({
asset: { name: 'bitcoin', priceUsd: '19116.0479117336250772' },
}),
keywords: ['bitcoin', 'crypto', 'cryptocurrency'],
static openApi = {
'/coincap/price-usd/{assetId}': {
get: {
summary: 'Coincap (Price USD)',
parameters: pathParams({
name: 'assetId',
example: 'bitcoin',
}),
},
},
]
}
static priceFormat(price) {
return `$${parseFloat(price)

View File

@ -1,4 +1,5 @@
import Joi from 'joi'
import { pathParams } from '../index.js'
import BaseCoincapService from './coincap-base.js'
const schema = Joi.object({
@ -13,14 +14,17 @@ const schema = Joi.object({
export default class CoincapRank extends BaseCoincapService {
static route = { base: 'coincap/rank', pattern: ':assetId' }
static examples = [
{
title: 'Coincap (Rank)',
namedParams: { assetId: 'bitcoin' },
staticPreview: this.render({ asset: { name: 'bitcoin', rank: '1' } }),
keywords: ['bitcoin', 'crypto', 'cryptocurrency'],
static openApi = {
'/coincap/rank/{assetId}': {
get: {
summary: 'Coincap (Rank)',
parameters: pathParams({
name: 'assetId',
example: 'bitcoin',
}),
},
},
]
}
static render({ asset }) {
return {

View File

@ -8,7 +8,7 @@ export default class DeprecatedGithubWorkflowStatus extends BaseService {
pattern: ':various+',
}
static examples = []
static openApi = {}
static defaultBadgeData = { label: 'build' }