Conversation
| if (aMinor !== bMinor) return bMinor - aMinor; | ||
| return bPatch - aPatch; | ||
| })[0].version; | ||
| })[0]?.version; |
There was a problem hiding this comment.
Was seeing an error in isomorphic SDK where we tried to read version property from undefined
vcua-mobify
left a comment
There was a problem hiding this comment.
Aside from a question around whether this should be enabled by default, the changes seem good to me.
Followed the test steps and the resulting diff file was produced
| "normalize-directory-names": flags.boolean({ | ||
| description: | ||
| "Normalize directory names by removing minor and patch versions. Example: 'shopper-stores-oas-1.0.16' -> 'shopper-stores-oas-1", | ||
| default: false, |
There was a problem hiding this comment.
Just wondering; wouldn't the most common use case have us set this to true so that we can compare the difference between two minor versions of the same API?
Otherwise, the diff will say the old version is removed and the new version is added and leave it at that, no? I don't think this old-version-removed/new-version-added also does a file by file compare?
There was a problem hiding this comment.
agreed, this should be the normal behavior, we should remove the patch verion alltoger since it is not possible the api will do release the same patch number twice. the minimal is the minor version (default): v1.1 vs v1.2 and the the other is v1 or v2. with this, any 1.1.1 and 1.1.4 can still produce meaningful output for us
There was a problem hiding this comment.
Updated the PR so that normalizing the directory name is the default behavior, you can pass in the --disable-normalize-directory-names flag to override this behavior.
For now, I'll keep the patch number appended to the directory name as part of the releases we're going to start to tie API versions to each SDK version, see this draft PR for an example: https://github.com/SalesforceCommerceCloud/commerce-sdk/pull/427/files#diff-06572a96a58dc510037d5efa622f9bec8519bc1beab13c9f251e97e657a9d4edR5
There was a problem hiding this comment.
Thanks for making this change, @joeluong-sfcc !
|
|
||
| beforeEach(() => { | ||
| ramlToolLoggerStub = sinon.stub(ramlToolLogger, "info"); | ||
| consoleStub = sinon.stub(console, "log"); |
There was a problem hiding this comment.
This set up is used to silent all console logs in tests. Are you sure you want to remove it?
There was a problem hiding this comment.
Ah, good point, I didn't think about silencing the console logs. I went back to my original approach where I export the consoleStub
src/diff/oasDiff.test.ts
Outdated
| expect(consoleStub.called).to.be.true; | ||
| const processingMessage = consoleStub.args.find( | ||
| // verify that the message contains the normalized directory name | ||
| (args) => args[0] === "Processing directory pair: api-1" |
There was a problem hiding this comment.
Nit: For consistency, in previous tests, we are assertting the exStub arg for the command output. Like this
expect(execStub.called).to.be.true;
expect(execStub.args[1][0]).to.equal(
'oasdiff changelog "base/api-v1/spec.yaml" "new/api-v1/spec.yaml"'
);
Any reason we don't want to do it here?
There was a problem hiding this comment.
Yeah, it's because if I target the expected string in the consoleStub directly it looks like this:
expect(consoleStub.args[2][0]).to.equal("Processing directory pair: api-1");
expect(consoleStub.args[6][0]).to.equal("Processing directory pair: api-2");
If we add a console.log somewhere else in the code path, this test will break, I used .find() to make it more resilient.
I've updated the test however flatten the args array so its a bit cleaner
This PR modifies the behavior of the
diffcommand, where if the directory name contains the version number, it'll remove the minor and the patch version. For example:shopper-stores-oas-1.0.16shopper-stores-oas-1To disable this behavior, a user can pass in the
--disable-normalize-directory-namesflag.This is because when we run the
updateApiscommand, we append the version number. The current implementation of thediffcommand on directory mode looks for matches in directory names, but since directories have the version number, there will never be a match unless the API version does not change. Example diff file:By normalizing the directory names to only include the major version in the directory name, we can start to compare the old API spec with the new API spec. We keep the major version for APIs with multiple versions, like shopper baskets. Example diff file with with updated normalization behavior:
This PR also removes some unnecessary test files that weren't being used.
To test this PR:
git checkout ju/fix-diff-commandnpm run buildgit checkout ju/fix-diff-commandANYPOINT_USERNAMEandANYPOINT_PASSWORDenv variables via shared password vaultyarn ci && yarn updateApistemp/diffApis.txtthat diff shows up