UNPKG

unleash-server

Version:

Unleash is an enterprise ready feature flag service. It provides different strategies for handling feature flags.

61 lines 2.44 kB
import { mapValues, omitKeys } from '../util/index.js'; import { openApiTags } from './util/index.js'; import { URL } from 'node:url'; import apiVersion from '../util/version.js'; /* * All schemas in `openapi/spec` should be listed here. * Instead of listing them all maunally, exclude those that are not schemas (maybe they should be moved elsewhere) */ import * as importedSchemas from './spec/index.js'; const { constraintSchemaBase, unknownFeatureEvaluationResult, playgroundStrategyEvaluation, strategyEvaluationResults, ...exportedSchemas } = importedSchemas; export const schemas = exportedSchemas; // Remove JSONSchema keys that would result in an invalid OpenAPI spec. export const removeJsonSchemaProps = (schema) => { return omitKeys(schema, '$id', 'components'); }; const findRootUrl = (unleashUrl, baseUriPath) => { if (!baseUriPath) { return unleashUrl; } const baseUrl = new URL(unleashUrl); const url = baseUrl.pathname.indexOf(baseUriPath) >= 0 ? `${baseUrl.protocol}//${baseUrl.host}` : baseUrl.toString(); return baseUriPath.startsWith('/') ? new URL(baseUriPath, url).toString() : url; }; export const createOpenApiSchema = ({ unleashUrl, baseUriPath, }) => { const url = findRootUrl(unleashUrl, baseUriPath); return { openapi: '3.0.3', servers: baseUriPath ? [{ url }] : [], info: { title: 'Unleash API', version: apiVersion, }, security: [{ apiKey: [] }, { bearerToken: [] }], components: { securitySchemes: { // https://swagger.io/docs/specification/authentication/api-keys/ apiKey: { type: 'apiKey', in: 'header', name: 'Authorization', description: 'API key needed to access this API', }, // https://swagger.io/docs/specification/authentication/bearer-authentication/ bearerToken: { type: 'http', scheme: 'bearer', description: 'API key needed to access this API, in Bearer token format', }, }, schemas: mapValues(schemas, removeJsonSchemaProps), }, tags: openApiTags, }; }; export * from './util/index.js'; export * from './spec/index.js'; //# sourceMappingURL=index.js.map