Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/chronicle/src/components/api/api-overview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ interface ApiOverviewProps {
auth?: { type: string; header: string; placeholder?: string }
}

export function ApiOverview({ method, path, operation, auth }: ApiOverviewProps) {
export function ApiOverview({ method, path, operation, serverUrl, auth }: ApiOverviewProps) {
const params = (operation.parameters ?? []) as OpenAPIV3.ParameterObject[]
const body = getRequestBody(operation.requestBody as OpenAPIV3.RequestBodyObject | undefined)

Expand All @@ -36,7 +36,7 @@ export function ApiOverview({ method, path, operation, auth }: ApiOverviewProps)
? headerFields
: []

const fullUrl = '{domain}' + path
const fullUrl = serverUrl + path
const snippetHeaders: Record<string, string> = {}
if (auth) snippetHeaders[auth.header] = auth.placeholder ?? 'YOUR_API_KEY'
if (body) snippetHeaders['Content-Type'] = body.contentType ?? 'application/json'
Expand Down
9 changes: 9 additions & 0 deletions packages/chronicle/src/lib/env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export function substituteEnvVars(value: string): string {
return value.replace(/\$\{(\w+)\}/g, (_, name) => {
const val = process.env[name];
if (val === undefined) {
throw new Error(`Environment variable '${name}' is not set`);
}
return val;
});
}
3 changes: 2 additions & 1 deletion packages/chronicle/src/lib/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import path from 'node:path'
import { parse as parseYaml } from 'yaml'
import type { OpenAPIV2, OpenAPIV3 } from 'openapi-types'
import type { ApiConfig, ApiServerConfig, ApiAuthConfig } from '@/types/config'
import { substituteEnvVars } from '@/lib/env'

type JsonObject = Record<string, unknown>

Expand Down Expand Up @@ -41,7 +42,7 @@ export async function loadApiSpec(config: ApiConfig, projectRoot: string): Promi
return {
name: config.name,
basePath: config.basePath,
server: config.server,
server: { ...config.server, url: substituteEnvVars(config.server.url) },
auth: config.auth,
document: v3Doc,
}
Expand Down
Loading