stoplightio / elements

Build beautiful, interactive API Docs with embeddable React or Web Components, powered by OpenAPI and Markdown.
https://stoplight.io/open-source/elements/
Apache License 2.0
1.82k stars 206 forks source link

Fix license URL vs identifier precedence issue in AdditionalInfo component #2724

Closed elmiomar closed 3 weeks ago

elmiomar commented 1 month ago

Description of the Issue

This PR addresses the issue , where the AdditionalInfo component prioritizes the license identifier (SPDX) over the provided license URL. According to the OpenAPI specification, the url and identifier fields in the license object are mutually exclusive, meaning that if both are provided, the license.url should take precedence.

Suggested Fix

I updated the logic in the AdditionalInfo component to make sure that if a license.url is provided, it takes precedence over the license.identifier. In the case where only an identifier is available, the component falls back to using the SPDX license URL.

Following is the change to the license URL logic:

const licenseUrl = license?.url
  ? license.url
  : license?.identifier
  ? `https://spdx.org/licenses/${license.identifier}.html`
  : undefined;

Unit Tests

The existing test already covers rendering the component when only the license.url is present. So, I added unit tests to cover the other two cases:

Storybook Changes

I also updated the Storybook stories to reflect this change, making the story names more meaningful:

Testing

I followed the contribution guidelines and did the following tests:

Both tests passed, and the issue seems to be resolved. I tested using Node v18.20.4 and v20.18.0.

image

EB97BE4E-4D9E-4C94-87D6-33E1D49C7DC4

netlify[bot] commented 1 month ago

Deploy Preview for stoplight-elements-demo ready!

Name Link
Latest commit 796bfdfc51112d62ad5af28d798f889e807ec5eb
Latest deploy log https://app.netlify.com/sites/stoplight-elements-demo/deploys/67220248a7854100089b7528
Deploy Preview https://deploy-preview-2724--stoplight-elements-demo.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

netlify[bot] commented 1 month ago

Deploy Preview for stoplight-elements ready!

Name Link
Latest commit 796bfdfc51112d62ad5af28d798f889e807ec5eb
Latest deploy log https://app.netlify.com/sites/stoplight-elements/deploys/672202486051a30008e668ba
Deploy Preview https://deploy-preview-2724--stoplight-elements.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.