-
Notifications
You must be signed in to change notification settings - Fork 54
Fix #493 repeated item in JSON schema required #505
Conversation
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.
Two general remarks:
- this is just a quickfix (which is fine)
- there are no unit tests for JSONSchemaVisitor; if you find the time you should add them
src/refract/JSONSchemaVisitor.cc
Outdated
|
||
for (const auto& member: members) { | ||
assert(member); | ||
if (!member) { |
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 conditional is never entered. Otherwise line 590 would assert.
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.
Agree, but I do not want to crash drafter with nullptr
on production
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.
Drafter wouldn't necessarily crash. It would yield to undefined behaviour, which is even worse. Nevertheless, the assert makes the branch impossible to unit test, so either choose an assert, or a conditional.
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.
And if you use a conditional, that path is definitely untested without unit tests for JSONSchemaVisitor.
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.
In general, there can be nullptr.
Then I will remove assert
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 is problem with testing, it is private function. We need bigger refactoring for this.
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.
At first look, it seem it is independent function and it can be isolated out of class
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.
So it use members fixed
, fixedType
, pDefs
.
Will try to fix it, but not sure if able finish before sprint end
src/refract/JSONSchemaVisitor.cc
Outdated
@@ -637,5 +643,10 @@ namespace refract | |||
throw LogicError("Invalid member type of object in MSON definition"); | |||
} | |||
} | |||
|
|||
std::for_each(required.begin(), required.end(), |
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.
Use std::transform with std::inserter.
9bd9bce
to
c446b59
Compare
Use internally
std::set
to catch all "required" members and avoid repeat value