-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #88 from superfaceai/test/json_schema
Move json schema test next to schemas
- Loading branch information
Showing
7 changed files
with
77 additions
and
73 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
macro_rules! json_schema { | ||
($file:expr) => {{ | ||
let yaml_str = include_str!($file); | ||
let yaml: serde_yaml::Value = serde_yaml::from_str(yaml_str).expect("Valid YAML"); | ||
let json = serde_json::to_value(&yaml).expect("Valid JSON"); | ||
jsonschema::JSONSchema::compile(&json).expect("Valid JSON Schema") | ||
}}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
use serde_json::json; | ||
|
||
#[macro_use] | ||
mod common; | ||
|
||
#[test] | ||
fn test_security_values() { | ||
let schema = json_schema!("../src/schemas/security_values.yaml"); | ||
|
||
let instance = json!({ | ||
"my_basic": { | ||
"username": "username", | ||
"password": "password" | ||
}, | ||
"my_token": { | ||
"token": "token" | ||
}, | ||
"my_api_key": { | ||
"apikey": "api key" | ||
} | ||
}); | ||
let result = schema.validate(&instance); | ||
assert!(result.is_ok()); | ||
|
||
let instance = json!({ | ||
"security_config": { | ||
"unknown": "so invalid" | ||
} | ||
}); | ||
let result = schema.validate(&instance); | ||
assert!(result.is_err()); | ||
|
||
let instance = json!({ | ||
"partial_basic": { | ||
"username": "username" | ||
} | ||
}); | ||
let result = schema.validate(&instance); | ||
assert!(result.is_err()); | ||
|
||
let instance = json!({ | ||
"empty": {} | ||
}); | ||
let result = schema.validate(&instance); | ||
assert!(result.is_err()); | ||
} |