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: support switching basepath #530

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions api/client.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions api/configuration.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions api/configuration_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func NewAPIConfig(params ConfigParams) *Configuration {

apiConfig := NewConfiguration()
apiConfig.Host = params.Host.Host
apiConfig.Path = params.Host.Path
apiConfig.Scheme = params.Host.Scheme
apiConfig.UserAgent = params.UserAgent
apiConfig.HTTPClient = &http.Client{Transport: clientTransport}
Expand Down
5 changes: 5 additions & 0 deletions api/templates/client.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,11 @@ func (c *APIClient) prepareRequest(
return nil, err
}

// Prepend request base path, if applicable
if c.cfg.Path != "" {
Copy link
Author

@tisonkun tisonkun Mar 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't make openapi locally so perhaps we still need some formatting here. But the code functions are proper.

./etc/generate-openapi.sh
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
Error opening file "/api/contract/openapi/src/legacy/paths/query.yml" 
ENOENT: no such file or directory, open '/api/contract/openapi/src/legacy/paths/query.yml'
make: *** [openapi] Error 1

url.Path = c.cfg.Path + url.Path
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to handle / properly. I don't know if there is an existing utility for it. But users can always self add/remove the / on demand.

}

// Override request host, if applicable
if c.cfg.Host != "" {
url.Host = c.cfg.Host
Expand Down
1 change: 1 addition & 0 deletions api/templates/configuration.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ type ServerConfigurations []ServerConfiguration
// Configuration stores the configuration of the API client
type Configuration struct {
Host string `json:"host,omitempty"`
Path string `json:"path,omitempty"`
Scheme string `json:"scheme,omitempty"`
DefaultHeader map[string]string `json:"defaultHeader,omitempty"`
UserAgent string `json:"userAgent,omitempty"`
Expand Down