From 3a222a5c2dc4e16529254c84c2d4cea32a5a6905 Mon Sep 17 00:00:00 2001 From: Andrew Jiang Date: Thu, 25 Apr 2024 11:05:39 -0400 Subject: [PATCH] fix: migrating docs.yml to 0.15.0-rc0 should fail if custom-domain is an array (#3467) --- .../migrateDocsAndMultipleAPIs.ts | 3 ++- .../migrateDocsAndSingleAPI.ts | 3 ++- .../migrateDocsInstances.ts | 14 ++++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 packages/cli/yaml/yaml-migrations/src/migrations/0.15.0-rc0/update-directory-structure/migrateDocsInstances.ts diff --git a/packages/cli/yaml/yaml-migrations/src/migrations/0.15.0-rc0/update-directory-structure/migrateDocsAndMultipleAPIs.ts b/packages/cli/yaml/yaml-migrations/src/migrations/0.15.0-rc0/update-directory-structure/migrateDocsAndMultipleAPIs.ts index 094b3c4c55d..2ffdff094be 100644 --- a/packages/cli/yaml/yaml-migrations/src/migrations/0.15.0-rc0/update-directory-structure/migrateDocsAndMultipleAPIs.ts +++ b/packages/cli/yaml/yaml-migrations/src/migrations/0.15.0-rc0/update-directory-structure/migrateDocsAndMultipleAPIs.ts @@ -10,6 +10,7 @@ import { loadRawGeneratorsConfiguration } from "./generators-configuration"; import { PathModificationStrategy } from "./generators-configuration/convertLegacyGeneratorsConfiguration"; +import { migrateDocsInstances } from "./migrateDocsInstances"; const APIS_DIRECTORY = "apis"; @@ -93,7 +94,7 @@ async function migrateAndWriteDocsYml({ } const convertedDocsConfig = convertLegacyDocsConfig({ docsConfiguration, - docsURLs, + docsURLs: migrateDocsInstances(docsURLs), apiName }); const absolutePathToDocsConfig = getAbsolutePathToDocsYaml({ absolutePathToWorkspace }); diff --git a/packages/cli/yaml/yaml-migrations/src/migrations/0.15.0-rc0/update-directory-structure/migrateDocsAndSingleAPI.ts b/packages/cli/yaml/yaml-migrations/src/migrations/0.15.0-rc0/update-directory-structure/migrateDocsAndSingleAPI.ts index 336206f1bdf..9df21a4fd9b 100644 --- a/packages/cli/yaml/yaml-migrations/src/migrations/0.15.0-rc0/update-directory-structure/migrateDocsAndSingleAPI.ts +++ b/packages/cli/yaml/yaml-migrations/src/migrations/0.15.0-rc0/update-directory-structure/migrateDocsAndSingleAPI.ts @@ -6,6 +6,7 @@ import { getAbsolutePathToDocsFolder, getAbsolutePathToDocsYaml, loadRawDocsConf import { convertLegacyDocsConfig } from "./docs-config/convertLegacyDocsConfig"; import { getAbsolutePathToGeneratorsConfiguration, loadRawGeneratorsConfiguration } from "./generators-configuration"; import { convertLegacyGeneratorsConfiguration } from "./generators-configuration/convertLegacyGeneratorsConfiguration"; +import { migrateDocsInstances } from "./migrateDocsInstances"; /** * fern/ <------ path to fern directory @@ -48,7 +49,7 @@ async function migrateAndWriteDocsYml({ } const convertedDocsConfig = convertLegacyDocsConfig({ docsConfiguration, - docsURLs, + docsURLs: migrateDocsInstances(docsURLs), apiName: undefined }); const absolutePathToDocsConfig = getAbsolutePathToDocsYaml({ absolutePathToWorkspace }); diff --git a/packages/cli/yaml/yaml-migrations/src/migrations/0.15.0-rc0/update-directory-structure/migrateDocsInstances.ts b/packages/cli/yaml/yaml-migrations/src/migrations/0.15.0-rc0/update-directory-structure/migrateDocsInstances.ts new file mode 100644 index 00000000000..2fb5710c135 --- /dev/null +++ b/packages/cli/yaml/yaml-migrations/src/migrations/0.15.0-rc0/update-directory-structure/migrateDocsInstances.ts @@ -0,0 +1,14 @@ +import { docsYml } from "@fern-api/configuration"; +import { DocsURL } from "./docs-config"; + +export function migrateDocsInstances(docsURLs: docsYml.RawSchemas.DocsInstances[]): DocsURL[] { + return docsURLs.map((docsURL) => { + if (Array.isArray(docsURL.customDomain)) { + throw new Error("Expected custom-domain to be a string, but it was an array."); + } + return { + ...docsURL, + customDomain: docsURL.customDomain + }; + }); +}