-
Notifications
You must be signed in to change notification settings - Fork 8
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: allows arrays with oneOf/anyOf/allOf definitions to pass lint #329
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
This file contains 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 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 |
---|---|---|
|
@@ -209,9 +209,14 @@ const arrayWithItemsInRequest = new RequestRule({ | |
(property) => { | ||
if (property.raw.type === "array") { | ||
if (!property.raw.items || !("type" in property.raw.items)) { | ||
throw new RuleError({ | ||
message: "type was not found array items", | ||
}); | ||
const oneOf = property.raw.items["oneOf"]; | ||
const allOf = property.raw.items["allOf"]; | ||
const anyOf = property.raw.items["anyOf"]; | ||
if (!oneOf && !allOf && !anyOf) { | ||
throw new RuleError({ | ||
message: "type was not found array items", | ||
}); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Recommend turning this into a helper, for incremental improvement as described above. Asserting a non-empty type seems like a generally useful thing we may want for property types as well as array item types. |
||
} | ||
} | ||
}, | ||
|
@@ -227,9 +232,14 @@ const arrayWithItemsInResponse = new ResponseBodyRule({ | |
(property) => { | ||
if (property.raw.type === "array") { | ||
if (!property.raw.items || !("type" in property.raw.items)) { | ||
throw new RuleError({ | ||
message: "type was not found array items", | ||
}); | ||
const oneOf = property.raw.items["oneOf"]; | ||
const allOf = property.raw.items["allOf"]; | ||
const anyOf = property.raw.items["anyOf"]; | ||
if (!oneOf && !allOf && !anyOf) { | ||
throw new RuleError({ | ||
message: "type was not found array items", | ||
}); | ||
} | ||
} | ||
} | ||
}, | ||
|
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.
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.
Should we pass if it's an empty composite type though? I think we should require at least one concrete type in here.
I suppose the worst pathological case would be nested composite types with nothing at the bottom -- so to be really comprehensive we should do a recursive descent to make sure all "leaf-node" type-paths are defined (not empty composites). This would be the most formally-correct solution.
For example, this type contains a whole lot of choices, all leading to "no type defined":
A helper function
isCompletelyDefinedType
could probably tackle this.A band-aid quick-fix solution might be to check that "all composites must contain one or more simple non-empty type" and deal with the formal solution in a followup. AFAIK no one's trying to nest composites at the moment (but it may happen unintentionally later!)
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 under the impression that there were other checks for composite types having concrete types--if not, wouldn't it be better to have those checks across all schemas rather than making that part of this check?
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.
There might be... I'll have to look (it's been a little while)
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.
Did a quick check and there aren't; I'm going to file an issue for validating that composites are completely typed, and go with a band-aid helper in this branch.
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.
#330