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

HTTP Resolver Not Working? #343

Closed
rawkode opened this issue Feb 24, 2022 · 15 comments · Fixed by #351
Closed

HTTP Resolver Not Working? #343

rawkode opened this issue Feb 24, 2022 · 15 comments · Fixed by #351

Comments

@rawkode
Copy link

rawkode commented Feb 24, 2022

Hi,

Sorry, I've been trying to work this out myself, but I'm not sure what's going wrong.

Validation error: failed to resolve https://schema.rawkode.dev/organization: error sending request for url (https://schema.rawkode.dev/organization): error trying to connect: invalid URL, scheme is not http
Instance path:
Validation error: failed to resolve https://schema.rawkode.dev/person: error sending request for url (https://schema.rawkode.dev/person): error trying to connect: invalid URL, scheme is not http
Instance path:

These URLs are definitely OK and I'm not sure what I've done wrong.

I've tried using http instead of https in my schema, but the problem is the same.

Any help appreciated.

@Stranger6667
Copy link
Owner

Hi!

Thanks for reporting! Could you, please, share the schema so I can reproduce the issue?

Looks strange to me - does it work with 0.14.0? There were some changes with reference resolving

@rawkode
Copy link
Author

rawkode commented Feb 25, 2022

Sure, the schema is:

{
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
        "people": {
            "type": "array",
            "items": {
                "$ref": "https://schema.rawkode.dev/person"
            },
            "links": [
                {
                    "rel": "collection",
                    "href": "#/organizations/{id}",
                    "templateRequired": [
                        "id"
                    ]
                }
            ]
        },
        "organizations": {
            "type": "array",
            "items": {
                "$ref": "https://schema.rawkode.dev/organization"
            }
        }
    }
}

I'll test with 0.14 and report back.

@rawkode
Copy link
Author

rawkode commented Feb 25, 2022

Still a problem with 0.14. I hope this doesn't mean its my fault 😅

Let me know if you need anything else, @Stranger6667

@Stranger6667
Copy link
Owner

Thanks for sharing!

At 778b424 I cannot reproduce it locally :(

Tried this instance:

{
    "people": [
        {"name": "x", "forename": "y", "surname":  "z"}
    ],
    "organizations": [
        {"name": "a"}
    ]
}

And this command (I suppressed warnings coming from not enabled newer drafts support):

⇒  RUSTFLAGS=-Awarnings cargo r -- schema.json -i instance.json
    Finished dev [unoptimized + debuginfo] target(s) in 0.05s
     Running `target/debug/jsonschema schema.json -i instance.json`
instance.json - VALID

Though it is the same result with all features enabled (including partial Draft 2020-12 support):

⇒  cargo r --all-features -- schema.json -i instance.json
    Finished dev [unoptimized + debuginfo] target(s) in 0.05s
     Running `target/debug/jsonschema schema.json -i instance.json`
instance.json - VALID

The same happens with the --release flag.

Could you, please, provide the following:

  • How do you run jsonschema? I assume that it is the cargo-installed jsonschema binary, but I might be mistaken.
  • With what flags did you install it?

Later I'll try to create a PR with this test case to isolate it a bit (maybe I have something that hides the issue locally).

@rawkode
Copy link
Author

rawkode commented Feb 25, 2022

I'm actually using this as a library and my code looks like:

use std::{fs::File, io::BufReader};

use jsonschema::JSONSchema;

fn main() {
    let file = File::open("schema.json").unwrap();
    let reader = BufReader::new(file);
    let schema = serde_json::from_reader(reader).unwrap();

    let file = File::open("data.json").unwrap();
    let reader = BufReader::new(file);
    let instance = serde_json::from_reader(reader).unwrap();

    let compiled = JSONSchema::compile(&schema).expect("A valid schema");
    let result = compiled.validate(&instance);
    if let Err(errors) = result {
        for error in errors {
            println!("Validation error: {}", error);
            println!("Instance path: {}", error.instance_path);
        }
    }
}

My data.json looks like:

{
    "$schema": "./schema.json",
    "people": [
        {
            "forename": "David",
            "surname": "Flanagan",
            "email": "david@rawkode.dev",
            "employers": [
                "Pulumi"
            ]
        }
    ],
    "organizations": [
        {
            "name": "Pulumi"
        }
    ]
}

and my schema.json:

{
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
        "people": {
            "type": "array",
            "items": {
                "$ref": "https://schema.rawkode.dev/person"
            },
            "links": [
                {
                    "rel": "collection",
                    "href": "#/organizations/{id}",
                    "templateRequired": [
                        "id"
                    ]
                }
            ]
        },
        "organizations": {
            "type": "array",
            "items": {
                "$ref": "https://schema.rawkode.dev/organization"
            }
        }
    }
}

