Files
shields/services/conda/conda-license.service.js
chris48s bd288db3a4 migrate examples to openApi part 18; affects [conda feedz gem openvsx readthedocs] github (#9607)
* migrate some services from examples to openApi

* fixup which --> variant param rename

* improve descriptions

* migrate gem version

* improve descriptions for ruby gems

* standardise on packageName for all conda badges
2023-12-23 18:19:15 +00:00

49 lines
1.2 KiB
JavaScript

import Joi from 'joi'
import { pathParams } from '../index.js'
import { renderLicenseBadge } from '../licenses.js'
import toArray from '../../core/base-service/to-array.js'
import BaseCondaService from './conda-base.js'
const schema = Joi.object({
license: Joi.string().required(),
}).required()
export default class CondaLicense extends BaseCondaService {
static category = 'license'
static route = { base: 'conda', pattern: 'l/:channel/:packageName' }
static openApi = {
'/conda/l/{channel}/{packageName}': {
get: {
summary: 'Conda - License',
parameters: pathParams(
{
name: 'channel',
example: 'conda-forge',
},
{
name: 'packageName',
example: 'setuptools',
},
),
},
},
}
static defaultBadgeData = { label: 'license' }
static render({ licenses }) {
return renderLicenseBadge({ licenses })
}
async handle({ channel, packageName }) {
const json = await this._requestJson({
schema,
url: `https://api.anaconda.org/package/${channel}/${packageName}`,
})
return this.constructor.render({
licenses: toArray(json.license),
})
}
}