1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-06-27 01:19:00 +02:00
unleash.unleash/website/prepare-generated-docs.mjs
Gastón Fournier 2e3a27a26d
fix: docs generation due to openapi static images (#10078)
New openapi docs need to have the static images for openapi. I just
duplicated them because they're expected in a different path.

Now this is what they look like: 

![image](https://github.com/user-attachments/assets/a99b70a9-b708-47b9-9c02-3c9d84ac178f)
2025-06-03 15:59:25 +00:00

56 lines
1.5 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).replace(
/\/ushosted\/openapi-static/g,
'/openapi-static',
),
'utf8',
);
console.log(`OpenAPI spec saved to ${outputPath}`);