Skip to content

Commit

Permalink
Merge pull request #92 from jayvdb/allow-no-http
Browse files Browse the repository at this point in the history
feat: Allow disabling http feature
  • Loading branch information
kstasik authored Jun 13, 2023
2 parents 143e1e5 + 209f7cf commit afd2ff4
Show file tree
Hide file tree
Showing 17 changed files with 292 additions and 190 deletions.
378 changes: 231 additions & 147 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ repository = "https://github.com/kstasik/schema-tools"
version = "0.14.0"

[workspace.dependencies]
reqwest = { version = "0.11.12", default-features = false, features = ["blocking"] }
reqwest = { version = "0.11.12", default-features = false, features = ["default-tls", "blocking"] }
serde_json = { version = "1", features = ["preserve_order"] }
serde_yaml = "0.9.14"
log = "0.4"
Expand Down
4 changes: 2 additions & 2 deletions crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ repository.workspace = true
version.workspace = true

[features]
default = ["codegen", "git2", "json-patch"]
default = ["codegen", "git2", "http", "json-patch"]
codegen = ["schematools/codegen"]
git2 = ["schematools/git2"]
http = ["schematools/http"]
json-patch = ["schematools/json-patch"]
semver = ["schematools/semver"]

[dependencies]
serde_json = { workspace = true }
serde_yaml = { workspace = true }
reqwest = { workspace = true }
log = { workspace = true }
thiserror = { workspace = true }

Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/commands/chain.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use clap::{Parser, Subcommand};

use reqwest::blocking::Client;
use schematools::Client;

use schematools::storage::SchemaStorage;
use schematools::{discovery::Discovery, schema::Schema};
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/commands/codegen.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use reqwest::blocking::Client;
use schematools::codegen::jsonschema::JsonSchemaExtractOptions;
use schematools::Client;
use serde_json::Value;
use std::{fmt::Display, time::Instant};

Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::io::prelude::*;

use clap::{Parser, ValueEnum};
use env_logger::Builder as LoggerBuilder;
use reqwest::blocking::Client;
use schematools::Client;
use serde_json::Value;

pub mod chain;
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/commands/process/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use std::fmt::Display;

use crate::commands::GetSchemaCommand;
use clap::{Parser, Subcommand};
use reqwest::blocking::Client;
use schematools::storage::SchemaStorage;
use schematools::tools;
use schematools::Client;

use crate::error::Error;
use schematools::process::{dereference, merge_allof, merge_openapi, name};
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/commands/validate.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::fmt::Display;

use clap::Parser;
use reqwest::blocking::Client;
use schematools::Client;

use crate::error::Error;
use schematools::schema::{path_to_url, Schema};
Expand Down
3 changes: 2 additions & 1 deletion crates/cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use clap::{Parser, Subcommand};
use schematools::Client;

