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

skeleton for openapi implementation #43

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion atelier-openapi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ all-features = true

[dependencies]
atelier_core = { version = "~0.2", path = "../atelier-core" }
okapi = "0.4.0"
okapi = { git = "https://github.com/GREsau/okapi" }
serde_json = "1.0"

[dev-dependencies]
Expand Down
43 changes: 14 additions & 29 deletions atelier-openapi/tests/describe_openapi_writer.rs
Original file line number Diff line number Diff line change
@@ -1,53 +1,38 @@
use atelier_core::io::{read_model_from_file, write_model_to_string, ModelWriter};
use atelier_core::io::{read_model_from_file, write_model_to_string};
use atelier_openapi::OpenApiWriter;
use atelier_smithy::SmithyReader;
use atelier_test::parse_and_compare_to_files;
use std::{
fs,
path::{Path, PathBuf},
};
use std::{fs, path::PathBuf};

use okapi::openapi3;

#[test]
fn test_smithy_prelude() {
fn test_unions() {
test("union-test");
}

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

// test helper which reads a smithy file, converts it to openapi, and compares with the
// corresponding openapi spec from the /models directory.
// just a naive line by line equality check for now until we have a real model to work with
fn test(file_name: &str) {
let source_file = PathBuf::from(format!(
"{}/tests/models/{}.smithy",
MANIFEST_DIR, file_name
));
let expected_file = PathBuf::from(format!(
let expected_file_path = PathBuf::from(format!(
"{}/tests/models/{}.openapi.jsoN",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jsoN?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

woops, will fix

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:) no problem

MANIFEST_DIR, file_name
));

let mut reader = SmithyReader::default();
let model = read_model_from_file(&mut reader, PathBuf::from(source_file)).unwrap();
let model = read_model_from_file(&mut reader, source_file).unwrap();

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

let expected_lines: Vec<String> = fs::read_to_string(expected_file)
.unwrap()
.split('\n')
// .split(LINE_ENDING)
.map(|s| {
format!(
"{:?}",
s.replace("\\n", "\n")
.replace("\\t", "\t")
.replace("\\\"", "\"")
)
})
.collect();

let actual_lines: Vec<&str> = output.split("\n").collect();

assert_eq!(actual_lines, expected_lines);
let actual_str = write_model_to_string(&mut writer, &model).unwrap();
let actual_spec: openapi3::OpenApi = serde_json::from_str(&actual_str).unwrap();

let expected_file = fs::read_to_string(expected_file_path).unwrap();
let expected_spec: openapi3::OpenApi = serde_json::from_str(&expected_file).unwrap();

assert_eq!(actual_spec, expected_spec);
}