|
1 | 1 | use atelier_core::io::{read_model_from_file, write_model_to_string};
|
| 2 | +use atelier_json::JsonReader; |
2 | 3 | use atelier_openapi::OpenApiWriter;
|
3 | 4 | use atelier_smithy::SmithyReader;
|
4 | 5 | use okapi::openapi3;
|
5 | 6 | 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 | +} |
7 | 13 |
|
8 | 14 | #[test]
|
9 | 15 | fn test_unions() {
|
10 |
| - test("union-test"); |
| 16 | + test("union-test.smithy"); |
11 | 17 | }
|
12 | 18 |
|
13 | 19 | const MANIFEST_DIR: &str = env!("CARGO_MANIFEST_DIR");
|
14 | 20 |
|
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. |
17 | 23 | 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(); |
29 | 35 |
|
30 | 36 | let mut writer = OpenApiWriter::default();
|
31 | 37 | let actual_str = write_model_to_string(&mut writer, &model).unwrap();
|
|
0 commit comments