Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrate examples to openApi part 13; affects [curseforge date fedora hsts modrinth ore] #9499

Merged
merged 3 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions services/curseforge/curseforge-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const schema = Joi.object({
}).required(),
}).required()

const documentation = `
const description = `
<p>
The CurseForge badge requires the <code>Project ID</code> in order access the
<a href="https://docs.curseforge.com/#get-mod" target="_blank">CurseForge API</a>.
Expand Down Expand Up @@ -58,4 +58,4 @@ export default class BaseCurseForgeService extends BaseJsonService {
}
}

export { BaseCurseForgeService, documentation }
export { BaseCurseForgeService, description }
21 changes: 12 additions & 9 deletions services/curseforge/curseforge-downloads.service.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { pathParams } from '../index.js'
import { renderDownloadsBadge } from '../downloads.js'
import BaseCurseForgeService, { documentation } from './curseforge-base.js'
import BaseCurseForgeService, { description } from './curseforge-base.js'

export default class CurseForgeDownloads extends BaseCurseForgeService {
static category = 'downloads'
Expand All @@ -9,16 +10,18 @@ export default class CurseForgeDownloads extends BaseCurseForgeService {
pattern: ':projectId',
}

static examples = [
{
title: 'CurseForge Downloads',
namedParams: {
projectId: '238222',
static openApi = {
'/curseforge/dt/{projectId}': {
get: {
summary: 'CurseForge Downloads',
description,
parameters: pathParams({
name: 'projectId',
example: '238222',
}),
},
staticPreview: renderDownloadsBadge({ downloads: 234000000 }),
documentation,
},
]
}

static defaultBadgeData = { label: 'downloads' }

Expand Down
21 changes: 12 additions & 9 deletions services/curseforge/curseforge-game-versions.service.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import BaseCurseForgeService, { documentation } from './curseforge-base.js'
import { pathParams } from '../index.js'
import BaseCurseForgeService, { description } from './curseforge-base.js'

export default class CurseForgeGameVersions extends BaseCurseForgeService {
static category = 'platform-support'
Expand All @@ -8,16 +9,18 @@ export default class CurseForgeGameVersions extends BaseCurseForgeService {
pattern: ':projectId',
}

static examples = [
{
title: 'CurseForge Game Versions',
namedParams: {
projectId: '238222',
static openApi = {
'/curseforge/game-versions/{projectId}': {
get: {
summary: 'CurseForge Game Versions',
description,
parameters: pathParams({
name: 'projectId',
example: '238222',
}),
},
staticPreview: this.render({ versions: ['1.20.0', '1.19.4'] }),
documentation,
},
]
}

static defaultBadgeData = { label: 'game versions' }

Expand Down
23 changes: 12 additions & 11 deletions services/curseforge/curseforge-version.service.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { pathParams } from '../index.js'
import { renderVersionBadge } from '../version.js'
import BaseCurseForgeService, { documentation } from './curseforge-base.js'
import BaseCurseForgeService, { description } from './curseforge-base.js'

export default class CurseForgeVersion extends BaseCurseForgeService {
static category = 'version'
Expand All @@ -9,18 +10,18 @@ export default class CurseForgeVersion extends BaseCurseForgeService {
pattern: ':projectId',
}

static examples = [
{
title: 'CurseForge Version',
namedParams: {
projectId: '238222',
static openApi = {
'/curseforge/v/{projectId}': {
get: {
summary: 'CurseForge Version',
description,
parameters: pathParams({
name: 'projectId',
example: '238222',
}),
},
staticPreview: renderVersionBadge({
version: 'jei-1.20-forge-14.0.0.4.jar',
}),
documentation,
},
]
}

static defaultBadgeData = { label: 'version' }

Expand Down
24 changes: 13 additions & 11 deletions services/date/date.service.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { formatRelativeDate } from '../text-formatters.js'
import { BaseService } from '../index.js'
import { BaseService, pathParams } from '../index.js'

const documentation = `
const description = `
<p>
Supply a unix timestamp in seconds to display the relative time from/to now
</p>
Expand All @@ -11,16 +11,18 @@ export default class Date extends BaseService {
static category = 'other'
static route = { base: 'date', pattern: ':timestamp(-?[0-9]+)' }

static examples = [
{
title: 'Relative date',
pattern: ':timestamp',
namedParams: { timestamp: '1540814400' },
staticPreview: this.render({ relativeDateString: '2 days ago' }),
keywords: ['time', 'countdown', 'countup', 'moment'],
documentation,
static openApi = {
'/date/{timestamp}': {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just now realizing (or perhaps have just forgotten) that I'm not sure if/how we're doing any parameter validation on the frontend badge builder in the new ui 🤔

More of a reminder/edification question, definitely non-blocking

Copy link
Member Author

@chris48s chris48s Nov 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is the relevant bit of validation:

// ensure openApi spec matches route
if (this.openApi) {
const preparedRoute = prepareRoute(this.route)
for (const [key, value] of Object.entries(this.openApi)) {
let example = key
for (const param of value.get.parameters) {
example = example.replace(`{${param.name}}`, param.example)
}
if (!example.match(preparedRoute.regex)) {
throw new Error(
`Inconsistent Open Api spec and Route found for service ${this.name}`,
)
}
}
}
}

Added in #9320 in response to #9320 (comment)

Does that cover what you were thinking of here?

get: {
summary: 'Relative date',
description,
parameters: pathParams({
name: 'timestamp',
example: '1540814400',
}),
},
},
]
}

static defaultBadgeData = { label: 'date' }

Expand Down
40 changes: 31 additions & 9 deletions services/fedora/fedora.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({
version: Joi.string().required(),
Expand All @@ -9,18 +9,40 @@ const schema = Joi.object({
// No way to permalink to current "stable", https://pagure.io/mdapi/issue/69
const defaultBranch = 'rawhide'

const description =
'See <a href="https://apps.fedoraproject.org/mdapi/">mdapi docs</a> for information on valid branches.'

export default class Fedora extends BaseJsonService {
static category = 'version'
static route = { base: 'fedora/v', pattern: ':packageName/:branch?' }
static examples = [
{
title: 'Fedora package',
namedParams: { packageName: 'rpm', branch: 'rawhide' },
staticPreview: renderVersionBadge({ version: '4.14.2.1' }),
documentation:
'See <a href="https://apps.fedoraproject.org/mdapi/">mdapi docs</a> for information on valid branches.',
static openApi = {
'/fedora/v/{packageName}/{branch}': {
get: {
summary: 'Fedora package (with branch)',
description,
parameters: pathParams(
{
name: 'packageName',
example: 'rpm',
},
{
name: 'branch',
example: 'rawhide',
},
),
},
},
]
'/fedora/v/{packageName}': {
get: {
summary: 'Fedora package',
description,
parameters: pathParams({
name: 'packageName',
example: 'rpm',
}),
},
},
}

static defaultBadgeData = { label: 'fedora' }

Expand Down
24 changes: 14 additions & 10 deletions services/hsts/hsts.service.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import Joi from 'joi'
import { BaseJsonService } from '../index.js'
import { BaseJsonService, pathParams } from '../index.js'

const label = 'hsts preloaded'
const schema = Joi.object({
status: Joi.string().required(),
}).required()

const documentation = `
const description = `
[\`Strict-Transport-Security\` is an HTTP response header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Strict-Transport-Security)
that signals that browsers should only access the site using HTTPS.
Expand All @@ -24,15 +25,18 @@ export default class HSTS extends BaseJsonService {
pattern: ':domain',
}

static examples = [
{
title: 'Chromium HSTS preload',
namedParams: { domain: 'github.com' },
staticPreview: this.render({ status: 'preloaded' }),
keywords: ['security'],
documentation,
static openApi = {
'/hsts/preload/{domain}': {
get: {
summary: 'Chromium HSTS preload',
description,
parameters: pathParams({
name: 'domain',
example: 'github.com',
}),
},
},
]
}

static render({ status }) {
let color = 'red'
Expand Down
4 changes: 2 additions & 2 deletions services/modrinth/modrinth-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const versionSchema = Joi.array()
)
.required()

const documentation =
const description =
"<p>You can use your project slug, or the project ID. The ID can be found in the 'Technical information' section of your Modrinth page.</p>"

class BaseModrinthService extends BaseJsonService {
Expand All @@ -36,4 +36,4 @@ class BaseModrinthService extends BaseJsonService {
}
}

export { BaseModrinthService, documentation }
export { BaseModrinthService, description }
21 changes: 13 additions & 8 deletions services/modrinth/modrinth-downloads.service.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { pathParams } from '../index.js'
import { renderDownloadsBadge } from '../downloads.js'
import { BaseModrinthService, documentation } from './modrinth-base.js'
import { BaseModrinthService, description } from './modrinth-base.js'

export default class ModrinthDownloads extends BaseModrinthService {
static category = 'downloads'
Expand All @@ -9,14 +10,18 @@ export default class ModrinthDownloads extends BaseModrinthService {
pattern: ':projectId',
}

static examples = [
{
title: 'Modrinth Downloads',
namedParams: { projectId: 'AANobbMI' },
staticPreview: renderDownloadsBadge({ downloads: 120000 }),
documentation,
static openApi = {
'/modrinth/dt/{projectId}': {
get: {
summary: 'Modrinth Downloads',
description,
parameters: pathParams({
name: 'projectId',
example: 'AANobbMI',
}),
},
},
]
}

static defaultBadgeData = { label: 'downloads' }

Expand Down
24 changes: 13 additions & 11 deletions services/modrinth/modrinth-followers.service.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { pathParams } from '../index.js'
import { metric } from '../text-formatters.js'
import { BaseModrinthService, documentation } from './modrinth-base.js'
import { BaseModrinthService, description } from './modrinth-base.js'

export default class ModrinthFollowers extends BaseModrinthService {
static category = 'social'
Expand All @@ -9,17 +10,18 @@ export default class ModrinthFollowers extends BaseModrinthService {
pattern: ':projectId',
}

static examples = [
{
title: 'Modrinth Followers',
namedParams: { projectId: 'AANobbMI' },
staticPreview: Object.assign(this.render({ followers: 176 }), {
label: 'Followers',
style: 'social',
}),
documentation,
static openApi = {
'/modrinth/followers/{projectId}': {
get: {
summary: 'Modrinth Followers',
description,
parameters: pathParams({
name: 'projectId',
example: 'AANobbMI',
}),
},
},
]
}

static defaultBadgeData = { label: 'followers' }

Expand Down
21 changes: 13 additions & 8 deletions services/modrinth/modrinth-game-versions.service.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { BaseModrinthService, documentation } from './modrinth-base.js'
import { pathParams } from '../index.js'
import { BaseModrinthService, description } from './modrinth-base.js'

export default class ModrinthGameVersions extends BaseModrinthService {
static category = 'platform-support'
Expand All @@ -8,14 +9,18 @@ export default class ModrinthGameVersions extends BaseModrinthService {
pattern: ':projectId',
}

static examples = [
{
title: 'Modrinth Game Versions',
namedParams: { projectId: 'AANobbMI' },
staticPreview: this.render({ versions: ['1.19.2', '1.19.1', '1.19'] }),
documentation,
static openApi = {
'/modrinth/game-versions/{projectId}': {
get: {
summary: 'Modrinth Game Versions',
description,
parameters: pathParams({
name: 'projectId',
example: 'AANobbMI',
}),
},
},
]
}

static defaultBadgeData = { label: 'game versions' }

Expand Down
Loading
Loading