From c767b97024eefef6d41e7b171ac447d852a8f17d Mon Sep 17 00:00:00 2001 From: Mark Story Date: Tue, 17 Dec 2024 14:22:28 -0500 Subject: [PATCH] feat(api) Add ability for endpoint specific domains Some of our endpoints require customers to use region domains in order to have APIs work correctly across DE and US regions. I've already updated those endpoints in getsentry/sentry#82159. Refs getsentry/sentry#81232 --- src/build/open-api/types.ts | 6 ++++++ src/build/resolveOpenAPI.ts | 6 ++++++ src/components/apiExamples/apiExamples.tsx | 2 +- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/build/open-api/types.ts b/src/build/open-api/types.ts index b2761cf2c967fe..5bc9a7c934af5b 100644 --- a/src/build/open-api/types.ts +++ b/src/build/open-api/types.ts @@ -36,6 +36,11 @@ type Tag = { 'x-sidebar-name': string; }; +type ServerMeta = { + description: string; + url: string; +}; + export type DeRefedOpenAPI = { paths: { [key: string]: { @@ -66,6 +71,7 @@ export type DeRefedOpenAPI = { tags: string[]; description?: string; security?: any; + servers?: ServerMeta[]; }; }; }; diff --git a/src/build/resolveOpenAPI.ts b/src/build/resolveOpenAPI.ts index 820b75a7cf31ad..1f2aa9b33b14cb 100644 --- a/src/build/resolveOpenAPI.ts +++ b/src/build/resolveOpenAPI.ts @@ -70,6 +70,7 @@ export type API = { pathParameters: APIParameter[]; queryParameters: APIParameter[]; responses: APIResponse[]; + server: string; slug: string; bodyContentType?: string; descriptionMarkdown?: string; @@ -120,11 +121,16 @@ async function apiCategoriesUncached(): Promise { Object.entries(data.paths).forEach(([apiPath, methods]) => { Object.entries(methods).forEach(([method, apiData]) => { + let server = 'https://sentry.io'; + if (apiData.servers && apiData.servers[0]) { + server = apiData.servers[0].url; + } apiData.tags.forEach(tag => { categoryMap[tag].apis.push({ apiPath, method, name: apiData.operationId, + server, slug: slugify(apiData.operationId), summary: apiData.summary, descriptionMarkdown: apiData.description, diff --git a/src/components/apiExamples/apiExamples.tsx b/src/components/apiExamples/apiExamples.tsx index cc5b026aeb0051..8c3248bca202cb 100644 --- a/src/components/apiExamples/apiExamples.tsx +++ b/src/components/apiExamples/apiExamples.tsx @@ -38,7 +38,7 @@ const codeToJsx = (code: string, lang = 'json') => { export function ApiExamples({api}: Props) { const apiExample = [ - `curl https://sentry.io${api.apiPath}`, + `curl ${api.server}${api.apiPath}`, ` -H 'Authorization: Bearer '`, ]; if (['put', 'options', 'delete'].includes(api.method.toLowerCase())) {