Skip to content
This repository has been archived by the owner on Nov 8, 2024. It is now read-only.

Fix #493 repeated item in JSON schema required #505

Merged
merged 3 commits into from
Sep 26, 2017
Merged

Conversation

klokane
Copy link
Contributor

@klokane klokane commented Sep 26, 2017

Use internally std::set to catch all "required" members and avoid repeat value

Copy link
Contributor

@tjanc tjanc left a 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


for (const auto& member: members) {
assert(member);
if (!member) {
Copy link
Contributor

@tjanc tjanc Sep 26, 2017

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.

Copy link
Contributor Author

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

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor Author

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.

Copy link
Contributor Author

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

Copy link
Contributor Author

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

@@ -637,5 +643,10 @@ namespace refract
throw LogicError("Invalid member type of object in MSON definition");
}
}

std::for_each(required.begin(), required.end(),
Copy link
Contributor

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.

@tjanc tjanc merged commit 300cf84 into master Sep 26, 2017
@tjanc tjanc deleted the klokane/fix-493 branch September 26, 2017 13:29
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants