Skip to content

Commit

Permalink
migrate examples to openApi part 2; affects [archlinux bitcompone…
Browse files Browse the repository at this point in the history
…nts bountysource cdnjs chrome clearlydefined clojars cocoapods coincap] (badges#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
  • Loading branch information
chris48s authored and nyurik committed Aug 9, 2023
1 parent 7a3e924 commit f950851
Show file tree
Hide file tree
Showing 17 changed files with 209 additions and 122 deletions.
30 changes: 20 additions & 10 deletions services/archlinux/archlinux.service.js
Original file line number Diff line number Diff line change
@@ -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(),
Expand All @@ -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' }

Expand Down
25 changes: 17 additions & 8 deletions services/bit/bit-components.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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' }

Expand Down
18 changes: 11 additions & 7 deletions services/bountysource/bountysource.service.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
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() })

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' }

Expand Down
17 changes: 11 additions & 6 deletions services/cdnjs/cdnjs.service.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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' }

Expand Down
18 changes: 11 additions & 7 deletions services/chrome-web-store/chrome-web-store-price.service.js
Original file line number Diff line number Diff line change
@@ -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' }

Expand Down
18 changes: 11 additions & 7 deletions services/chrome-web-store/chrome-web-store-users.service.js
Original file line number Diff line number Diff line change
@@ -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' }

Expand Down
18 changes: 11 additions & 7 deletions services/chrome-web-store/chrome-web-store-version.service.js
Original file line number Diff line number Diff line change
@@ -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' }

Expand Down
40 changes: 28 additions & 12 deletions services/clearlydefined/clearlydefined-score.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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' }

Expand Down
16 changes: 11 additions & 5 deletions services/clojars/clojars-downloads.service.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
import { pathParams } from '../index.js'
import { renderDownloadsBadge } from '../downloads.js'
import { BaseClojarsService } from './clojars-base.js'

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' }

Expand Down
18 changes: 11 additions & 7 deletions services/cocoapods/cocoapods-docs.service.js
Original file line number Diff line number Diff line change
@@ -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({
Expand All @@ -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' }

Expand Down
17 changes: 11 additions & 6 deletions services/cocoapods/cocoapods-license.service.js
Original file line number Diff line number Diff line change
@@ -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' }

Expand Down
Loading

0 comments on commit f950851

Please sign in to comment.