-
Notifications
You must be signed in to change notification settings - Fork 91
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
base: main
Are you sure you want to change the base?
Conversation
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]>
Docs are updated 👍 |
There was a problem hiding this 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
.
7856f0a
to
d2d9794
Compare
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]>
d2d9794
to
a6b5ee1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
* @returns an array containing the violations found or [] if no violations | ||
*/ | ||
function checkForDateBasedFormat(s, p, apidef) { | ||
const examples = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1/3: declare array for examples at all levels of the schema hierarchy.
|
||
// Either use the schema example directly or search the list of examples | ||
// for an example object that contains a value for this property. | ||
const exampleValue = schema.example || findExample(propertyPath, examples); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't composition-aware, so it will miss examples in schemas like this:
{
"type": "string",
"allOf": [
{
"example": "2024-12-19"
}
]
}
Signed-off-by: Dustin Popp <[email protected]> Co-authored-by: Dan Hudlow <[email protected]>
expect(isDateBasedName('create_date')).toBe(true); | ||
expect(isDateBasedName('created_time')).toBe(true); | ||
expect(isDateBasedName('created_date')).toBe(true); | ||
expect(isDateBasedName('modify_time')).toBe(true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something about this (and other things like running_time
for a movie, or hang_time
for a football) feels like it could conceivably be a duration, which makes me reluctant to flag these for integer types. That's why I currently don't check for these. What do you think @hudlow ?
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:
.secrets.baseline
has been updated as needednpm run generate-utilities-docs
has been run if any files inpackages/utilities/src
have been updatedChecklist for adding a new validation rule: