-
Notifications
You must be signed in to change notification settings - Fork 22
fix(ls): add validation for examples with date-time format #5155
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7fb22e5
fix(ls): add validation for examples with date-time format
glowcloud a505f01
fix(ls): constrain days and handle `null` type
glowcloud 74288d9
fix(ls): handle nullable
glowcloud 9af257a
refactor(ls): use temporal polyfill
glowcloud e5b5cb8
Merge branch 'main' into fix/oss-914-date-time-validation
glowcloud File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
packages/apidom-ls/src/config/common/schema/lint/example--date-time.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import { DiagnosticSeverity } from 'vscode-languageserver-types'; | ||
|
|
||
| import ApilintCodes from '../../../codes.ts'; | ||
| import { LinterMeta } from '../../../../apidom-language-types.ts'; | ||
| import { OpenAPI2, OpenAPI3 } from '../../../openapi/target-specs.ts'; | ||
|
|
||
| const exampleDateTimeLint: LinterMeta = { | ||
| code: ApilintCodes.SCHEMA_EXAMPLE_DATE_TIME, | ||
| source: 'apilint', | ||
| message: 'example value must be a valid date-time string (RFC 3339)', | ||
| severity: DiagnosticSeverity.Error, | ||
| linterFunction: 'apilintValidDateTimeExample', | ||
| linterParams: [], | ||
| marker: 'value', | ||
| target: 'example', | ||
| data: {}, | ||
| targetSpecs: [...OpenAPI2, ...OpenAPI3], | ||
| conditions: [ | ||
| { | ||
| targets: [{ path: 'format' }], | ||
| function: 'apilintValueOrArray', | ||
| params: [['date-time']], | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| export default exampleDateTimeLint; |
27 changes: 27 additions & 0 deletions
27
packages/apidom-ls/src/config/common/schema/lint/examples--date-time.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import { DiagnosticSeverity } from 'vscode-languageserver-types'; | ||
|
|
||
| import ApilintCodes from '../../../codes.ts'; | ||
| import { LinterMeta } from '../../../../apidom-language-types.ts'; | ||
| import { OpenAPI31, OpenAPI32 } from '../../../openapi/target-specs.ts'; | ||
|
|
||
| const examplesDateTimeLint: LinterMeta = { | ||
| code: ApilintCodes.SCHEMA_EXAMPLES_DATE_TIME, | ||
| source: 'apilint', | ||
| message: 'examples values must be valid date-time strings (RFC 3339)', | ||
| severity: DiagnosticSeverity.Error, | ||
| linterFunction: 'apilintValidDateTimeExample', | ||
| linterParams: [true], | ||
| marker: 'value', | ||
| target: 'examples', | ||
| data: {}, | ||
| targetSpecs: [...OpenAPI31, ...OpenAPI32], | ||
| conditions: [ | ||
| { | ||
| targets: [{ path: 'format' }], | ||
| function: 'apilintValueOrArray', | ||
| params: [['date-time']], | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| export default examplesDateTimeLint; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
packages/apidom-ls/test/fixtures/validation/oas/example-date-time.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| openapi: 3.0.4 | ||
| info: | ||
| title: Example API | ||
| version: 1.0.0 | ||
| paths: | ||
| /example: | ||
| get: | ||
| responses: | ||
| '200': | ||
| description: OK | ||
| content: | ||
| application/json: | ||
| schema: | ||
| properties: | ||
| # basic date-time | ||
| dateTimeValid1: | ||
| type: string | ||
| format: date-time | ||
| example: '2025-12-18T06:43:17.913Z' | ||
|
|
||
| # date-time with timezone offset | ||
| dateTimeValid2: | ||
| type: string | ||
| format: date-time | ||
| example: '2025-12-18T06:43:17.913+00:00' | ||
|
|
||
| # date-time with lower case "t" and timezone offset | ||
| dateTimeValid3: | ||
| type: string | ||
| format: date-time | ||
| example: '2025-12-18t06:43:17.913+07:00' | ||
|
|
||
| # date-time with negative timezone offset | ||
| dateTimeValid4: | ||
| type: string | ||
| format: date-time | ||
| example: '2025-12-18T06:43:17.913-07:00' | ||
|
|
||
| # leap year | ||
| dateTimeValid5: | ||
| type: string | ||
| format: date-time | ||
| example: '2024-02-29T06:43:17.913Z' | ||
|
|
||
| # date-time without type defined | ||
| dateTimeValid6: | ||
| format: date-time | ||
| example: '2025-12-18T06:43:17.913Z' | ||
|
|
||
| # non-string type with date-time format | ||
| dateTimeValid7: | ||
| type: object | ||
| format: date-time | ||
| example: | ||
| test: 123 | ||
|
|
||
| # non-string type with date-time format and string example | ||
| dateTimeValid8: | ||
| type: object | ||
| format: date-time | ||
| example: 'not a date-time' | ||
|
|
||
| # nullable date-time | ||
| dateTimeValid9: | ||
| type: string | ||
| format: date-time | ||
| nullable: true | ||
| example: null | ||
|
|
||
| # date-time without "T" separator | ||
| dateTimeInvalid1: | ||
| type: string | ||
| format: date-time | ||
| example: '2025-12-18 06:43:17.913Z' | ||
|
|
||
| # date with invalid month | ||
| dateTimeInvalid2: | ||
| type: string | ||
| format: date-time | ||
| example: '2025-20-18T06:43:17.913Z' | ||
|
|
||
| # date with invalid day | ||
| dateTimeInvalid3: | ||
| type: string | ||
| format: date-time | ||
| example: '2025-11-31T06:43:17.913Z' | ||
|
|
||
| # date-time without "Z" or timezone offset | ||
| dateTimeInvalid4: | ||
| type: string | ||
| format: date-time | ||
| example: '2025-12-30T06:43:17.913' | ||
|
|
||
| # date-time with extra text | ||
| dateTimeInvalid5: | ||
| type: string | ||
| format: date-time | ||
| example: '2025-12-18T06:43:17.913Z UTC' | ||
|
|
||
| # date-time with completely invalid string | ||
| dateTimeInvalid6: | ||
| type: string | ||
| format: date-time | ||
| example: 'invalid' | ||
|
|
||
| # date-time with numeric value | ||
| dateTimeInvalid7: | ||
| type: string | ||
| format: date-time | ||
| example: 123 | ||
|
|
||
| # date-time with invalid leap year | ||
| dateTimeInvalid8: | ||
| type: string | ||
| format: date-time | ||
| example: '2025-02-29T06:43:17.913Z' | ||
|
|
||
| # date-time without type defined and with non-string example value | ||
| dateTimeInvalid9: | ||
| format: date-time | ||
| example: 123 | ||
|
|
||
| # nullable date-time with string null example | ||
| dateTimeInvalid10: | ||
| type: string | ||
| format: date-time | ||
| nullable: true | ||
| example: 'null' |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.