1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-28 00:06:53 +01:00
unleash.unleash/website/prepare-generated-docs.mjs
Thomas Heartman 5d32d149cd
feat: add stale flag count to project status payload (#8751)
This PR adds stale flag count to the project status payload. This is
useful for the project status page to show the number of stale flags in
the project.
2024-11-14 14:10:10 +00:00

49 lines
1.4 KiB
JavaScript

// Description:
//
// ## What
//
// This script replaces all references to the Unleash ushosted instance in the
// generated OpenAPI docs. It removes extra path segments (such as leading
// `/ushosted` instances) and replaces the ushosted base url with something
// user-agnostic.
//
// ## Why
//
// When we host the OpenAPI docs in our official documentation, the generated
// docs shouldn't necessarily point at _one specific instance_, and especially
// not one that the reader is unlikely to ever use. Instead, we can remove all
// the bits that are specific to the generation source we use, and make the docs
// easier to use. In particular, removing the leading `/ushosted` is likely to
// save us loooots of questions.
import fs from 'node:fs/promises';
import path from 'node:path';
const url = 'https://us.app.unleash-hosted.com/ushosted/docs/openapi.json';
// Fetch the OpenAPI spec
const response = await fetch(url);
if (!response.ok) {
throw new Error(`Failed to fetch OpenAPI spec: ${response.statusText}`);
}
const data = await response.json();
data.servers = [
{
url: '<your-unleash-url>',
},
];
const outputDir = './docs/generated/';
// Write the JSON to file
const outputPath = path.join(outputDir, 'openapi.json');
// Ensure directory exists
await fs.mkdir(outputDir, { recursive: true });
await fs.writeFile(outputPath, JSON.stringify(data, null, 2), 'utf8');
console.log(`OpenAPI spec saved to ${outputPath}`);