Skip to content

Commit

Permalink
migrate examples to openApi part 3; affects [conan cookbook cover…
Browse files Browse the repository at this point in the history
…ity cpan debian docker docsrs dub eclipse] (#9429)

* migrate some services from examples to openApi

* improve and de-dupe service titles

* revert changes to depfu
  • Loading branch information
chris48s authored Aug 17, 2023
1 parent 61b8446 commit 478b108
Show file tree
Hide file tree
Showing 16 changed files with 225 additions and 118 deletions.
18 changes: 11 additions & 7 deletions services/conan/conan-version.service.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { pathParams } from '../index.js'
import { renderVersionBadge } from '../version.js'
import { ConditionalGithubAuthV3Service } from '../github/github-auth-service.js'
import { fetchRepoContent } from '../github/github-common-fetch.js'
Expand All @@ -8,14 +9,17 @@ export default class ConanVersion extends ConditionalGithubAuthV3Service {

static route = { base: 'conan/v', pattern: ':packageName' }

static examples = [
{
title: 'Conan Center',
namedParams: { packageName: 'boost' },
staticPreview: renderVersionBadge({ version: '1.78.0' }),
keywords: ['c++'],
static openApi = {
'/conan/v/{packageName}': {
get: {
summary: 'Conan Center',
parameters: pathParams({
name: 'packageName',
example: 'boost',
}),
},
},
]
}

static defaultBadgeData = { label: 'conan' }

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

export default class Cookbook extends BaseJsonService {
static category = 'version'
static route = { base: 'cookbook/v', pattern: ':cookbook' }

static examples = [
{
title: 'Chef cookbook',
namedParams: { cookbook: 'chef-sugar' },
staticPreview: renderVersionBadge({ version: '5.0.0' }),
static openApi = {
'/cookbook/v/{cookbook}': {
get: {
summary: 'Chef cookbook',
parameters: pathParams({
name: 'cookbook',
example: 'chef-sugar',
}),
},
},
]
}

static defaultBadgeData = { label: 'cookbook' }

Expand Down
20 changes: 10 additions & 10 deletions services/coverity/coverity-scan.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'

const messageRegex = /passed|passed .* new defects|pending|failed/
const schema = Joi.object({
Expand All @@ -10,17 +10,17 @@ export default class CoverityScan extends BaseJsonService {
static category = 'analysis'
static route = { base: 'coverity/scan', pattern: ':projectId' }

static examples = [
{
title: 'Coverity Scan',
namedParams: {
projectId: '3997',
static openApi = {
'/coverity/scan/{projectId}': {
get: {
summary: 'Coverity Scan',
parameters: pathParams({
name: 'projectId',
example: '3997',
}),
},
staticPreview: this.render({
message: 'passed',
}),
},
]
}

static defaultBadgeData = { label: 'coverity' }

Expand Down
18 changes: 11 additions & 7 deletions services/cpan/cpan-license.service.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
import { pathParams } from '../index.js'
import BaseCpanService from './cpan.js'

export default class CpanLicense extends BaseCpanService {
static category = 'license'
static route = { base: 'cpan/l', pattern: ':packageName' }

static examples = [
{
title: 'CPAN',
namedParams: { packageName: 'Config-Augeas' },
staticPreview: this.render({ license: 'lgpl_2_1' }),
keywords: ['perl'],
static openApi = {
'/cpan/l/{packageName}': {
get: {
summary: 'CPAN License',
parameters: pathParams({
name: 'packageName',
example: 'Config-Augeas',
}),
},
},
]
}

static render({ license }) {
return {
Expand Down
18 changes: 11 additions & 7 deletions services/cpan/cpan-version.service.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import { pathParams } from '../index.js'
import { renderVersionBadge } from '../version.js'
import BaseCpanService from './cpan.js'

export default class CpanVersion extends BaseCpanService {
static category = 'version'
static route = { base: 'cpan/v', pattern: ':packageName' }

static examples = [
{
title: 'CPAN',
namedParams: { packageName: 'Config-Augeas' },
staticPreview: renderVersionBadge({ version: '1.000' }),
keywords: ['perl'],
static openApi = {
'/cpan/v/{packageName}': {
get: {
summary: 'CPAN Version',
parameters: pathParams({
name: 'packageName',
example: 'Config-Augeas',
}),
},
},
]
}

async handle({ packageName }) {
const { version } = await this.fetch({ packageName })
Expand Down
38 changes: 31 additions & 7 deletions services/debian/debian.service.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import Joi from 'joi'
import { latest, renderVersionBadge } from '../version.js'
import { BaseJsonService, NotFound, InvalidResponse } from '../index.js'
import {
BaseJsonService,
NotFound,
InvalidResponse,
pathParams,
} from '../index.js'

const schema = Joi.array()
.items(
Expand All @@ -23,13 +28,32 @@ export default class Debian extends BaseJsonService {
pattern: ':packageName/:distribution?',
}

static examples = [
{
title: 'Debian package',
namedParams: { packageName: 'apt', distribution: 'unstable' },
staticPreview: renderVersionBadge({ version: '1.8.0' }),
static openApi = {
'/debian/v/{packageName}/{distribution}': {
get: {
summary: 'Debian package (for distribution)',
parameters: pathParams(
{
name: 'packageName',
example: 'apt',
},
{
name: 'distribution',
example: 'unstable',
},
),
},
},
'/debian/v/{packageName}': {
get: {
summary: 'Debian package',
parameters: pathParams({
name: 'packageName',
example: 'apt',
}),
},
},
]
}

static defaultBadgeData = { label: 'debian' }

Expand Down
25 changes: 16 additions & 9 deletions services/docker/docker-automated.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 {
dockerBlue,
buildDockerUrl,
Expand All @@ -13,16 +13,23 @@ const automatedBuildSchema = Joi.object({
export default class DockerAutomatedBuild extends BaseJsonService {
static category = 'build'
static route = buildDockerUrl('automated')
static examples = [
{
title: 'Docker Automated build',
namedParams: {
user: 'jrottenberg',
repo: 'ffmpeg',
static openApi = {
'/docker/automated/{user}/{repo}': {
get: {
summary: 'Docker Automated build',
parameters: pathParams(
{
name: 'user',
example: 'jrottenberg',
},
{
name: 'repo',
example: 'ffmpeg',
},
),
},
staticPreview: this.render({ isAutomated: true }),
},
]
}

static _cacheLength = 14400

Expand Down
25 changes: 16 additions & 9 deletions services/docker/docker-pulls.service.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Joi from 'joi'
import { renderDownloadsBadge } from '../downloads.js'
import { nonNegativeInteger } from '../validators.js'
import { BaseJsonService } from '../index.js'
import { BaseJsonService, pathParams } from '../index.js'
import {
dockerBlue,
buildDockerUrl,
Expand All @@ -15,16 +15,23 @@ const pullsSchema = Joi.object({
export default class DockerPulls extends BaseJsonService {
static category = 'downloads'
static route = buildDockerUrl('pulls')
static examples = [
{
title: 'Docker Pulls',
namedParams: {
user: '_',
repo: 'ubuntu',
static openApi = {
'/docker/pulls/{user}/{repo}': {
get: {
summary: 'Docker Pulls',
parameters: pathParams(
{
name: 'user',
example: '_',
},
{
name: 'repo',
example: 'ubuntu',
},
),
},
staticPreview: this.render({ count: 765400000 }),
},
]
}

static _cacheLength = 14400

Expand Down
25 changes: 16 additions & 9 deletions services/docker/docker-stars.service.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Joi from 'joi'
import { metric } from '../text-formatters.js'
import { nonNegativeInteger } from '../validators.js'
import { BaseJsonService } from '../index.js'
import { BaseJsonService, pathParams } from '../index.js'
import {
dockerBlue,
buildDockerUrl,
Expand All @@ -15,16 +15,23 @@ const schema = Joi.object({
export default class DockerStars extends BaseJsonService {
static category = 'rating'
static route = buildDockerUrl('stars')
static examples = [
{
title: 'Docker Stars',
namedParams: {
user: '_',
repo: 'ubuntu',
static openApi = {
'/docker/stars/{user}/{repo}': {
get: {
summary: 'Docker Stars',
parameters: pathParams(
{
name: 'user',
example: '_',
},
{
name: 'repo',
example: 'ubuntu',
},
),
},
staticPreview: this.render({ stars: 9000 }),
},
]
}

static _cacheLength = 14400

Expand Down
34 changes: 26 additions & 8 deletions services/docsrs/docsrs.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'

const schema = Joi.object({
doc_status: Joi.boolean().required(),
Expand All @@ -8,14 +8,32 @@ const schema = Joi.object({
export default class DocsRs extends BaseJsonService {
static category = 'build'
static route = { base: 'docsrs', pattern: ':crate/:version?' }
static examples = [
{
title: 'docs.rs',
namedParams: { crate: 'regex', version: 'latest' },
staticPreview: this.render({ version: 'latest', docStatus: true }),
keywords: ['rust'],
static openApi = {
'/docsrs/{crate}/{version}': {
get: {
summary: 'docs.rs (with version)',
parameters: pathParams(
{
name: 'crate',
example: 'regex',
},
{
name: 'version',
example: 'latest',
},
),
},
},
]
'/docsrs/{crate}': {
get: {
summary: 'docs.rs',
parameters: pathParams({
name: 'crate',
example: 'regex',
}),
},
},
}

static defaultBadgeData = { label: 'docs' }

Expand Down
Loading

0 comments on commit 478b108

Please sign in to comment.