Skip to content

Commit

Permalink
migrate some services from examples to openApi (#9737)
Browse files Browse the repository at this point in the history
  • Loading branch information
chris48s authored Dec 24, 2023
1 parent 5024688 commit 9628fc4
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 143 deletions.
103 changes: 41 additions & 62 deletions services/bundlejs/bundlejs-package.service.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Joi from 'joi'
import { BaseJsonService } from '../index.js'
import { BaseJsonService, pathParam, queryParam } from '../index.js'

const schema = Joi.object({
size: Joi.object({
Expand All @@ -11,18 +11,16 @@ const queryParamSchema = Joi.object({
exports: Joi.string(),
}).required()

const keywords = ['node', 'bundlejs']

const esbuild =
'<a href="https://github.com/evanw/esbuild" target="_blank" rel="noopener">esbuild</a>'
const denoflate =
'<a href="https://github.com/hazae41/denoflate" target="_blank" rel="noopener">denoflate</a>'
const bundlejs =
'<a href="https://bundlejs.com/" target="_blank" rel="noopener">bundlejs</a>'

const documentation = `
const description = `
<p>
View ${esbuild} minified and ${denoflate} gzipped size of a package or selected exports, via ${bundlejs}.
View ${esbuild} minified and ${denoflate} gzipped size of a javascript package or selected exports, via ${bundlejs}.
</p>
`

Expand All @@ -35,67 +33,48 @@ export default class BundlejsPackage extends BaseJsonService {
queryParamSchema,
}

static examples = [
{
title: 'npm package minimized gzipped size',
pattern: ':packageName',
namedParams: {
packageName: 'react',
},
staticPreview: this.render({ size: '2.94 kB' }),
keywords,
documentation,
},
{
title: 'npm package minimized gzipped size (version)',
pattern: ':packageName',
namedParams: {
packageName: '[email protected]',
},
staticPreview: this.render({ size: '2.94 kB' }),
keywords,
documentation,
},
{
title: 'npm package minimized gzipped size (scoped)',
pattern: ':scope/:packageName',
namedParams: {
scope: '@cycle',
packageName: 'rx-run',
static openApi = {
'/bundlejs/size/{packageName}': {
get: {
summary: 'npm package minimized gzipped size',
description,
parameters: [
pathParam({
name: 'packageName',
example: '[email protected]',
description:
'This can either be a package name e.g: `value-enhancer`, or a package name and version e.g: `[email protected]`',
}),
queryParam({
name: 'exports',
example: 'isVal,val',
}),
],
},
staticPreview: this.render({ size: '32.3 kB' }),
keywords,
documentation,
},
{
title: 'npm package minimized gzipped size (select exports)',
pattern: ':packageName',
namedParams: {
packageName: 'value-enhancer',
'/bundlejs/size/{scope}/{packageName}': {
get: {
summary: 'npm package minimized gzipped size (scoped)',
description,
parameters: [
pathParam({
name: 'scope',
example: '@ngneat',
}),
pathParam({
name: 'packageName',
example: '[email protected]',
description:
'This can either be a package name e.g: `falso`, or a package name and version e.g: `[email protected]`',
}),
queryParam({
name: 'exports',
example: 'randEmail,randFullName',
}),
],
},
queryParams: {
exports: 'isVal,val',
},
staticPreview: this.render({ size: '823 B' }),
keywords,
documentation,
},
{
title:
'npm package minimized gzipped size (scoped version select exports)',
pattern: ':scope/:packageName',
namedParams: {
scope: '@ngneat',
packageName: '[email protected]',
},
queryParams: {
exports: 'randEmail,randFullName',
},
staticPreview: this.render({ size: '17.8 kB' }),
keywords,
documentation,
},
]
}

static defaultBadgeData = { label: 'bundlejs', color: 'informational' }

Expand Down
54 changes: 24 additions & 30 deletions services/cirrus/cirrus.service.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Joi from 'joi'
import { isBuildStatus, renderBuildStatusBadge } from '../build-status.js'
import { BaseJsonService } from '../index.js'
import { BaseJsonService, pathParam, queryParam } from '../index.js'

const schema = Joi.object({
subject: Joi.string().required(),
Expand All @@ -21,37 +21,31 @@ export default class Cirrus extends BaseJsonService {
queryParamSchema,
}

static examples = [
{
title: 'Cirrus CI - Base Branch Build Status',
namedParams: { user: 'flutter', repo: 'flutter' },
pattern: 'github/:user/:repo',
staticPreview: this.render({ status: 'passing' }),
static openApi = {
'/cirrus/github/{user}/{repo}': {
get: {
summary: 'Cirrus CI - Default Branch Build Status',
parameters: [
pathParam({ name: 'user', example: 'flutter' }),
pathParam({ name: 'repo', example: 'flutter' }),
queryParam({ name: 'task', example: 'build_docker' }),
queryParam({ name: 'script', example: 'test' }),
],
},
},
{
title: 'Cirrus CI - Specific Branch Build Status',
pattern: 'github/:user/:repo/:branch',
namedParams: { user: 'flutter', repo: 'flutter', branch: 'master' },
staticPreview: this.render({ status: 'passing' }),
'/cirrus/github/{user}/{repo}/{branch}': {
get: {
summary: 'Cirrus CI - Specific Branch Build Status',
parameters: [
pathParam({ name: 'user', example: 'flutter' }),
pathParam({ name: 'repo', example: 'flutter' }),
pathParam({ name: 'branch', example: 'master' }),
queryParam({ name: 'task', example: 'build_docker' }),
queryParam({ name: 'script', example: 'test' }),
],
},
},
{
title: 'Cirrus CI - Specific Task Build Status',
pattern: 'github/:user/:repo',
queryParams: { task: 'build_docker' },
namedParams: { user: 'flutter', repo: 'cocoon' },
staticPreview: this.render({
subject: 'build_docker',
status: 'passing',
}),
},
{
title: 'Cirrus CI - Task and Script Build Status',
pattern: 'github/:user/:repo',
queryParams: { task: 'build_docker', script: 'test' },
namedParams: { user: 'flutter', repo: 'cocoon' },
staticPreview: this.render({ subject: 'test', status: 'passing' }),
},
]
}

static defaultBadgeData = { label: 'build' }

Expand Down
70 changes: 41 additions & 29 deletions services/factorio-mod-portal/factorio-mod-portal.service.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Joi from 'joi'
import { BaseJsonService } from '../index.js'
import { BaseJsonService, pathParams } from '../index.js'
import { age } from '../color-formatters.js'
import { formatDate } from '../text-formatters.js'
import { nonNegativeInteger } from '../validators.js'
Expand Down Expand Up @@ -50,13 +50,17 @@ class FactorioModPortalLatestVersion extends BaseFactorioModPortalService {
pattern: ':modName',
}

static examples = [
{
title: 'Factorio Mod Portal mod version',
namedParams: { modName: 'rso-mod' },
staticPreview: this.render({ version: '6.2.20' }),
static openApi = {
'/factorio-mod-portal/v/{modName}': {
get: {
summary: 'Factorio Mod Portal mod version',
parameters: pathParams({
name: 'modName',
example: 'rso-mod',
}),
},
},
]
}

static defaultBadgeData = { label: 'latest version' }

Expand All @@ -79,13 +83,17 @@ class FactorioModPortalFactorioVersion extends BaseFactorioModPortalService {
pattern: ':modName',
}

static examples = [
{
title: 'Factorio Mod Portal factorio versions',
namedParams: { modName: 'rso-mod' },
staticPreview: this.render({ version: '1.1' }),
static openApi = {
'/factorio-mod-portal/factorio-version/{modName}': {
get: {
summary: 'Factorio Mod Portal factorio versions',
parameters: pathParams({
name: 'modName',
example: 'rso-mod',
}),
},
},
]
}

static defaultBadgeData = { label: 'factorio version' }

Expand All @@ -109,15 +117,17 @@ class FactorioModPortalLastUpdated extends BaseFactorioModPortalService {
pattern: ':modName',
}

static examples = [
{
title: 'Factorio Mod Portal mod',
namedParams: { modName: 'rso-mod' },
staticPreview: this.render({
lastUpdated: new Date(),
}),
static openApi = {
'/factorio-mod-portal/last-updated/{modName}': {
get: {
summary: 'Factorio Mod Portal last updated',
parameters: pathParams({
name: 'modName',
example: 'rso-mod',
}),
},
},
]
}

static defaultBadgeData = { label: 'last updated' }

Expand Down Expand Up @@ -145,15 +155,17 @@ class FactorioModPortalDownloads extends BaseFactorioModPortalService {
pattern: ':modName',
}

static examples = [
{
title: 'Factorio Mod Portal mod downloads',
namedParams: { modName: 'rso-mod' },
staticPreview: this.render({
downloads: 1694763,
}),
static openApi = {
'/factorio-mod-portal/dt/{modName}': {
get: {
summary: 'Factorio Mod Portal downloads',
parameters: pathParams({
name: 'modName',
example: 'rso-mod',
}),
},
},
]
}

static defaultBadgeData = { label: 'downloads' }

Expand Down
29 changes: 17 additions & 12 deletions services/gerrit/gerrit.service.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Joi from 'joi'
import { optionalUrl } from '../validators.js'
import { BaseJsonService } from '../index.js'
import { BaseJsonService, pathParam, queryParam } from '../index.js'

const queryParamSchema = Joi.object({
baseUrl: optionalUrl.required(),
Expand All @@ -13,19 +13,24 @@ const schema = Joi.object({
export default class Gerrit extends BaseJsonService {
static category = 'issue-tracking'
static route = { base: 'gerrit', pattern: ':changeId', queryParamSchema }
static examples = [
{
title: 'Gerrit change status',
namedParams: {
changeId: '1011478',
static openApi = {
'/gerrit/{changeId}': {
get: {
summary: 'Gerrit change status',
parameters: [
pathParam({
name: 'changeId',
example: '1011478',
}),
queryParam({
name: 'baseUrl',
example: 'https://android-review.googlesource.com',
required: true,
}),
],
},
queryParams: { baseUrl: 'https://android-review.googlesource.com' },
staticPreview: this.render({
changeId: 1011478,
status: 'MERGED',
}),
},
]
}

static defaultBadgeData = { label: 'gerrit' }

Expand Down
30 changes: 20 additions & 10 deletions services/wikiapiary/wikiapiary-installs.service.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import Joi from 'joi'
import { renderDownloadsBadge } from '../downloads.js'
import { BaseJsonService, NotFound } from '../index.js'
import { BaseJsonService, NotFound, pathParams } from '../index.js'

const documentation = `
const description = `
<p>
<a href="https://wikiapiary.com">WikiApiary</a> holds information about MediaWiki websites.
</p>
<p>
The name of an extension is case-sensitive excluding the first character.
</p>
Expand Down Expand Up @@ -52,15 +55,22 @@ export default class WikiapiaryInstalls extends BaseJsonService {
pattern: ':variant(extension|skin|farm|generator|host)/installs/:name',
}

static examples = [
{
title: 'Wikiapiary installs',
namedParams: { variant: 'extension', name: 'ParserFunctions' },
staticPreview: this.render({ usage: 11170 }),
documentation,
keywords: ['mediawiki'],
static openApi = {
'/wikiapiary/{variant}/installs/{name}': {
get: {
summary: 'Wikiapiary installs',
description,
parameters: pathParams(
{
name: 'variant',
example: 'extension',
schema: { type: 'string', enum: this.getEnum('variant') },
},
{ name: 'name', example: 'ParserFunctions' },
),
},
},
]
}

static defaultBadgeData = { label: 'installs', color: 'informational' }

Expand Down

0 comments on commit 9628fc4

Please sign in to comment.