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

fix: change constructServiceURL from method to function #141

Merged
merged 2 commits into from
Jun 7, 2021

Conversation

ajhynes7
Copy link
Contributor

@ajhynes7 ajhynes7 commented Jun 4, 2021

Now it can be used as a utility function instead of an inherited method.

An SDK class can now include a constructServiceURL method with a different signature than this function.

Checklist
  • npm test passes (tip: npm run lint-fix can correct most style issues)
  • tests are included
  • documentation is changed or added

Now it can be used as a utility function instead of an inherited method.

An SDK class can now include a `constructServiceURL` method with a different signature than this function.
@ajhynes7 ajhynes7 requested review from dpopp07 and padamstx June 4, 2021 18:40
lib/helper.ts Outdated
* the default variable value will be used instead.
* @returns {string} The formatted URL with all variable placeholders replaced by values.
*/
export function constructServiceURL(
Copy link
Member

Choose a reason for hiding this comment

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

I only just now thought of this, but since we're changing it already... we don't fully capitalize "URL" elsewhere in the core. For example, the BaseService class has a method called setServiceUrl. I think we probably want to be consistent and call this constructServiceUrl. Sorry for not catching that earlier!

Copy link
Member

Choose a reason for hiding this comment

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

I noticed this too, and tbh we have the same discrepancy in the java core. I only noticed that AFTER the PR was merged in :)
Let's make this change here while we're changing things anyway.

Copy link
Member

Choose a reason for hiding this comment

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

BTW, I'm not suggesting we change the Java core :)

@@ -1,4 +1,4 @@
const { BaseService } = require('../../dist/lib/base-service');
const { constructServiceURL } = require('../../dist/lib/helper');
Copy link
Member

Choose a reason for hiding this comment

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

Question: will moving this function to helpers.ts make it more difficult to import it in the generated SDK code?
@dpopp07 any idea?

Copy link
Member

Choose a reason for hiding this comment

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

@padamstx Good question - no, it won't. All of the helper methods are exported at the top level of the core so the import will be simple:

const { constructServiceUrl, <any-other-imports> } = require('ibm-cloud-sdk-core');

Copy link
Member

Choose a reason for hiding this comment

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

ok, sounds good, but I assume this means that when we generate the service code for a service, we'll need to be careful about correctly importing constructServiceUrl from the core when we will be generating a service-specific constructServiceUrl() function that will reference the function in the core.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, because of name conflicts? That could be a legitimate issue, though it should be easy to get around in a compatible way

Copy link
Member

Choose a reason for hiding this comment

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

I wasn't thinking about name conflicts actually. But in the node generator, when we process an API definition, we'd generate the constructServiceUrl() function in the service .ts file ONLY if we detect server variables in one of the "servers" entries.
So only in that case would we want to import the "constructServiceUrl" function from the core, since that's the only scenario where we'd use it.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, I see. That makes sense

lib/helper.ts Outdated
* the default variable value will be used instead.
* @returns {string} The formatted URL with all variable placeholders replaced by values.
*/
export function constructServiceURL(
Copy link
Member

Choose a reason for hiding this comment

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

I noticed this too, and tbh we have the same discrepancy in the java core. I only noticed that AFTER the PR was merged in :)
Let's make this change here while we're changing things anyway.

lib/helper.ts Outdated
* the default variable value will be used instead.
* @returns {string} The formatted URL with all variable placeholders replaced by values.
*/
export function constructServiceURL(
Copy link
Member

Choose a reason for hiding this comment

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

BTW, I'm not suggesting we change the Java core :)

This is consistent with the existing `setServiceUrl` method.
Copy link
Member

@dpopp07 dpopp07 left a comment

Choose a reason for hiding this comment

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

Looks good! 👍

@ajhynes7 ajhynes7 merged commit cd2d28c into main Jun 7, 2021
@ajhynes7 ajhynes7 deleted the fix_constructServiceURL branch June 7, 2021 16:24
ibm-devx-sdk pushed a commit that referenced this pull request Jun 7, 2021
## [2.11.1](v2.11.0...v2.11.1) (2021-06-07)

### Bug Fixes

* change constructServiceURL from method to function ([#141](#141)) ([cd2d28c](cd2d28c))
@ibm-devx-sdk
Copy link

🎉 This PR is included in version 2.11.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants