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

Add the "contains" keyword for array instances. #113

Merged
merged 1 commit into from
Nov 7, 2016

Conversation

handrews
Copy link
Contributor

This addresses the enhancement requested in issues #32 and #63.
Only the single-schema form from #63 is added here as the multi-schema form
did not gather significant support in the absence of a clear use case.

This addresses the enhancement requested in issues json-schema-org#32 and json-schema-org#63.
Only the single-schema form from json-schema-org#63 is added here as the multi-schema form
did not gather significant support in the absence of a clear use case.
<t>
An array instance is valid against "contains" if at least one of
its elements is valid against the given schema.
</t>
Copy link
Member

Choose a reason for hiding this comment

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

or array is empty

Copy link
Member

@awwright awwright Oct 28, 2016

Choose a reason for hiding this comment

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

If I want an array to contain an item, I would think that means empty array should always be invalid.

I don't see any reason to have a special behavior for an edge case.

Is there a case I would want to treat an empty array instance as valid?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The "or array is empty" is easily handled by:

{
    "type": "array",
    "items": {...},
    "oneOf": [
        {"contains": {...}},
        {"maxItems": 0}
    ]
}

Copy link
Member

@epoberezkin epoberezkin Oct 29, 2016

Choose a reason for hiding this comment

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

It follows from contains being equivalent to:

{
    "not": {
        "items": {
            "not": {... whatever ...}
        }
    }
}

Copy link
Member

Choose a reason for hiding this comment

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

or it doesn't? :)

Copy link
Member

@epoberezkin epoberezkin Oct 29, 2016

Choose a reason for hiding this comment

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

yes, ok, should have at least one item :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, an empty array fails that schema, because an empty array passes the schema "items": {"not": {...}}, so the outer not causes it to fail overall.

@handrews
Copy link
Contributor Author

handrews commented Nov 2, 2016

@awwright @Relequestual I think all outstanding concerns here are resolved, any chance of getting this merged?

@Relequestual
Copy link
Member

I'm in favour of saying, with 3 change approvals, merging is OK to go.

@handrews
Copy link
Contributor Author

handrews commented Nov 3, 2016

I'm in favour of saying, with 3 change approvals, merging is OK to go.

Do you mean I need to get two more formal approvals? @awwright , @epoberezkin ?

@Relequestual
Copy link
Member

Actually, given the "official" people involved, that could be a bit tricky. Can non members submit reviews?

@handrews
Copy link
Contributor Author

handrews commented Nov 3, 2016

@Relequestual : Yup, as you probably noticed because I just tried it out by commenting on your PR :-)

@jdesrosiers
Copy link
Member

Let's do this. JSON Schema can do this functionality without contains, but it's ugly, verbose, and difficult to work with. I think contains is very welcome spoonful of syntactic sugar.

@Relequestual
Copy link
Member

OK. if a contributor reviews and agrees then I'll merge!

@handrews
Copy link
Contributor Author

handrews commented Nov 7, 2016

@epoberezkin , @awwright any chance I can convince either of you to be approver #3?

@awwright awwright merged commit 4090d4c into json-schema-org:master Nov 7, 2016
@awwright
Copy link
Member

awwright commented Nov 7, 2016

I'd normally wait 14 days but this seems relatively uncontroversial

@handrews
Copy link
Contributor Author

handrews commented Nov 7, 2016

Thanks @awwright . I had figured since this was was a pretty direct implementation of something that had gotten approval on the issue, that the 14 day counter included the period of agreement on the issue.

If you want pull requests to always stay open for 14 days that's good to know. I'd like to try to get the requisite approval comments as soon as possible but I'm fine with leaving things open for a minimum period. We should document that somewhere, perhaps a "contributors" section of the site? Or a wiki page in this repo?

@handrews handrews deleted the contains branch November 7, 2016 21:11
@Relequestual
Copy link
Member

I would personally like to see this info (on what will happen and how) in the repo readme. Even if JUST "we will wait 14 days before merging, if we like it"

@handrews
Copy link
Contributor Author

handrews commented Nov 8, 2016

@Relequestual I filed issue #137 to collect stuff like "we will wait 14 days" before merging. I'm tired of getting criticized for not following rules that aren't written down :-(

@awwright
Copy link
Member

awwright commented Nov 8, 2016

I was explaining what I do to help manage expectations, it's not really a
rule for people to follow.

On Nov 8, 2016 11:42 AM, "Henry Andrews" notifications@github.com wrote:

@Relequestual https://github.com/Relequestual I filed issue #137
#137 to
collect stuff like "we will wait 14 days" before merging. I'm tired of
getting criticized for not following rules that aren't written down :-(


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#113 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAatDeFYsG_IdJdfUO-ZzodQ49zVqi3lks5q8MKigaJpZM4KjsGd
.

@handrews
Copy link
Contributor Author

handrews commented Nov 8, 2016

I was explaining what I do to help manage expectations, it's not really a
rule for people to follow.

Whether it's a "rule" or some other word is not the point. The point is that it's not documented, and there are a lot of these things that are not documented. Tripping over them when you suddenly say that something I've been doing is counter-productive or pointless or trying to move too fast (and really I'm not trying to rush anything) is very frustrating. I could have just not spent time on the thing you don't want people to work on or aren't going to look at anytime remotely soon. And I don't want to be pestering people when there's a minimum deadline that hasn't been met. Etc. etc. etc.

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.

5 participants