-
Notifications
You must be signed in to change notification settings - Fork 11
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
brendo-m
wants to merge
7
commits into
johnstonskj:main
Choose a base branch
from
brendo-m:master
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7800cd7
skeleton for openapi implementation
9921ecf
import okapi for OpenAPI types, ModelVisitor skeleton
1ad59cd
test helper compares actual OpenApi spec
ed6b515
extract title from trait or shape name
b7ae6aa
minor refactoring
fad7cab
use prettier_assertions for better string diffs
5d98680
add json AST based test file and ability to run tests against json AST
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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,44 @@ | ||
use atelier_core::io::{read_model_from_file, write_model_to_string}; | ||
use atelier_json::JsonReader; | ||
use atelier_openapi::OpenApiWriter; | ||
use atelier_smithy::SmithyReader; | ||
use okapi::openapi3; | ||
use pretty_assertions::assert_eq; | ||
use std::{ffi::OsStr, fs, path::PathBuf}; | ||
|
||
#[test] | ||
fn test_service() { | ||
test("test-service.json"); | ||
} | ||
|
||
#[test] | ||
fn test_unions() { | ||
test("union-test.smithy"); | ||
} | ||
|
||
const MANIFEST_DIR: &str = env!("CARGO_MANIFEST_DIR"); | ||
|
||
// test helper which reads either a smithy idl file or smithy json file, converts it | ||
// to openapi, and compares with the corresponding openapi spec from the /models directory. | ||
fn test(file_name: &str) { | ||
let source_file = PathBuf::from(format!("{}/tests/models/{}", MANIFEST_DIR, file_name)); | ||
let expected_file_path = source_file.with_extension("openapi.json"); | ||
|
||
let extension = source_file.extension().and_then(OsStr::to_str).unwrap(); | ||
|
||
let model = match extension { | ||
"smithy" => read_model_from_file(&mut SmithyReader::default(), source_file), | ||
"json" => read_model_from_file(&mut JsonReader::default(), source_file), | ||
_ => panic!("test input extension must be .smithy or .json"), | ||
} | ||
.unwrap(); | ||
|
||
let mut writer = OpenApiWriter::default(); | ||
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); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure if this is the best way to go about extracting traits. I'd like to is_titled but
HasTraits
is not implemented forService
. Not sure how this all fits together just yet