From 309279242e86c39e1767ab9fdf69c7cad5982a62 Mon Sep 17 00:00:00 2001 From: Chris Freeman Date: Fri, 27 Feb 2026 12:24:42 -0700 Subject: [PATCH] Replace instance configuration with serverURL in code samples Update code sample transformer to use hardcoded serverURL values instead of instance environment variables across Python, TypeScript, Go, and Java code samples. --- src/code-sample-transformer.js | 24 ++++++++++++------------ tests/code-sample-transformer.test.js | 12 ++++++------ 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/code-sample-transformer.js b/src/code-sample-transformer.js index 653c79a..1601012 100644 --- a/src/code-sample-transformer.js +++ b/src/code-sample-transformer.js @@ -77,43 +77,43 @@ export function transformPythonCodeSamplesToPython(spec) { } /** - * Transforms code samples in an OpenAPI specification to add instance configuration - * for various programming languages. This function adds the necessary instance/server + * Transforms code samples in an OpenAPI specification to add server URL configuration + * for various programming languages. This function adds the necessary server URL * configuration to existing code samples that only contain API token configuration. * * Supported transformations: - * - Python: Adds `instance=os.getenv("GLEAN_INSTANCE", "")` after `api_token` - * - TypeScript: Adds `instance: process.env["GLEAN_INSTANCE"] ?? ""` after `apiToken` - * - Go: Adds `apiclientgo.WithInstance("")` before `WithSecurity` - * - Java: Adds `.instance("")` after `.apiToken()` + * - Python: Adds `server_url="mycompany-be.glean.com",` after `api_token` + * - TypeScript: Adds `serverURL: "mycompany-be.glean.com",` after `apiToken` + * - Go: Adds `apiclientgo.WithServerURL("mycompany-be.glean.com"),` before `WithSecurity` + * - Java: Adds `.serverURL("mycompany-be.glean.com")` after `.apiToken()` * * @param {Object} spec The OpenAPI specification object containing code samples * @returns {Object} The modified OpenAPI specification with updated code samples */ -export function addInstanceToCodeSamples(spec) { +export function addServerURLToCodeSamples(spec) { const transformationsByLang = { python: [ [ /([\s]*)(api_token=os\.getenv\("GLEAN_API_TOKEN", ""\),)/, - '$1$2$1instance=os.getenv("GLEAN_INSTANCE", ""),', + '$1$2$1server_url="mycompany-be.glean.com",', ], ], typescript: [ [ /([\s]*)(apiToken: process\.env\["GLEAN_API_TOKEN"\] \?\? "",)/, - '$1$2$1instance: process.env["GLEAN_INSTANCE"] ?? "",', + '$1$2$1serverURL: "mycompany-be.glean.com",', ], ], go: [ [ /([\s]*)(apiclientgo\.WithSecurity\(os\.Getenv\("GLEAN_API_TOKEN"\)\),)/, - '$1$2$1apiclientgo.WithInstance(os.Getenv("GLEAN_INSTANCE")),', + '$1$2$1apiclientgo.WithServerURL("mycompany-be.glean.com"),', ], ], java: [ [ /([\s]*)(\.apiToken\(""\))/, - '$1$2$1.instance("")', + '$1$2$1.serverURL("mycompany-be.glean.com")', ], ], }; @@ -149,7 +149,7 @@ export function transform(content, _filename) { const spec = yaml.load(content); transformPythonCodeSamplesToPython(spec); - addInstanceToCodeSamples(spec); + addServerURLToCodeSamples(spec); return yaml.dump(spec, { lineWidth: -1, // Preserve line breaks diff --git a/tests/code-sample-transformer.test.js b/tests/code-sample-transformer.test.js index 3e808d0..6fd8340 100644 --- a/tests/code-sample-transformer.test.js +++ b/tests/code-sample-transformer.test.js @@ -133,11 +133,11 @@ paths: }); }); - describe('addInstanceToCodeSamples', () => { + describe('addServerURLToCodeSamples', () => { test('updates chat code sample to use namespace', () => { const spec = yaml.load(fixtureContent); - const updatedSpec = codeSampleTransformer.addInstanceToCodeSamples(spec); + const updatedSpec = codeSampleTransformer.addServerURLToCodeSamples(spec); const chatSpec = updatedSpec.paths['/rest/api/v1/chat']; expect(codeSampleTransformer.extractCodeSnippet(chatSpec, 'python')) @@ -151,7 +151,7 @@ paths: with Glean( api_token=os.getenv("GLEAN_API_TOKEN", ""), - instance=os.getenv("GLEAN_INSTANCE", ""), + server_url="mycompany-be.glean.com", ) as g_client: res = g_client.client.chat.create(messages=[ @@ -177,7 +177,7 @@ paths: const glean = new Glean({ apiToken: process.env["GLEAN_API_TOKEN"] ?? "", - instance: process.env["GLEAN_INSTANCE"] ?? "", + serverURL: "mycompany-be.glean.com", }); async function run() { @@ -220,7 +220,7 @@ paths: s := apiclientgo.New( apiclientgo.WithSecurity(os.Getenv("GLEAN_API_TOKEN")), - apiclientgo.WithInstance(os.Getenv("GLEAN_INSTANCE")), + apiclientgo.WithServerURL("mycompany-be.glean.com"), ) res, err := s.Client.Chat.Create(ctx, components.ChatRequest{ @@ -262,7 +262,7 @@ paths: Glean sdk = Glean.builder() .apiToken("") - .instance("") + .serverURL("mycompany-be.glean.com") .build(); ChatResponse res = sdk.client().chat().create()