Software: Apache/2.4.41 (Ubuntu). PHP/8.0.30 uname -a: Linux apirnd 5.4.0-204-generic #224-Ubuntu SMP Thu Dec 5 13:38:28 UTC 2024 x86_64 uid=33(www-data) gid=33(www-data) groups=33(www-data) Safe-mode: OFF (not secure) /usr/local/lib/node_modules/homebridge-config-ui-x/node_modules/fastify-swagger/lib/spec/swagger/ drwxr-xr-x | |
| Viewing file: Select action/file-type: 'use strict'
const yaml = require('js-yaml')
const { shouldRouteHide } = require('../../util/common')
const { prepareDefaultOptions, prepareSwaggerObject, prepareSwaggerMethod, normalizeUrl, prepareSwaggerDefinitions } = require('./utils')
module.exports = function (opts, cache, routes, Ref, done) {
let ref
const defOpts = prepareDefaultOptions(opts)
return function (opts) {
if (opts && opts.yaml) {
if (cache.string) return cache.string
} else {
if (cache.object) return cache.object
}
const swaggerObject = prepareSwaggerObject(defOpts, done)
ref = Ref()
swaggerObject.definitions = prepareSwaggerDefinitions({
...swaggerObject.definitions,
...(ref.definitions().definitions)
}, ref)
swaggerObject.paths = {}
for (const route of routes) {
const schema = defOpts.transform
? defOpts.transform(route.schema)
: route.schema
const shouldRouteHideOpts = {
hiddenTag: defOpts.hiddenTag,
hideUntagged: defOpts.hideUntagged
}
if (shouldRouteHide(schema, shouldRouteHideOpts)) continue
const url = normalizeUrl(route.url, defOpts.basePath, defOpts.stripBasePath)
const swaggerRoute = Object.assign({}, swaggerObject.paths[url])
const swaggerMethod = prepareSwaggerMethod(schema, ref, swaggerObject)
if (route.links) {
throw new Error('Swagger (Open API v2) does not support Links. Upgrade to OpenAPI v3 (see fastify-swagger readme)')
}
// route.method should be either a String, like 'POST', or an Array of Strings, like ['POST','PUT','PATCH']
const methods = typeof route.method === 'string' ? [route.method] : route.method
for (const method of methods) {
swaggerRoute[method.toLowerCase()] = swaggerMethod
}
swaggerObject.paths[url] = swaggerRoute
}
if (opts && opts.yaml) {
cache.string = yaml.dump(swaggerObject, { skipInvalid: true })
return cache.string
}
cache.object = swaggerObject
return cache.object
}
}
|
:: Command execute :: | |
--[ c99shell v. 2.5 [PHP 8 Update] [24.05.2025] | Generation time: 0.0045 ]-- |