Add server URL normalization for flexible serverURL input#109
Merged
chris-freeman-glean merged 4 commits intomainfrom Mar 4, 2026
Merged
Add server URL normalization for flexible serverURL input#109chris-freeman-glean merged 4 commits intomainfrom
chris-freeman-glean merged 4 commits intomainfrom
Conversation
Add SDKInit hook that normalizes server URLs: strips trailing slashes and preserves http/https schemes. Consistent with Go/Python/Java SDKs.
The Speakeasy-generated serverURLFromOptions() calls new URL() which throws on schemeless input like "mycompany-be.glean.com". This edit adds normalization (prepend https://, strip trailing slashes) before the URL constructor, matching the behavior of Go/Python/Java SDKs. This is a Custom Code edit to a generated file — Speakeasy's 3-way merge will preserve it across regenerations.
…t edits - Update README preamble and Experimental Features examples to use serverURL instead of instance - Update indexing.test-d.ts to use serverURL/GLEAN_SERVER_URL - Enable persistentEdits in gen.yaml to preserve the config.ts schemeless URL normalization across Speakeasy regenerations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds server URL normalization so users can pass schemeless URLs (e.g.,
"mycompany-be.glean.com") asserverURLwhen constructing the SDK client. This is part of promotingserverURLas the primary configuration option, replacinginstancein all documentation and examples.TypeScript-specific implementation
The TypeScript SDK required a two-layer approach due to how Speakeasy generates the TypeScript target:
SDKInit hook (
src/hooks/server-url-normalizer.ts): Normalizes URLs that already have a scheme (strips trailing slashes, preserves http/https). This is consistent with the hook-based approach used in Go, Python, and Java SDKs.Custom Code edit to
config.ts(src/lib/config.ts): The Speakeasy-generatedserverURLFromOptions()callsnew URL()before the SDKInit hook runs. Unlike Go/Python/Java where the hook receives a raw string, the TypeScript hook receives a parsedURLobject — so schemeless URLs throwTypeError: Invalid URLbefore the hook can normalize them. This edit adds normalization directly inserverURLFromOptions(), beforenew URL()is called. Speakeasy's Custom Code 3-way merge preserves this edit across regenerations.Normalization rules
https://http://preserved (for localhost/dev)https://preservedUser-facing API
Backwards compatibility
The
instanceparameter continues to work unchanged. No breaking changes.Test plan