-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
migrate some services from examples to openApi (#9841)
- Loading branch information
Showing
9 changed files
with
100 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 39 additions & 50 deletions
89
services/eclipse-marketplace/eclipse-marketplace-downloads.service.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,58 @@ | ||
import Joi from 'joi' | ||
import { renderDownloadsBadge } from '../downloads.js' | ||
import { pathParams } from '../index.js' | ||
import { nonNegativeInteger } from '../validators.js' | ||
import EclipseMarketplaceBase from './eclipse-marketplace-base.js' | ||
|
||
const monthlyResponseSchema = Joi.object({ | ||
const downloadsResponseSchema = Joi.object({ | ||
marketplace: Joi.object({ | ||
node: Joi.object({ | ||
installsrecent: nonNegativeInteger, | ||
}), | ||
}), | ||
}).required() | ||
|
||
const totalResponseSchema = Joi.object({ | ||
marketplace: Joi.object({ | ||
node: Joi.object({ | ||
installstotal: nonNegativeInteger, | ||
}), | ||
}), | ||
}).required() | ||
|
||
function DownloadsForInterval(downloadsInterval) { | ||
const { | ||
base, | ||
schema, | ||
interval = '', | ||
name, | ||
} = { | ||
month: { | ||
base: 'eclipse-marketplace/dm', | ||
interval: 'month', | ||
schema: monthlyResponseSchema, | ||
name: 'EclipseMarketplaceDownloadsMonth', | ||
}, | ||
total: { | ||
base: 'eclipse-marketplace/dt', | ||
schema: totalResponseSchema, | ||
name: 'EclipseMarketplaceDownloadsTotal', | ||
}, | ||
}[downloadsInterval] | ||
export default class EclipseMarketplaceDownloads extends EclipseMarketplaceBase { | ||
static category = 'downloads' | ||
static route = { | ||
base: 'eclipse-marketplace', | ||
pattern: ':interval(dm|dt)/:name', | ||
} | ||
|
||
return class EclipseMarketplaceDownloads extends EclipseMarketplaceBase { | ||
static name = name | ||
static category = 'downloads' | ||
static route = this.buildRoute(base) | ||
static examples = [ | ||
{ | ||
title: 'Eclipse Marketplace', | ||
namedParams: { name: 'notepad4e' }, | ||
staticPreview: this.render({ downloads: 30000 }), | ||
static openApi = { | ||
'/eclipse-marketplace/{interval}/{name}': { | ||
get: { | ||
summary: 'Eclipse Marketplace Downloads', | ||
parameters: pathParams( | ||
{ | ||
name: 'interval', | ||
example: 'dt', | ||
schema: { type: 'string', enum: this.getEnum('interval') }, | ||
}, | ||
{ | ||
name: 'name', | ||
example: 'planet-themes', | ||
}, | ||
), | ||
}, | ||
] | ||
}, | ||
} | ||
|
||
static render({ downloads }) { | ||
return renderDownloadsBadge({ downloads, interval }) | ||
} | ||
static render({ interval, downloads }) { | ||
const intervalString = interval === 'dm' ? 'month' : null | ||
return renderDownloadsBadge({ downloads, interval: intervalString }) | ||
} | ||
|
||
async handle({ name }) { | ||
const { marketplace } = await this.fetch({ name, schema }) | ||
const downloads = | ||
downloadsInterval === 'total' | ||
? marketplace.node.installstotal | ||
: marketplace.node.installsrecent | ||
return this.constructor.render({ downloads }) | ||
} | ||
async handle({ interval, name }) { | ||
const { marketplace } = await this.fetch({ | ||
schema: downloadsResponseSchema, | ||
name, | ||
}) | ||
const downloads = | ||
interval === 'dt' | ||
? marketplace.node.installstotal | ||
: marketplace.node.installsrecent | ||
return this.constructor.render({ downloads, interval }) | ||
} | ||
} | ||
|
||
export default ['month', 'total'].map(DownloadsForInterval) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters