Repository navigation
Keep the host URL path prefix in the generated API client - #38
Open
DzmitryHumianiuk wants to merge 1 commit into
Open
DzmitryHumianiuk wants to merge 1 commit into
DzmitryHumianiuk wants to merge 1 commit into
Conversation
With a host such as https://srv/reportportal the generated OpenAPI client requested /api/v1/... while the Resty clients requested /reportportal/api/..., so 'gorp launch list' (without filters) and 'gorp quality-gate check' missed a ReportPortal served under a path prefix. newAPIClient copied only scheme and host into the configuration; the path came from the fixed server URL of the spec (/api). Prepend the escaped, slash-trimmed path of the host URL to the configured server URLs. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
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
Fixes #37
With a host such as
https://srv/reportportal, the generated OpenAPI client requested/api/v1/...while the Resty clients requested/reportportal/api/....gorp launch list(without filters) andgorp quality-gate checktherefore missed a ReportPortal served under a path prefix, while reporting worked. Both clients now resolve the same URLs for the same host.Changes
pkg/gorp/client.go(newAPIClient): prepend the escaped path of the host URL, with trailing slashes trimmed, to every server URL of the generated configuration. A host without a path (or with/) leaves the configuration as it was.pkg/gorp/base_path_test.go: table tests against anhttptestserver that serves only under<prefix>/api/and records the request paths.TestClientKeepsHostPathPrefix:LaunchAPI.GetProjectLaunches,LaunchAPI.GetLaunch(generated) andGetLaunchesByFilterString(Resty) on oneClient.TestReportingClientKeepsHostPathPrefix:ReportingClient.StartLaunch./,/reportportal,/reportportal/,/reportportal//,/a/b/,/report%20portal/.pkg/openapi, the spec orscripts/openapi-preprocess.jq; nothing was regenerated. The server URL/apistill comes from the spec.Before the fix, 5 of the 7
TestClientKeepsHostPathPrefixcases fail (every host with a path prefix). The two cases without a prefix and allTestReportingClientKeepsHostPathPrefixcases passed before as well: they pin the behaviour that was already right, so the two clients stay consistent.Lint:
task lintneeds Docker, which is not running, so the pinned version was run without it:go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.15.0 run ./...reports0 issues. Not run:task e2e, and the CLI commands themselves against a prefixed server (the tests cover the library calls they make).Investigation log
All commands run from the repository root; line numbers are for this branch.
sed -n 101,116p pkg/openapi/configuration.go:NewConfigurationsetsServersto one entry withURL: "/api";OperationServersis empty.grep -n localBasePath pkg/openapi/api_launch.go | head -2: each operation buildslocalBasePath + "/v1/{projectKey}/...", wherelocalBasePathiscfg.ServerURLWithContext(...), i.e./api.sed -n 500,508p pkg/openapi/client.go:prepareRequest(starts at line 417) overrides onlyurl.Hostandurl.Schemefrom the configuration.python3 -c "import json;print(json.load(open('reportportal-api-docs.json'))['servers'])"prints[{'url': '/api'}].pkg/gorpbuilds the configuration.pkg/gorp/client.go:89-103(newAPIClient): before the fix it set onlyconf.Schemeandconf.Host; lines 94-101 are the fix.grep -rn --include='*.go' -e NewConfiguration -e NewAPIClient . | grep -v '^./pkg/openapi':pkg/gorp/client.gois the only construction site.pkg/gorp/client.go:79SetBaseURL(u.String())andpkg/gorp/reporting_client.go:27SetBaseURL(host); request paths are absolute, e.g.pkg/gorp/launches.go:12"/api/v1/{project}/launch".strings.TrimRight(baseURL, "/") + path(middleware.go:147in$(go list -m -f '{{.Dir}}' resty.dev/v3)), so the prefix is kept and trailing slashes are dropped.grep -rn --include='*.go' 'API\.' internal: onlyinternal/commands/launch.go:141(GetProjectLaunches, the branch without filters) andinternal/commands/quality_gate.go:140(GetLaunch).internal/commands/commands.go:172-182passes the parsed host unchanged togorp.NewClient.git stashis not needed:git diff HEAD~1 HEAD -- pkg/gorp/client.go > /tmp/fix.patch && git apply -R /tmp/fix.patchgo test ./pkg/gorp/ -run KeepsHostPathPrefix -vTestClientKeepsHostPathPrefixfails forprefix,prefix_with_trailing_slash,prefix_with_trailing_slashes,nested_prefix,escaped_prefix, e.g. expectedGET /reportportal/api/v1/prj/launch,GET /reportportal/api/v1/prj/launch/42,GET /reportportal/api/v1/prj/launch; actualGET /api/v1/prj/launch,GET /api/v1/prj/launch/42,GET /reportportal/api/v1/prj/launch(the third request is Resty).no_path,root_pathand allTestReportingClientKeepsHostPathPrefixcases pass.git apply /tmp/fix.patchto restore the fix.go test ./pkg/gorp/ -run KeepsHostPathPrefix -v: all 14 subtests pass.go build ./... && go vet ./... && go test ./...:okforinternal/commandsandpkg/gorp.go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.15.0 run ./...:0 issues.🤖 Generated with Claude Code