Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): Dynamic snippets API support custom base URLs #5382

Merged
merged 7 commits into from
Dec 11, 2024

Conversation

amckinney
Copy link
Contributor

@amckinney amckinney commented Dec 10, 2024

This adds the ability for dynamic snippet callers to customize the environment and/or base URL used in the generated snippet. There are a few use cases to consider:

  1. Environment by ID

This works for both single environment and multi environment SDKs.

const response = await go.endpoint("POST /users").generate({
  environment: "Staging",
  requestBody: { ... }
})
client := client.NewClient(
    option.WithBaseURL(
       acme.Staging // Reference the generated environment enum.
    ),
)
  1. Single environment with custom base URL

If both baseURL and environment are set, we return a validation error.

const response = await go.endpoint("POST /users").generate({
  baseURL: "http://localhost:8080"
  requestBody: { ... }
})
client := client.NewClient(
    option.WithBaseURL(
       "http://localhost:8080" // Use the raw url string.
    ),
)
  1. Multiple environment with custom URL

Expects an object with a multiple keys, with each environment ID as a key w/ a base URL value.

Note that the WithEnvironment option isn't actually supported in the Go SDK yet, but this at least
outlines the expected use case (which is applicable to other languages, too).

const response = await go.endpoint("POST /users").generate({
  environment: {
    ec2: "http://localhost:8080",
    aws: "http://localhost:8081"
  },
  requestBody: { ... }
})
client := client.NewClient(
    option.WithEnvironment(
       acme.Environment{
         Ec2: "http://localhost:8080",
         Aws: "http://localhost:8081"
       }
    ),
)

@amckinney amckinney changed the title feat(go): Dynamic snippets support custom base URLs feat(go): Dynamic snippets API support custom base URLs Dec 10, 2024
@amckinney amckinney marked this pull request as ready for review December 10, 2024 23:40
@amckinney amckinney requested a review from dsinghvi as a code owner December 10, 2024 23:40
@amckinney amckinney changed the title feat(go): Dynamic snippets API support custom base URLs feat(cli): Dynamic snippets API support custom base URLs Dec 10, 2024
@amckinney amckinney merged commit eb5316e into main Dec 11, 2024
45 of 51 checks passed
@amckinney amckinney deleted the amckinney/dynamic-snippets/environment branch December 11, 2024 00:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants