Skip to content

oneOf with a not exist format #482

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

Closed
saosir opened this issue Oct 25, 2018 · 5 comments
Closed

oneOf with a not exist format #482

saosir opened this issue Oct 25, 2018 · 5 comments

Comments

@saosir
Copy link

saosir commented Oct 25, 2018

The code run on windows without socket.inet_pton, why the message is 1.1.1.1 is valid under .....

from jsonschema import validate, FormatChecker, Draft4Validator

schema = {
    "type": "object",
    "properties": {
        "data": {
            "type": "object",
            "properties": {
                "name": {"type": "string", "maxLength": 128},
                "ip": {"oneOf": [{"format": "ipv4"}, {"format": "ipv6"}], "type": "string",},
            },
            "required": ["name", "ip"]
        }
    },
    "required": ["data"]
}


validator = Draft4Validator(schema, format_checker=FormatChecker())
d = {"data": {"ip": "1.1.1.1", "name":"x" }}
# will print:
# '1.1.1.1' is valid under each of {'format': 'ipv6'}, {'format': 'ipv4'}
for e in validator.iter_errors(d):
    print e.message

# print nothing
d = {"data": {"ip": "x", "name":"x" }}
for e in validator.iter_errors(d):
    print e.message
@Julian
Copy link
Member

Julian commented Oct 25, 2018

IPv6 support doesn't exist on Windows, so format: ipv6 passes on Windows, meaning your first example is valid under both schemas, and your second fails only IPv4, IPv6 passes.

@saosir
Copy link
Author

saosir commented Oct 26, 2018

I think format: ipv6 not support on Windows should raise a exception

@Julian
Copy link
Member

Julian commented Oct 26, 2018

The spec says format is essentially best effort, and that it's equally for documentation as for validation. Draft 8 is changing that a bit, but as is, this is just what the spec says to do more or less.

@saosir
Copy link
Author

saosir commented Oct 29, 2018

thanks~

@saosir saosir closed this as completed Oct 29, 2018
@handrews
Copy link

Julian added a commit that referenced this issue Aug 24, 2021
ab0b1ae71 fix draft4 schemas
0df96bc38 group tests to avoid duplicating test descriptions
93293efca fix indentation
76b529ff6 Merge pull request #482 from json-schema-org/ether/more-date-time-tests
57f1d63d7 some more tests for "date" and "time" formats

git-subtree-dir: json
git-subtree-split: ab0b1ae710158817af2e48556e22377363aeb169
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

No branches or pull requests

3 participants