* prototype fix msrv using yanked versions * make it prettier * deduplicate schema definition and add version info helper function * use newest version only if it wasnt yanked * fix variable name typo * remove unused import * try add new test * satisfy linter * don't import "describe()" * fixup --------- Co-authored-by: chris48s <git@chris-shaw.dev>
28 lines
741 B
JavaScript
28 lines
741 B
JavaScript
import { renderVersionBadge } from '../version.js'
|
|
import { pathParams } from '../index.js'
|
|
import { BaseCratesService, description } from './crates-base.js'
|
|
|
|
export default class CratesVersion extends BaseCratesService {
|
|
static category = 'version'
|
|
static route = { base: 'crates/v', pattern: ':crate' }
|
|
|
|
static openApi = {
|
|
'/crates/v/{crate}': {
|
|
get: {
|
|
summary: 'Crates.io Version',
|
|
description,
|
|
parameters: pathParams({
|
|
name: 'crate',
|
|
example: 'rustc-serialize',
|
|
}),
|
|
},
|
|
},
|
|
}
|
|
|
|
async handle({ crate }) {
|
|
const json = await this.fetch({ crate })
|
|
const version = this.constructor.getLatestVersion(json)
|
|
return renderVersionBadge({ version })
|
|
}
|
|
}
|