Skip to content

Commit 2487d02

Browse files
author
Brendan McKee
committed
add json AST based test file and ability to run tests against json AST
1 parent fad7cab commit 2487d02

File tree

4 files changed

+722
-16
lines changed

4 files changed

+722
-16
lines changed

atelier-openapi/Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ all-features = true
1818

1919
[dependencies]
2020
atelier_core = { version = "~0.2", path = "../atelier-core" }
21-
okapi = { git = "https://github.com/GREsau/okapi" }
21+
okapi = "0.7.0-rc.1"
2222
serde_json = "1.0"
2323

2424
[dev-dependencies]
2525
atelier_test = { version = "0.1", path = "../atelier-test" }
2626
atelier_smithy = { version = "~0.2", path = "../atelier-smithy" }
27+
atelier_json = { version = "~0.2", path = "../atelier-json" }
2728
pretty_assertions = "1.1"

atelier-openapi/tests/describe_openapi_writer.rs

+21-15
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,37 @@
11
use atelier_core::io::{read_model_from_file, write_model_to_string};
2+
use atelier_json::JsonReader;
23
use atelier_openapi::OpenApiWriter;
34
use atelier_smithy::SmithyReader;
45
use okapi::openapi3;
56
use pretty_assertions::assert_eq;
6-
use std::{fs, path::PathBuf};
7+
use std::{ffi::OsStr, fs, path::PathBuf};
8+
9+
#[test]
10+
fn test_service() {
11+
test("test-service.json");
12+
}
713

814
#[test]
915
fn test_unions() {
10-
test("union-test");
16+
test("union-test.smithy");
1117
}
1218

1319
const MANIFEST_DIR: &str = env!("CARGO_MANIFEST_DIR");
1420

15-
// test helper which reads a smithy file, converts it to openapi, and compares with the
16-
// corresponding openapi spec from the /models directory.
21+
// test helper which reads either a smithy idl file or smithy json file, converts it
22+
// to openapi, and compares with the corresponding openapi spec from the /models directory.
1723
fn test(file_name: &str) {
18-
let source_file = PathBuf::from(format!(
19-
"{}/tests/models/{}.smithy",
20-
MANIFEST_DIR, file_name
21-
));
22-
let expected_file_path = PathBuf::from(format!(
23-
"{}/tests/models/{}.openapi.json",
24-
MANIFEST_DIR, file_name
25-
));
26-
27-
let mut reader = SmithyReader::default();
28-
let model = read_model_from_file(&mut reader, source_file).unwrap();
24+
let source_file = PathBuf::from(format!("{}/tests/models/{}", MANIFEST_DIR, file_name));
25+
let expected_file_path = source_file.with_extension("openapi.json");
26+
27+
let extension = source_file.extension().and_then(OsStr::to_str).unwrap();
28+
29+
let model = match extension {
30+
"smithy" => read_model_from_file(&mut SmithyReader::default(), source_file),
31+
"json" => read_model_from_file(&mut JsonReader::default(), source_file),
32+
_ => todo!(),
33+
}
34+
.unwrap();
2935

3036
let mut writer = OpenApiWriter::default();
3137
let actual_str = write_model_to_string(&mut writer, &model).unwrap();

0 commit comments

Comments
 (0)