Skip to content

W 18764378/oasdiff on multi vers of api#233

Merged
alexvuong merged 11 commits intomainfrom
W-18764378/oasdiff-on-multi-vers-of-api
Jun 19, 2025
Merged

W 18764378/oasdiff on multi vers of api#233
alexvuong merged 11 commits intomainfrom
W-18764378/oasdiff-on-multi-vers-of-api

Conversation

@alexvuong
Copy link
Contributor

@alexvuong alexvuong commented Jun 14, 2025

This PR fixed the oasdiff command to be compatible with multiple version of the same API. (E.g shopper-basket v2 and v1)

Problem:

Since we are pulling multiple verserions of the same apis. Some of them will have the same endpoints. When we try to run oasdiff changlog on the parent directory (apis vs oldApis). We ran into an error of endpoint duplication.

Solution

Loop through the each API folder and run oasdiff instead of the parent directory. This will guarantee there is not duplication in each run and concat the results into a txt file.

How to test drive

  • check out code
  • npm i
  • npm run build
  • npm run test
  • Observe all the tests are passing

How to test the changes on isomorphic

  • check out this oas branch for isomorphic @W-18349405@ Download and generate multiple versions of ShopperBaskets commerce-sdk-isomorphic#198
  • Change raml-toolkit to locale dependencies
  • yarn ci
  • Make sure your node_modules has the raml-toolkit of your local
  • Run npm run updateApis twice to get the current api copied to oldApis folder
  • Here two copies will be identical, you won't see much output in the diffApi.txt. Go to oldApis and randomly removed any endpoint from 2 api. E.g oldApis/shopper-basket-oas-1.8.19/shopper-basket-oas-v1-bundled.yaml. Removed end endpoint. Do the same for shopper-basket-oas-2.x
  • Run yarn run diffApis and observe the diffApis. You should see output look similiar to this.
    default format output
=== Changes in shopper-baskets-oas-1.8.19 ===
1 changes: 0 error, 0 warning, 1 info
info	[endpoint-added] at apis/shopper-baskets-oas-1.8.19/shopper-baskets-oas-v1-bundled.yaml	
	in API POST /organizations/{organizationId}/baskets
		endpoint added



=== Changes in shopper-baskets-oas-2.0.10 ===
1 changes: 0 error, 0 warning, 1 info
info	[endpoint-added] at apis/shopper-baskets-oas-2.0.10/shopper-baskets-oas-v2-bundled.yaml	
	in API DELETE /organizations/{organizationId}/baskets/{basketId}/coupons/{couponItemId}
		endpoint added



======shopper-orders-oas-1.4.8 API is deleted======
======shopper-stores-oas-1.0.15 API is added======
  • Json output console
[
  {
    "directory": "shopper-baskets-oas-1.8.19",
    "changes": [
      {
        "id": "endpoint-added",
        "text": "endpoint added",
        "level": 1,
        "operation": "POST",
        "operationId": "createBasket",
        "path": "/organizations/{organizationId}/baskets",
        "source": "apis/shopper-baskets-oas-1.8.19/shopper-baskets-oas-v1-bundled.yaml",
        "section": "paths"
      }
    ]
  },
  {
    "directory": "shopper-baskets-oas-2.0.10",
    "changes": [
      {
        "id": "endpoint-added",
        "text": "endpoint added",
        "level": 1,
        "operation": "DELETE",
        "operationId": "removeCouponFromBasket",
        "path": "/organizations/{organizationId}/baskets/{basketId}/coupons/{couponItemId}",
        "source": "apis/shopper-baskets-oas-2.0.10/shopper-baskets-oas-v2-bundled.yaml",
        "section": "paths"
      }
    ]
  },
  {
    "directory": "shopper-orders-oas-1.4.8",
    "status": "deleted",
    "message": "shopper-orders-oas-1.4.8 API is deleted"
  },
  {
    "directory": "shopper-stores-oas-1.0.15",
    "status": "added",
    "message": "shopper-stores-oas-1.0.15 API is added"
  }
]

@alexvuong alexvuong requested a review from a team as a code owner June 14, 2025 01:37
vcua-mobify
vcua-mobify previously approved these changes Jun 18, 2025
Copy link
Contributor

@vcua-mobify vcua-mobify left a comment

Choose a reason for hiding this comment

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

I've verified that these changes work in the node sdk to address the duplicate endpoints errors that appear as a result of having -internal and -public yaml files in the same location.

I just have a small comment about maybe separating the logic for directory mode but otherwise LGTM.

baseApiTarget = '"' + baseApi + "/**/*.yaml" + '"';
newApiTarget = '"' + newApi + "/**/*.yaml" + '"';
}
// Find all exchange.json files and their parent directories
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: There's a lot of logic specifically for handling directory mode. I wonder if we should break it off into a separate function just to make things a bit easier to read?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good call. I've break it down a bit. Please take another look when you get some time

vcua-mobify
vcua-mobify previously approved these changes Jun 18, 2025
Copy link
Contributor

@vcua-mobify vcua-mobify left a comment

Choose a reason for hiding this comment

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

Thanks for adjusting @alexvuong !

);
}
}
} else {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: Is this case even possible.. where the directory exists but Yaml is missing? May be when download has some issues

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. I think it is stil good to leave it here if download happens to has some issue and dev does not realize it and run oasdiff. The logic in here simply notify which yml files are removed from previous version into output file

@alexvuong alexvuong merged commit a790e5b into main Jun 19, 2025
7 checks passed
@alexvuong alexvuong deleted the W-18764378/oasdiff-on-multi-vers-of-api branch June 19, 2025 19:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants