Skip to content

Added support for 'file://' URL schema on the RefResolver #531

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
wants to merge 1 commit into from

Conversation

USSX-Hares
Copy link

Fixes #398

Difference

Before this fix, RefResolver created with base_uri starting with file:// could work not properly.

Example code to test:

import os.path
import json

from jsonschema import validate, RefResolver

contact = \
{
    "name": "William Johns",
    "age": 25,
    "birthDate": { "month": "apr", "day": 15 }
}

def main():
    schema_path = "schemas/main_schema.json"
    schema = json.load(open(schema_path))
    validate(contact, schema, resolver=RefResolver(base_uri='file://' + os.path.dirname(os.path.abspath(schema_path)), referrer=schema))

if (__name__ == '__main__'):
    main()

Work tree:

    /
    +-- code.py
    +-- schemas /
    |   +-- dependencies /
    |   |   +-- date.json
    |   |   +-- month.json
    |   |   +-- positive_integer.json
    |   +-- main_schema.json

$ref Dependencies:

main_schema => date, positive_integer
date => month, positive_integer

Tests

Tests passed on:

  • Windows 7, Python 2.7.15
  • Windows 7, Python 3.5.2
  • Windows 7, Python 3.7.2

Would also test on:

  • Linux (Ubuntu 16.04), Python 2.7.
  • Linux (Ubuntu 16.04), Python 3.5.2
  • Linux (Ubuntu 16.04), Python 3.6.7
  • Linux (Ubuntu 16.04), Python 3.7.2

@codecov
Copy link

codecov bot commented Feb 28, 2019

Codecov Report

Merging #531 into master will decrease coverage by 0.07%.
The diff coverage is 87.5%.

@@            Coverage Diff            @@
##           master    #531      +/-   ##
=========================================
- Coverage   96.27%   96.2%   -0.08%     
=========================================
  Files          19      19              
  Lines        2416    2422       +6     
  Branches      314     316       +2     
=========================================
+ Hits         2326    2330       +4     
- Misses         77      78       +1     
- Partials       13      14       +1

1 similar comment
@codecov
Copy link

codecov bot commented Feb 28, 2019

Codecov Report

Merging #531 into master will decrease coverage by 0.07%.
The diff coverage is 87.5%.

@@            Coverage Diff            @@
##           master    #531      +/-   ##
=========================================
- Coverage   96.27%   96.2%   -0.08%     
=========================================
  Files          19      19              
  Lines        2416    2422       +6     
  Branches      314     316       +2     
=========================================
+ Hits         2326    2330       +4     
- Misses         77      78       +1     
- Partials       13      14       +1

@Julian
Copy link
Member

Julian commented Feb 28, 2019

Hi! Thanks.

I don't remember the behavior here off hand, but does this work with requests?

If so now that requests is as prevalent I'm more inclined to just drop support for ref resolution without it.

@USSX-Hares
Copy link
Author

@Julian did not try to use requests for accessing local files. I'm not sure if this would work.

@Julian Julian mentioned this pull request Aug 19, 2019
@Julian Julian closed this Oct 31, 2019
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.

jsonschema validation fails to resolve “grandchild” local file references
2 participants