Skip to content

Conversation

shakrav2
Copy link
Contributor

@shakrav2 shakrav2 commented Oct 16, 2025

Closes #46
Implements lint rules for AEP-142 (Time and Duration) to validate time-related fields in OpenAPI specifications.

Rules Implemented

  • aep-142-time-field-type: Validates time-related field types
  • aep-142-time-field-names: Warns about timestamp field naming
  • aep-142-time-field-suffix: Enforces _time suffix for timestamp fields

Reference

Testing

  • Added comprehensive test coverage in test/0142/
  • All 164 tests pass (28 new tests for AEP-142)
  • Code coverage: 89.65%
  • Linter passes

Documentation

  • Added rule documentation in docs/0142.md
  • Updated docs/rules.md index

Copy link
Contributor

@mkistler mkistler left a comment

Choose a reason for hiding this comment

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

Thank you for this PR! Overall it looks really good.

I think there are some problems with handling arrays -- I've suggested a few changes to the tests to suss those out.

I also want to point out that the current implementation misses date/time values passed in parameters and headers. The latter is an interesting case since AEP-142 isn't consistent with AEP-142 for headers (see #364). For parameters, I don't think there is an easy fix so I'm fine if we just create an issue for that and deal with it in a follow-on PR.

aep/0142.yaml Outdated
message: '{{error}}'
severity: warn
formats: ['oas2', 'oas3']
given: '$..[?(@property.match(/_(time|times|date|seconds|millis|micros|nanos)$/))]'
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this pattern could potentially generate some nasty false positives. This will help cut down on that:

Suggested change
given: '$..[?(@property.match(/_(time|times|date|seconds|millis|micros|nanos)$/))]'
given: '$..properties[?(@property.match(/_(time|times|date|seconds|millis|micros|nanos)$/))]'

delete_time: {
type: 'string',
format: 'date-time',
},
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the following should pass but generates an error

Suggested change
},
},
more_times: {
type: 'array',
items: {
type: 'string',
format: 'date-time',
},
},

update_time: {
type: 'string',
format: 'date-time',
},
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the following should pass but generates an error:

Suggested change
},
},
more_times: {
type: 'array',
items: {
type: 'string',
format: 'date-time',
},
},

@shakrav2
Copy link
Contributor Author

Thanks for the review! I've addressed both concerns you raised.

Changes Made

1. JSONPath Pattern (aep/0142.yaml:11)
✅ Updated from $..[?(@property.match(...))] to $..properties[?(@property.match(...))] as suggested.

This makes the pattern more specific by only targeting actual schema properties, reducing potential false positives.

2. Array Handling for _times Fields
✅ Added array support in functions/aep-142-time-field-type.js

Per AEP-142, fields ending in _times should be arrays of timestamps. The function now:

  • Detects when a field with _times suffix has type: 'array'
  • Validates that items.type === 'string' and items.format === 'date-time'
  • Provides appropriate error messages for arrays vs. scalar fields

3. Test Coverage
✅ Added more_times array test case to test/0142/time-field-type.test.js

Note on test placement: I added the more_times test only to time-field-type.test.js, not to time-field-suffix.test.js. This is because the aep-142-time-field-suffix rule pattern ($..[?(@.type == "string" && @.format == "date-time")]~) matches fields that are directly type: string, so array fields are not checked by that rule—only by the type rule.

Test Results

All 28 AEP-142 tests passing ✓

Let me know if you'd like any adjustments!

Copy link
Contributor

@mkistler mkistler left a comment

Choose a reason for hiding this comment

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

Looks good! 👍

@mkistler mkistler merged commit 3bb7da1 into aep-dev:main Oct 19, 2025
3 checks passed
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.

Implement rules for AEP-142 Time and Duration

2 participants