Files
shields/services/dynamic/dynamic-json.service.js
chris48s 148b51d554 Export OpenAPI definitions from service examples; affects [dynamic endpoint static] (#8966)
* WIP export OpenAPI definitions from service examples

* allow services to optionally define an OpenApi Paths Object instead of examples

* make use of param descriptions and required query params

* convert other 'core' services to declare openApi..

..instead of examples

* tweak descriptions for standard query params

* move stuff around, add a high-level integration test for category2openapi

* update simple-icons text refs #9054

* remove legacy param names
2023-04-11 18:37:16 +01:00

65 lines
1.9 KiB
JavaScript

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