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

feat(ibm-use-date-based-format): introduce new validation rule #706

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

dpopp07
Copy link
Member

@dpopp07 dpopp07 commented Dec 19, 2024

PR summary

This commit introduces the new 'ibm-use-date-based-format' rule,
which will heuristically verify that schemas, with either a name
or an example value indicating a date-based logical type, be
strings and use either "date" or "date-time" as the format.

PR Checklist

General checklist

Please make sure that your PR fulfills the following requirements:

  • The commit message follows the Angular Commit Message Guidelines.
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • Dependencies have been updated as needed
  • .secrets.baseline has been updated as needed
  • npm run generate-utilities-docs has been run if any files in packages/utilities/src have been updated

Checklist for adding a new validation rule:

  • Added new validation rule definition (packages/ruleset/src/rules/*.js, index.js)
  • If necessary, added new validation rule implementation (packages/ruleset/src/functions/*.js, updated index.js)
  • Added new rule to default configuration (packages/ruleset/src/ibm-oas.js)
  • Added tests for new rule (packages/ruleset/test/*.test.js)
  • Added docs for new rule (docs/ibm-cloud-rules.md)
  • Added scoring rubric entry for new rule (packages/validator/src/scoring-tool/rubric.js)

@dpopp07 dpopp07 requested review from hudlow and padamstx December 19, 2024 16:24
@dpopp07
Copy link
Member Author

dpopp07 commented Dec 19, 2024

Whoops, forgot to update the docs - I will push that change soon! Everything else is ready to review

Docs are updated 👍

Copy link
Member

@padamstx padamstx left a comment

Choose a reason for hiding this comment

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

PR looks great!
I just had one small suggestion for date-based-utils.js.

@dpopp07 dpopp07 force-pushed the dp/date-time-rule branch 2 times, most recently from d2d9794 to a6b5ee1 Compare December 19, 2024 19:10
Copy link
Member

@padamstx padamstx left a comment

Choose a reason for hiding this comment

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

LGTM!

packages/ruleset/src/functions/use-date-based-format.js Outdated Show resolved Hide resolved
packages/ruleset/src/functions/use-date-based-format.js Outdated Show resolved Hide resolved
packages/ruleset/src/functions/use-date-based-format.js Outdated Show resolved Hide resolved
packages/ruleset/src/utils/date-based-utils.js Outdated Show resolved Hide resolved
packages/ruleset/src/utils/date-based-utils.js Outdated Show resolved Hide resolved
packages/ruleset/src/functions/use-date-based-format.js Outdated Show resolved Hide resolved
packages/ruleset/src/functions/use-date-based-format.js Outdated Show resolved Hide resolved
@dpopp07 dpopp07 requested a review from hudlow December 30, 2024 20:35
The comment noted that the rule was using the resolved API definition,
when it was, in fact, using the unresolved definition. This wasn't a
bug - the rule doesn't look at any locations that might include
references - but the documentation was wrong and misleading. This
commit fixes that.

Signed-off-by: Dustin Popp <[email protected]>
I think this file was added around the same time that the tests were re-organized
into folders. It must have been overlooked during the changes. This commit moves
it to the right spot and corrects the copyright statement (this file was created
in 2024).

Signed-off-by: Dustin Popp <[email protected]>
This commit introduces the new 'ibm-use-date-based-format' rule,
which will heuristically verify that schemas, with either a name
or an example value indicating a date-based logical type, be
strings and use either "date" or "date-time" as the format.

Signed-off-by: Dustin Popp <[email protected]>
Co-authored-by: Dan Hudlow <[email protected]>
@dpopp07 dpopp07 force-pushed the dp/date-time-rule branch from 7bac905 to 9b07fb6 Compare January 7, 2025 23:07
// parses the object, looking for the value at that path. If it finds one,
// the value will be returned. If not, the function will return `undefined`.
function getObjectValueAtPath(obj, pathToValue) {
return pathToValue.reduce((value, field) => value[field], obj);
Copy link
Member

Choose a reason for hiding this comment

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

I think this is needed to keep this safe in the case that an undefined property is encountered before the last element of the path.

Suggested change
return pathToValue.reduce((value, field) => value[field], obj);
return pathToValue.reduce((value, field) => value?.[field], obj);

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