pub mod commands;
pub mod error;
Expand Down Expand Up @@ -29,7 +30,7 @@ enum Command {

fn main() {
let opts: Opts = Opts::parse();
let client = reqwest::blocking::Client::new();
let client = Client::new();

let result = match opts.command {
Command::Process(opts) => commands::process::execute(opts, &client),
Expand Down
11 changes: 6 additions & 5 deletions crates/schematools/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,27 @@ repository.workspace = true
version.workspace = true

[features]
default = ["codegen", "git2", "json-patch"]
default = ["codegen", "git2", "http", "json-patch"]
codegen = ["tera", "semver"]
http = ["jsonschema/resolve-http", "reqwest"]

[dependencies]
serde_json = { workspace = true }
serde_yaml = { workspace = true }
reqwest = { workspace = true }
reqwest = { workspace = true, optional = true }
log = { workspace = true }
thiserror = { workspace = true }

url = "2"
lazy_static = "1.4.0"
regex = "1"
jsonschema = { version = "0.14", default-features = false, features = ["reqwest", "reqwest-rustls-tls"] }
jsonschema = { version = "0.17", default-features = false, features = ["resolve-file"] }
tera = { version = "1", default-features = false, optional = true }
serde = { version = "1.0", features = ["derive"] }
walkdir = "2"
json-patch = { version = "0.2.6", optional = true }
json-patch = { version = "0.2.7", optional = true }
semver = { version = "1.0", optional = true }
git2 = { version = "0.16", optional = true }
git2 = { version = "0.17", optional = true }
md5 = "0.7.0"
Inflector = "0.11"
digest = "0.10.1"
Expand Down
12 changes: 12 additions & 0 deletions crates/schematools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,16 @@ pub mod storage;
pub mod tools;
pub mod validate;

#[cfg(feature = "http")]
pub use reqwest::blocking::Client;
/// A dummy client to be used when the http feature is disabled
#[cfg(not(feature = "http"))]
pub struct Client;
#[cfg(not(feature = "http"))]
impl Client {
pub fn new() -> Client {
Client {}
}
}

pub const VERSION: &str = "0.14.0";
27 changes: 15 additions & 12 deletions crates/schematools/src/process/dereference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use crate::schema::Schema;
use crate::scope::SchemaScope;
use crate::storage::{ref_to_url, SchemaStorage};

use reqwest::Url;
use serde_json::Value;
use url::Url;

pub struct Dereferencer;

Expand Down Expand Up @@ -244,7 +244,7 @@ fn process_discriminator(root: &mut Value, ctx: &mut DereferencerContext) {
#[cfg(test)]
mod tests {
use super::*;
use reqwest::Url;
use crate::Client;
use serde_json::json;

fn spec_from_file(file: &str) -> Schema {
Expand All @@ -257,7 +257,7 @@ mod tests {
fn test_infinite_ref() {
let mut spec = spec_from_file("resources/test/json-schemas/07-with-infinite-ref.json");

let client = reqwest::blocking::Client::new();
let client = Client::new();
let ss = SchemaStorage::new(&spec, &client);

Dereferencer::options()
Expand All @@ -270,7 +270,7 @@ mod tests {
fn test_string_reference() {
let mut spec = spec_from_file("resources/test/json-schemas/16-string-reference.json");

let client = reqwest::blocking::Client::new();
let client = Client::new();
let ss = SchemaStorage::new(&spec, &client);

Dereferencer::options().process(&mut spec, &ss);
Expand Down Expand Up @@ -302,7 +302,7 @@ mod tests {
fn test_discriminator() {
let mut spec = spec_from_file("resources/test/json-schemas/22-discriminator-root.json");

let client = reqwest::blocking::Client::new();
let client = Client::new();
let ss = SchemaStorage::new(&spec, &client);

Dereferencer::options()
Expand Down Expand Up @@ -372,7 +372,7 @@ mod tests {
fn test_with_local_reference() {
let mut spec = spec_from_file("resources/test/json-schemas/06-with-local-reference.json");

let client = reqwest::blocking::Client::new();
let client = Client::new();
let ss = SchemaStorage::new(&spec, &client);
Dereferencer::options().process(&mut spec, &ss);

Expand Down Expand Up @@ -422,7 +422,7 @@ mod tests {
fn test_create_internal_references() {
let mut spec = spec_from_file("resources/test/json-schemas/20-local-reference.json");

let client = reqwest::blocking::Client::new();
let client = Client::new();
let ss = SchemaStorage::new(&spec, &client);

Dereferencer::options()
Expand Down Expand Up @@ -521,11 +521,12 @@ mod tests {
}

#[test]
#[cfg(feature = "http")]
fn test_with_nested_remote_external_reference() {
let mut spec =
spec_from_file("resources/test/json-schemas/05-with-nested-remote-external-ref.json");

let client = reqwest::blocking::Client::new();
let client = Client::new();
let ss = SchemaStorage::new(&spec, &client);

Dereferencer::options().process(&mut spec, &ss);
Expand Down Expand Up @@ -556,7 +557,7 @@ mod tests {
let mut spec =
spec_from_file("resources/test/json-schemas/04-with-nested-external-ref.json");

let client = reqwest::blocking::Client::new();
let client = Client::new();
let ss = SchemaStorage::new(&spec, &client);

Dereferencer::options().process(&mut spec, &ss);
Expand Down Expand Up @@ -605,11 +606,12 @@ mod tests {
}

#[test]
#[cfg(feature = "http")]
fn test_skip_references() {
let mut spec =
spec_from_file("resources/test/json-schemas/05-with-nested-remote-external-ref.json");

let client = reqwest::blocking::Client::new();
let client = Client::new();
let ss = SchemaStorage::new(&spec, &client);

Dereferencer::options()
Expand All @@ -633,11 +635,12 @@ mod tests {
}

#[test]
#[cfg(feature = "http")]
fn test_simple_with_external_reference() {
let mut spec =
spec_from_file("resources/test/json-schemas/03-simple-with-external-ref.json");

let client = reqwest::blocking::Client::new();
let client = Client::new();
let ss = SchemaStorage::new(&spec, &client);

Dereferencer::options().process(&mut spec, &ss);
Expand Down Expand Up @@ -667,7 +670,7 @@ mod tests {
fn test_simple_with_reference() {
let mut spec = spec_from_file("resources/test/json-schemas/02-simple-with-reference.json");

let client = reqwest::blocking::Client::new();
let client = Client::new();
let ss = SchemaStorage::new(&spec, &client);

Dereferencer::options().process(&mut spec, &ss);
Expand Down
15 changes: 8 additions & 7 deletions crates/schematools/src/process/merge_allof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ fn merge_values(a: &mut Value, b: Value) {
#[cfg(test)]
mod tests {
use super::*;
use crate::Client;
use serde_json::json;

#[test]
Expand Down Expand Up @@ -242,7 +243,7 @@ mod tests {

let mut schema = Schema::from_json(value);

let client = reqwest::blocking::Client::new();
let client = Client::new();
let ss = SchemaStorage::new(&schema, &client);

Merger::options().process(&mut schema, &ss);
Expand Down Expand Up @@ -296,7 +297,7 @@ mod tests {

let mut schema = Schema::from_json(value);

let client = reqwest::blocking::Client::new();
let client = Client::new();
let ss = SchemaStorage::new(&schema, &client);

Merger::options().process(&mut schema, &ss);
Expand Down Expand Up @@ -338,7 +339,7 @@ mod tests {

let mut schema = Schema::from_json(value);

let client = reqwest::blocking::Client::new();
let client = Client::new();
let ss = SchemaStorage::new(&schema, &client);

Merger::options().process(&mut schema, &ss);
Expand Down Expand Up @@ -390,7 +391,7 @@ mod tests {

let mut schema = Schema::from_json(value);

let client = reqwest::blocking::Client::new();
let client = Client::new();
let ss = SchemaStorage::new(&schema, &client);

Merger::options().process(&mut schema, &ss);
Expand Down Expand Up @@ -462,7 +463,7 @@ mod tests {

let mut schema = Schema::from_json(value);

let client = reqwest::blocking::Client::new();
let client = Client::new();
let ss = SchemaStorage::new(&schema, &client);

Merger::options().process(&mut schema, &ss);
Expand Down Expand Up @@ -587,7 +588,7 @@ mod tests {

let mut schema = Schema::from_json(value);

let client = reqwest::blocking::Client::new();
let client = Client::new();
let ss = SchemaStorage::new(&schema, &client);

Merger::options().process(&mut schema, &ss);
Expand Down Expand Up @@ -631,7 +632,7 @@ mod tests {

let mut schema = Schema::from_json(value);

let client = reqwest::blocking::Client::new();
let client = Client::new();
let ss = SchemaStorage::new(&schema, &client);

Merger::options().process(&mut schema, &ss);
Expand Down
3 changes: 1 addition & 2 deletions crates/schematools/src/process/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ pub mod merge_openapi;
pub mod name;
pub mod patch;

use reqwest::Url;
use serde_json::Value;
use url::Url;

// this function should probably be removed in favor of schema registry
pub fn rel_to_absolute_refs(_url: &Url, mut _data: Value) -> Value {
Expand Down Expand Up @@ -86,7 +86,6 @@ where
#[cfg(test)]
mod tests {
use super::*;
use reqwest::Url;
use serde_json::json;

#[test]
Expand Down
3 changes: 1 addition & 2 deletions crates/schematools/src/resolver.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{error::Error, storage::SchemaStorage};
use reqwest::Url;
use serde_json::Value;
use url::Url;

use crate::{schema::Schema, scope::SchemaScope};

Expand Down Expand Up @@ -137,7 +137,6 @@ impl<'a> SchemaResolver<'a> {
#[cfg(test)]
mod tests {
use super::*;
use reqwest::Url;

#[test]
fn test_when_file_and_spec_are_valid() {
Expand Down
Loading

0 comments on commit afd2ff4

Please sign in to comment.