@rawkode
Copy link
Author

rawkode commented Feb 25, 2022

Running the jsonschema binary does work correctly, @Stranger6667

js schema.json -i data.json
data.json - VALID

I'm confused 😅

@Stranger6667
Copy link
Owner

And so am I! :) Will check it deeper

Stranger6667 added a commit that referenced this issue Feb 25, 2022
@rawkode
Copy link
Author

rawkode commented Feb 25, 2022

@Stranger6667 Am I reading that correctly? Did that test pass? 😱

@Stranger6667
Copy link
Owner

Yes 😕 Maybe it is related to some dependencies? which somehow indirectly affect reqwest? Could you, please, share your dependency tree? cargo tree - hope it is not private :)

@rawkode
Copy link
Author

rawkode commented Feb 25, 2022

active-data v0.1.0 (/Users/rawkode/Code/sandbox/active-data)
├── jsonschema v0.14.0
│   ├── ahash v0.7.6
│   │   ├── getrandom v0.2.5
│   │   │   ├── cfg-if v1.0.0
│   │   │   └── libc v0.2.119
│   │   ├── once_cell v1.9.0
│   │   └── serde v1.0.136
│   │       └── serde_derive v1.0.136 (proc-macro)
│   │           ├── proc-macro2 v1.0.36
│   │           │   └── unicode-xid v0.2.2
│   │           ├── quote v1.0.15
│   │           │   └── proc-macro2 v1.0.36 (*)
│   │           └── syn v1.0.86
│   │               ├── proc-macro2 v1.0.36 (*)
│   │               ├── quote v1.0.15 (*)
│   │               └── unicode-xid v0.2.2
│   │   [build-dependencies]
│   │   └── version_check v0.9.4
│   ├── base64 v0.13.0
│   ├── bytecount v0.6.2
│   ├── fancy-regex v0.7.1
│   │   ├── bit-set v0.5.2
│   │   │   └── bit-vec v0.6.3
│   │   └── regex v1.5.4
│   │       ├── aho-corasick v0.7.18
│   │       │   └── memchr v2.4.1
│   │       ├── memchr v2.4.1
│   │       └── regex-syntax v0.6.25
│   ├── fraction v0.9.0
│   │   ├── lazy_static v1.4.0
│   │   └── num v0.2.1
│   │       ├── num-bigint v0.2.6
│   │       │   ├── num-integer v0.1.44
│   │       │   │   └── num-traits v0.2.14
│   │       │   │       [build-dependencies]
│   │       │   │       └── autocfg v1.1.0
│   │       │   │   [build-dependencies]
│   │       │   │   └── autocfg v1.1.0
│   │       │   └── num-traits v0.2.14 (*)
│   │       │   [build-dependencies]
│   │       │   └── autocfg v1.1.0
│   │       ├── num-complex v0.2.4
│   │       │   └── num-traits v0.2.14 (*)
│   │       │   [build-dependencies]
│   │       │   └── autocfg v1.1.0
│   │       ├── num-integer v0.1.44 (*)
│   │       ├── num-iter v0.1.42
│   │       │   ├── num-integer v0.1.44 (*)
│   │       │   └── num-traits v0.2.14 (*)
│   │       │   [build-dependencies]
│   │       │   └── autocfg v1.1.0
│   │       ├── num-rational v0.2.4
│   │       │   ├── num-bigint v0.2.6 (*)
│   │       │   ├── num-integer v0.1.44 (*)
│   │       │   └── num-traits v0.2.14 (*)
│   │       │   [build-dependencies]
│   │       │   └── autocfg v1.1.0
│   │       └── num-traits v0.2.14 (*)
│   ├── iso8601 v0.4.1
│   │   └── nom v7.1.0
│   │       ├── memchr v2.4.1
│   │       └── minimal-lexical v0.2.1
│   │       [build-dependencies]
│   │       └── version_check v0.9.4
│   ├── itoa v1.0.1
│   ├── lazy_static v1.4.0
│   ├── memchr v2.4.1
│   ├── num-cmp v0.1.0
│   ├── parking_lot v0.12.0
│   │   ├── lock_api v0.4.6
│   │   │   └── scopeguard v1.1.0
│   │   └── parking_lot_core v0.9.1
│   │       ├── cfg-if v1.0.0
│   │       ├── libc v0.2.119
│   │       └── smallvec v1.8.0
│   ├── percent-encoding v2.1.0
│   ├── regex v1.5.4 (*)
│   ├── reqwest v0.11.9
│   │   ├── base64 v0.13.0
│   │   ├── bytes v1.1.0
│   │   ├── encoding_rs v0.8.30
│   │   │   └── cfg-if v1.0.0
│   │   ├── futures-core v0.3.21
│   │   ├── futures-util v0.3.21
│   │   │   ├── futures-core v0.3.21
│   │   │   ├── futures-io v0.3.21
│   │   │   ├── futures-task v0.3.21
│   │   │   ├── memchr v2.4.1
│   │   │   ├── pin-project-lite v0.2.8
│   │   │   ├── pin-utils v0.1.0
│   │   │   └── slab v0.4.5
│   │   ├── h2 v0.3.11
│   │   │   ├── bytes v1.1.0
│   │   │   ├── fnv v1.0.7
│   │   │   ├── futures-core v0.3.21
│   │   │   ├── futures-sink v0.3.21
│   │   │   ├── futures-util v0.3.21 (*)
│   │   │   ├── http v0.2.6
│   │   │   │   ├── bytes v1.1.0
│   │   │   │   ├── fnv v1.0.7
│   │   │   │   └── itoa v1.0.1
│   │   │   ├── indexmap v1.8.0
│   │   │   │   └── hashbrown v0.11.2
│   │   │   │   [build-dependencies]
│   │   │   │   └── autocfg v1.1.0
│   │   │   ├── slab v0.4.5
│   │   │   ├── tokio v1.17.0
│   │   │   │   ├── bytes v1.1.0
│   │   │   │   ├── libc v0.2.119
│   │   │   │   ├── memchr v2.4.1
│   │   │   │   ├── mio v0.8.0
│   │   │   │   │   ├── libc v0.2.119
│   │   │   │   │   └── log v0.4.14
│   │   │   │   │       └── cfg-if v1.0.0
│   │   │   │   ├── num_cpus v1.13.1
│   │   │   │   │   └── libc v0.2.119
│   │   │   │   ├── pin-project-lite v0.2.8
│   │   │   │   └── socket2 v0.4.4
│   │   │   │       └── libc v0.2.119
│   │   │   ├── tokio-util v0.6.9
│   │   │   │   ├── bytes v1.1.0
│   │   │   │   ├── futures-core v0.3.21
│   │   │   │   ├── futures-sink v0.3.21
│   │   │   │   ├── log v0.4.14 (*)
│   │   │   │   ├── pin-project-lite v0.2.8
│   │   │   │   └── tokio v1.17.0 (*)
│   │   │   └── tracing v0.1.31
│   │   │       ├── cfg-if v1.0.0
│   │   │       ├── pin-project-lite v0.2.8
│   │   │       └── tracing-core v0.1.22
│   │   │           └── lazy_static v1.4.0
│   │   ├── http v0.2.6 (*)
│   │   ├── http-body v0.4.4
│   │   │   ├── bytes v1.1.0
│   │   │   ├── http v0.2.6 (*)
│   │   │   └── pin-project-lite v0.2.8
│   │   ├── hyper v0.14.17
│   │   │   ├── bytes v1.1.0
│   │   │   ├── futures-channel v0.3.21
│   │   │   │   └── futures-core v0.3.21
│   │   │   ├── futures-core v0.3.21
│   │   │   ├── futures-util v0.3.21 (*)
│   │   │   ├── h2 v0.3.11 (*)
│   │   │   ├── http v0.2.6 (*)
│   │   │   ├── http-body v0.4.4 (*)
│   │   │   ├── httparse v1.6.0
│   │   │   ├── httpdate v1.0.2
│   │   │   ├── itoa v1.0.1
│   │   │   ├── pin-project-lite v0.2.8
│   │   │   ├── socket2 v0.4.4 (*)
│   │   │   ├── tokio v1.17.0 (*)
│   │   │   ├── tower-service v0.3.1
│   │   │   ├── tracing v0.1.31 (*)
│   │   │   └── want v0.3.0
│   │   │       ├── log v0.4.14 (*)
│   │   │       └── try-lock v0.2.3
│   │   ├── ipnet v2.3.1
│   │   ├── lazy_static v1.4.0
│   │   ├── log v0.4.14 (*)
│   │   ├── mime v0.3.16
│   │   ├── percent-encoding v2.1.0
│   │   ├── pin-project-lite v0.2.8
│   │   ├── serde v1.0.136 (*)
│   │   ├── serde_json v1.0.79
│   │   │   ├── itoa v1.0.1
│   │   │   ├── ryu v1.0.9
│   │   │   └── serde v1.0.136 (*)
│   │   ├── serde_urlencoded v0.7.1
│   │   │   ├── form_urlencoded v1.0.1
│   │   │   │   ├── matches v0.1.9
│   │   │   │   └── percent-encoding v2.1.0
│   │   │   ├── itoa v1.0.1
│   │   │   ├── ryu v1.0.9
│   │   │   └── serde v1.0.136 (*)
│   │   ├── tokio v1.17.0 (*)
│   │   └── url v2.2.2
│   │       ├── form_urlencoded v1.0.1 (*)
│   │       ├── idna v0.2.3
│   │       │   ├── matches v0.1.9
│   │       │   ├── unicode-bidi v0.3.7
│   │       │   └── unicode-normalization v0.1.19
│   │       │       └── tinyvec v1.5.1
│   │       │           └── tinyvec_macros v0.1.0
│   │       ├── matches v0.1.9
│   │       └── percent-encoding v2.1.0
│   ├── serde v1.0.136 (*)
│   ├── serde_json v1.0.79 (*)
│   ├── structopt v0.3.26
│   │   ├── clap v2.34.0
│   │   │   ├── ansi_term v0.12.1
│   │   │   ├── atty v0.2.14
│   │   │   │   └── libc v0.2.119
│   │   │   ├── bitflags v1.3.2
│   │   │   ├── strsim v0.8.0
│   │   │   ├── textwrap v0.11.0
│   │   │   │   └── unicode-width v0.1.9
│   │   │   ├── unicode-width v0.1.9
│   │   │   └── vec_map v0.8.2
│   │   ├── lazy_static v1.4.0
│   │   └── structopt-derive v0.4.18 (proc-macro)
│   │       ├── heck v0.3.3
│   │       │   └── unicode-segmentation v1.9.0
│   │       ├── proc-macro-error v1.0.4
│   │       │   ├── proc-macro-error-attr v1.0.4 (proc-macro)
│   │       │   │   ├── proc-macro2 v1.0.36 (*)
│   │       │   │   └── quote v1.0.15 (*)
│   │       │   │   [build-dependencies]
│   │       │   │   └── version_check v0.9.4
│   │       │   ├── proc-macro2 v1.0.36 (*)
│   │       │   ├── quote v1.0.15 (*)
│   │       │   └── syn v1.0.86 (*)
│   │       │   [build-dependencies]
│   │       │   └── version_check v0.9.4
│   │       ├── proc-macro2 v1.0.36 (*)
│   │       ├── quote v1.0.15 (*)
│   │       └── syn v1.0.86 (*)
│   ├── time v0.3.7
│   │   ├── libc v0.2.119
│   │   ├── num_threads v0.1.3
│   │   │   └── libc v0.2.119
│   │   └── time-macros v0.2.3 (proc-macro)
│   ├── url v2.2.2 (*)
│   └── uuid v0.8.2
└── serde_json v1.0.79 (*)

@rawkode
Copy link
Author

rawkode commented Feb 25, 2022

@Stranger6667 I've pushed the whole thing. This is very much the testing phase, there's nothing secret

https://github.com/rawkode/schemarstest

@rawkode
Copy link
Author

rawkode commented Feb 25, 2022

❯ cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.03s
     Running `target/debug/active-data`
thread 'main' panicked at 'assertion failed: result.is_ok()', src/main.rs:14:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

@Stranger6667
Copy link
Owner

Thank you so much for such detailed info :) I reproduced this behavior

Could you try adding reqwest = { version = "0.11.9", features = ["rustls"]} to Cargo.toml? After this change it works locally

@Stranger6667
Copy link
Owner

Oh, we have

reqwest = { version = ">= 0.10", features = ["blocking", "json"], default-features = false, optional = true }

which means that by default, reqwest won't have TLS enabled. Let me think about it

@Stranger6667
Copy link
Owner

Sorry that it took so long, 0.15.1 contains a proper fix :)

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

Successfully merging a pull request may close this issue.

2 participants