Files
shields/services/dynamic/dynamic-yaml.service.js
chris48s 57c2ba0d68 Convert examples arrays to openApi objects (part 1) (#9320)
* add helper functions for generating Open API path/query params with defaults

* tweak Open API schema

- make description optional
- allow null example + allowEmptyValue (for boolean query params)

* convert examples --> openApi in amo

* convert examples --> openApi in ansible

* convert examples --> openApi in appveyor build/job

* add re-usable Open API query param for test-results badges

we can use these for all the 'test results' badges

* convert examples --> openApi in appveyor tests

* DRY up existing dynamic/endpoint param definitions

* DRY up queryParam

* allow enum param in serviceDefinition schema

* improve misleading param name

* check route and openApi are consistent on service load

* fix mistake in ansible role route

* documentation --> description

* add pathParams and queryParams helpers +docstrings

* give everything a search-friendly summary, check for duplicate summary

* prettier fixup
2023-07-31 12:22:33 +01:00

55 lines
1.6 KiB
JavaScript

import { MetricNames } from '../../core/base-service/metric-helper.js'
import { BaseYamlService, queryParams } from '../index.js'
import { createRoute } from './dynamic-helpers.js'
import jsonPath from './json-path.js'
export default class DynamicYaml extends jsonPath(BaseYamlService) {
static enabledMetrics = [MetricNames.SERVICE_RESPONSE_SIZE]
static route = createRoute('yaml')
static openApi = {
'/badge/dynamic/yaml': {
get: {
summary: 'Dynamic YAML Badge',
description: `<p>
The Dynamic YAML Badge allows you to extract an arbitrary value from any
YAML Document using a JSONPath selector and show it on a badge.
</p>`,
parameters: queryParams(
{
name: 'url',
description: 'The URL to a YAML document',
required: true,
example:
'https://raw.githubusercontent.com/badges/shields/master/.github/dependabot.yml',
},
{
name: 'query',
description:
'A <a href="https://jsonpath.com/">JSONPath</a> expression that will be used to query the document',
required: true,
example: '$.version',
},
{
name: 'prefix',
description: 'Optional prefix to append to the value',
example: '[',
},
{
name: 'suffix',
description: 'Optional suffix to append to the value',
example: ']',
},
),
},
},
}
async fetch({ schema, url, httpErrors }) {
return this._requestYaml({
schema,
url,
httpErrors,
})
}
}