Skip to content
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

fix required attribute processing for json schema of oneOf #453

Merged
merged 4 commits into from
Feb 10, 2017

Conversation

goganchic
Copy link
Contributor

@goganchic goganchic commented Feb 4, 2017

This PR solves problem described in #452, but I think a bit of refactoring is required. It's possible to make it in separate PR or in this one.

Functions void JSONSchemaVisitor::operator()(const OptionElement& e) and void JSONSchemaVisitor::operator()(const ObjectElement& e) have a lot of common code (MemberElement & SelectElement processing, required attributes calculation) and I think this code a bit dirty: it's difficult to understand Select -> Option -> Select chain processing. This refactoring may take some time and it's difficult to estimate how much time it will be.

// UPDATE: refactoring complete

@kylef kylef changed the base branch from master to stable/3.x February 6, 2017 16:34
@kylef kylef changed the base branch from stable/3.x to master February 6, 2017 16:35
@pksunkara
Copy link
Contributor

@w-vi I am adding you as a reviewer too.

JSONSchemaVisitor renderer(pDefs, fixed);
Visit(renderer, *(*it));
ObjectElement *o1 = TypeQueryVisitor::as<ObjectElement>(renderer.get());
if (!o1->value.empty()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add an empty line before this.

ObjectElement *o1 = TypeQueryVisitor::as<ObjectElement>(renderer.get());
if (!o1->value.empty()) {
MemberElement *m1 = TypeQueryVisitor::as<MemberElement>(o1->value[0]->clone());
if (m1) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add an empty line before this.

m1->renderType(IElement::rCompact);
o->push_back(m1);
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary empty line.

switch (type.get()) {
case TypeQueryVisitor::Member: {
MemberElement *mr = static_cast<MemberElement*>(*it);
if (IsTypeAttribute(*(*it), "required") ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add an empty line before this.

((fixed || fixedType) && !IsTypeAttribute(*(*it), "optional"))) {

StringElement *str = TypeQueryVisitor::as<StringElement>(mr->value.first);
if (str) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add an empty line before this.


pObj = new ObjectElement;
pObj->renderType(IElement::rCompact);

addMember("properties", props);
if (!reqVals.empty()) {
addMember("required", new ArrayElement(reqVals, IElement::rCompact));
}
if (!oneOfMembers.empty()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add an empty line before this.


pObj = new ObjectElement;
pObj->renderType(IElement::rCompact);

addMember("properties", props);
if (!reqVals.empty()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add an empty line before this.

}
}
else {
Visit(*this, *(*it));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic is missing in the refactor.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, okay. Add another test case as I requested and I can merge 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.

done

- Properties
- foo: A (string, required)

- Properties
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try a test case with removing only the above line. Properties is not always needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should I add one more test with such data

# GET /ab
- response 200 (application/json)
    - Attributes (Test)
 
# Data Structures
 
## Test (object)
- One Of
    - Properties
        - foo: A (string, required)
    - bar: B (string)

or change this one?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add one more please.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor

@pksunkara pksunkara left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just 1 minor change.

- Properties
- foo: A (string, required)

- bar: B (string)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add required here.

@pksunkara
Copy link
Contributor

@goganchic Can you force push and trigger the CI again please? Thanks.

@goganchic
Copy link
Contributor Author

done

@pksunkara pksunkara merged commit cf93d13 into apiaryio:master Feb 10, 2017
@w-vi
Copy link
Member

w-vi commented Feb 10, 2017

Should've been squashed but otherwise it's all good. Cheers @goganchic

@vassilevsky
Copy link

Is it possible to include this fix in the next release?

pksunkara added a commit that referenced this pull request Apr 11, 2017
@pksunkara
Copy link
Contributor

Will do.

@vassilevsky
Copy link

Thanks a lot, Pavan! Спасибо!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants