IBM / python-sdk-core

The python-sdk-core repository contains core functionality required by Python code generated by the IBM OpenAPI SDK Generator.
Apache License 2.0
20 stars 27 forks source link

fix: strip trailing slashes in BaseService.set_service_url #130

Closed padamstx closed 2 years ago

padamstx commented 3 years ago

This commit modifies the BaseService.set_service_url() function so that it removes any trailing slashes.

Previously, a service URL containing a trailing slash (e.g. "https://myserver.com/api/v1/") would result in a request URL that contains two slashes between the service URL and the operation path (e.g. "https://myserver.com/api/v1//myoperationpath"), and some server implementations might fail to process such a request properly.

With the changes in this commit, a request URL of "https://myserver.com/api/v1/myoperationpath" will be used instead.

codecov[bot] commented 3 years ago

Codecov Report

Merging #130 (7ad297f) into main (1e29bfa) will increase coverage by 0.00%. The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #130   +/-   ##
=======================================
  Coverage   99.66%   99.66%           
=======================================
  Files          24       24           
  Lines         906      908    +2     
=======================================
+ Hits          903      905    +2     
  Misses          3        3           
Impacted Files Coverage Δ
ibm_cloud_sdk_core/base_service.py 99.48% <100.00%> (+<0.01%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 1e29bfa...7ad297f. Read the comment docs.

padamstx commented 3 years ago

Reminder to myself: before we merge this, we need to test this version of the core with existing generated unit tests.

Edit: The platform-services python SDK's unit tests ran clean using my local copy of the python core.

padamstx commented 3 years ago

I also did a test with the platform-services python SDK where I ran the global-search integration test with and without the python core fix. The service URL I used in each case was: https://api.global-search-tagging.cloud.ibm.com/. In the "before" scenario (without the python core fix), I see this in the http debug messages:

send: b'POST //v3/resources/search?limit=1 HTTP/1.1\r\nHost: api.global-search-tagging.cloud.ibm.com

so the path value passed in the HTTP request message does in fact have a leading double-slash (the global-search server still processes this request just fine, but not all servers behave this way).

In the "after" scenario (with the python core fix), I see this in the http debug messages:

send: b'POST /v3/resources/search?limit=1 HTTP/1.1\r\nHost: api.global-search-tagging.cloud.ibm.com

so the path value now has just a single slash.

ibm-devx-sdk commented 2 years ago

:tada: This PR is included in version 3.13.1 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket: