-
Notifications
You must be signed in to change notification settings - Fork 191
feat: new linting rules for compositions keys oneOf, anyOf, allOf #2369
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
base: main
Are you sure you want to change the base?
feat: new linting rules for compositions keys oneOf, anyOf, allOf #2369
Conversation
|
|
50557a0 to
4ee9d5e
Compare
…ords feat: add proper check for mutually exclusive schemas in oneOf feat: add checks for object min/max props, required props and additionlProperties feat: add rule to the oas3_2 spec refactor: functions naming and returning type refactor: change if statement refactor: move areDuplicatedSchemas function to utility and change naming feat: add new rule no-illogical-any-of-usage chore: add new rule to type fix: getEffectiveBounds functionality, pattern check and mutualExclusibity check feat: add functionality to report more then 1 problem chore: improve warning messages feat: add proper checks, refactor and change error messages fix: error message in areDuplicatedSchemas refactor: move logic into main function, add helper function, rename utility function refactor: change naming and functionality for duplicated shcemas function refactor: nullable function and return statement fix: nullable type detection refactor: add utility functions refactor: remove functions, clean code, refactor additionalProperties refactor: functions naming, if statement chore: remove oneOf/anyOf/allOf separate rules and add one to handle different behavior feat: add proper handling for additionalProperties chore: update type feat: add functionality to handle anyOf and allOf checks
4ee9d5e to
b6216c1
Compare
tatomyr
left a comment
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.
Had a quick look. I suggest to reorganise the checks, so they cover fist for oneOfs, then anyOfs, and then allOfs. Just duplicate the checks when needed.
Will have another look after you implement those changes.
| // Helper function to get the composition keyword and schemas | ||
| const compositionData = (() => { |
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.
Please use correct naming so you don't need the comments, e.g.:
| // Helper function to get the composition keyword and schemas | |
| const compositionData = (() => { | |
| const getSchemaCompositionData = (() => { |
or something similar.
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.
Oh, wait, it's an IIFE? Then it's a bit of overengineering. You can do simply this:
const oneOfs = schema.oneOfif you prefer to have a separate variable, and then just do every needed check. Don't be afraid to repeat yourself.
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.
I was thinking about using a separate variable for every composition keyword, but in that case, i need to duplicate checks (duplicated schemas, length of schemas) for every composition keyword and the only difference will be in the warning message. So, the purpose of the IIFE is to return the schema and string, and after that to easily retrieve them in the report message and checks.
packages/core/src/rules/oas3/no-illogical-composition-keywords.ts
Outdated
Show resolved
Hide resolved
packages/core/src/rules/oas3/no-illogical-composition-keywords.ts
Outdated
Show resolved
Hide resolved
| // Helper function to get the composition keyword and schemas | ||
| const compositionData = (() => { | ||
| if (schema.oneOf && Array.isArray(schema.oneOf)) { | ||
| return { keyword: 'oneOf' as const, schemas: schema.oneOf }; |
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.
Technically, your schema could contain oneOf and allOf simultaneously. The code doesn't handle this case.
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 functionality at all doesn't resolve all nested composition keywords, because we consider, that every composition keyword is a new scope of validation.
packages/core/src/rules/oas3/no-illogical-composition-keywords.ts
Outdated
Show resolved
Hide resolved
|
|
||
| const { keyword, schemas } = compositionData; | ||
|
|
||
| // Check for minimum schema count (oneOf and anyOf require at least 2) |
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.
You don't need comments like this as the intention should be clear enough from the condition and the report message.
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.
Yeah, you are right. I just left all comments to simplify the review of PR, i will remove it after finalizing the functionality.
packages/core/src/rules/oas3/no-illogical-composition-keywords.ts
Outdated
Show resolved
Hide resolved
| return null; | ||
| })(); | ||
|
|
||
| if (!compositionData) return; |
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 duplicates the skip() functianality.
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.
Yeah, it is duplication, because it doesn't see proper type, even we check in skip method.
What/Why/How?
New linting rules to handle illogical use of composition keys:
oneOf,anyOf,allOf.Reference
Resolves #2326
Testing
Screenshots (optional)
Check yourself
Security