2024-11-14 12:07:23 +01:00
|
|
|
// 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();
|
|
|
|
|
2024-11-14 15:10:10 +01:00
|
|
|
data.servers = [
|
|
|
|
{
|
|
|
|
url: '<your-unleash-url>',
|
|
|
|
},
|
|
|
|
];
|
2024-11-14 12:07:23 +01:00
|
|
|
|
2024-11-14 15:10:10 +01:00
|
|
|
const outputDir = './docs/generated/';
|
2024-11-14 12:07:23 +01:00
|
|
|
|
|
|
|
// Write the JSON to file
|
2024-11-14 15:10:10 +01:00
|
|
|
const outputPath = path.join(outputDir, 'openapi.json');
|
2024-11-14 12:07:23 +01:00
|
|
|
|
|
|
|
// Ensure directory exists
|
|
|
|
await fs.mkdir(outputDir, { recursive: true });
|
|
|
|
|
2024-11-14 15:10:10 +01:00
|
|
|
await fs.writeFile(outputPath, JSON.stringify(data, null, 2), 'utf8');
|
2024-11-14 12:07:23 +01:00
|
|
|
|
|
|
|
console.log(`OpenAPI spec saved to ${outputPath}`);
|