Skip to content

Commit

Permalink
Implement oneOf tests for rust axum
Browse files Browse the repository at this point in the history
  • Loading branch information
Victoria-Casasampere-BeeTheData committed Dec 27, 2024
1 parent ab259fa commit 42b2b4a
Show file tree
Hide file tree
Showing 38 changed files with 264 additions and 3 deletions.
11 changes: 11 additions & 0 deletions CI/circle_parallel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,21 @@ if [ "$NODE_INDEX" = "1" ]; then

sudo apt-get -y install cpanminus

# install rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y

echo "Testing perl"
(cd samples/client/petstore/perl && /bin/bash ./test.bash)

echo "Testing ruby"
(cd samples/client/petstore/ruby && mvn integration-test)
(cd samples/client/petstore/ruby-faraday && mvn integration-test)
(cd samples/client/petstore/ruby-httpx && mvn integration-test)
(cd samples/client/petstore/ruby-autoload && mvn integration-test)

echo "Testing rust"
(cd samples/server/petstore/rust-axum/output/rust-axum-oneof && mvn integration-test)

elif [ "$NODE_INDEX" = "2" ]; then
echo "Running node $NODE_INDEX to test Go"
# install haskell
Expand Down Expand Up @@ -106,6 +115,8 @@ elif [ "$NODE_INDEX" = "3" ]; then
(cd samples/client/petstore/javascript-es6 && mvn integration-test)
(cd samples/client/petstore/javascript-promise-es6 && mvn integration-test)

elif [ "$NODE_INDEX" = "4" ]; then

else
echo "Running node $NODE_INDEX ..."
java -version
Expand Down
3 changes: 3 additions & 0 deletions bin/utils/test_file_list.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,6 @@
sha256: 67a9e63e13ebddac21cb236aa015edce30f5d3bd8d6adcf50044cad00d48c45e
- filename: "samples/openapi3/client/petstore/java/jersey2-java8/src/test/java/org/openapitools/client/model/ZebraTest.java"
sha256: 15eeb6d8a9a79d0f1930b861540d9c5780d6c49ea4fdb68269ac3e7ec481e142
# rust axum test files
- filename: "samples/server/petstore/rust-axum/output/rust-axum-oneof/src/tests.rs"
sha256: 3d4198174018cc7fd9d4bcffd950609a5bd306cf03b2fa780516f4e22a566e8c
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,9 @@ public RustAxumServerCodegen() {
supportingFiles.add(new SupportingFile("header.mustache", "src", "header.rs"));
supportingFiles.add(new SupportingFile("server-mod.mustache", "src/server", "mod.rs"));
supportingFiles.add(new SupportingFile("apis-mod.mustache", apiPackage().replace('.', File.separatorChar), "mod.rs"));
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md")
.doNotOverwrite());
// The file gets overwritten regardless
supportingFiles.add(new SupportingFile("tests.mustache", "src", "tests.rs").doNotOverwrite());
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md").doNotOverwrite());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@ pub mod apis;

#[cfg(feature = "server")]
pub(crate) mod header;

#[cfg(test)]
mod tests;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#[test]
fn std_test() {
assert!(true);
}

#[tokio::test]
async fn tokio_test() {
assert!(true);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ src/header.rs
src/lib.rs
src/models.rs
src/server/mod.rs
src/tests.rs
src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ pub mod types;

#[cfg(feature = "server")]
pub(crate) mod header;

#[cfg(test)]
mod tests;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#[test]
fn std_test() {
assert!(true);
}

#[tokio::test]
async fn tokio_test() {
assert!(true);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ src/header.rs
src/lib.rs
src/models.rs
src/server/mod.rs
src/tests.rs
src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ pub mod types;

#[cfg(feature = "server")]
pub(crate) mod header;

#[cfg(test)]
mod tests;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#[test]
fn std_test() {
assert!(true);
}

#[tokio::test]
async fn tokio_test() {
assert!(true);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ src/header.rs
src/lib.rs
src/models.rs
src/server/mod.rs
src/tests.rs
src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ pub mod types;

#[cfg(feature = "server")]
pub(crate) mod header;

#[cfg(test)]
mod tests;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#[test]
fn std_test() {
assert!(true);
}

#[tokio::test]
async fn tokio_test() {
assert!(true);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ src/header.rs
src/lib.rs
src/models.rs
src/server/mod.rs
src/tests.rs
src/types.rs
3 changes: 3 additions & 0 deletions samples/server/petstore/rust-axum/output/ops-v3/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ pub mod types;

#[cfg(feature = "server")]
pub(crate) mod header;

#[cfg(test)]
mod tests;
9 changes: 9 additions & 0 deletions samples/server/petstore/rust-axum/output/ops-v3/src/tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#[test]
fn std_test() {
assert!(true);
}

#[tokio::test]
async fn tokio_test() {
assert!(true);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ src/header.rs
src/lib.rs
src/models.rs
src/server/mod.rs
src/tests.rs
src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ pub mod types;

#[cfg(feature = "server")]
pub(crate) mod header;

#[cfg(test)]
mod tests;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#[test]
fn std_test() {
assert!(true);
}

#[tokio::test]
async fn tokio_test() {
assert!(true);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ src/header.rs
src/lib.rs
src/models.rs
src/server/mod.rs
src/tests.rs
src/types.rs
3 changes: 3 additions & 0 deletions samples/server/petstore/rust-axum/output/petstore/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ pub mod types;

#[cfg(feature = "server")]
pub(crate) mod header;

#[cfg(test)]
mod tests;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#[test]
fn std_test() {
assert!(true);
}

#[tokio::test]
async fn tokio_test() {
assert!(true);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ src/header.rs
src/lib.rs
src/models.rs
src/server/mod.rs
src/tests.rs
src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ pub mod types;

#[cfg(feature = "server")]
pub(crate) mod header;

#[cfg(test)]
mod tests;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#[test]
fn std_test() {
assert!(true);
}

#[tokio::test]
async fn tokio_test() {
assert!(true);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ src/header.rs
src/lib.rs
src/models.rs
src/server/mod.rs
src/tests.rs
src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ pub mod types;

#[cfg(feature = "server")]
pub(crate) mod header;

#[cfg(test)]
mod tests;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#[test]
fn std_test() {
assert!(true);
}

#[tokio::test]
async fn tokio_test() {
assert!(true);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
.gitignore
.openapi-generator-ignore
Cargo.toml
README.md
src/apis/default.rs
Expand All @@ -8,4 +7,5 @@ src/header.rs
src/lib.rs
src/models.rs
src/server/mod.rs
src/tests.rs
src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ pub mod types;

#[cfg(feature = "server")]
pub(crate) mod header;

#[cfg(test)]
mod tests;
101 changes: 101 additions & 0 deletions samples/server/petstore/rust-axum/output/rust-axum-oneof/src/tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#[test]
fn test_oneof_schema_with_discriminator() {
use crate::models::*;

let test0 = r#"{"op": "ignored", "d": {"welcome_message": "test0"}}"#;

let test1 = r#"{"op": "Hello", "d": {"welcome_message": "test1"}}"#;
let test2 = r#"{"op": "Greeting", "d": {"greet_message": "test2"}}"#;
let test3 = r#"{"op": "Goodbye", "d": {"goodbye_message": "test3"}}"#;

let test4 = Hello {
op: "ignored".to_string(),
d: HelloD {
welcome_message: "test4".to_string(),
},
};

let test5 = Greeting {
op: "ignored".to_string(),
d: GreetingD {
greet_message: "test5".to_string(),
},
};

let test6 = Goodbye {
op: "ignored".to_string(),
d: GoodbyeD {
goodbye_message: "test6".to_string(),
},
};

let test7 = Message::Hello(test4.clone().into());
let test8 = Message::Greeting(test5.clone().into());
let test9 = Message::Goodbye(test6.clone().into());

let test10: Message = test4.clone().into();
let test11: Message = test5.clone().into();
let test12: Message = test6.clone().into();

let test13 = r#"{"op":"Hello","d":{"welcome_message":"test4"}}"#;
let test14 = r#"{"d":{"greet_message":"test5"},"op":"Greeting"}"#;
let test15 = r#"{"op":"Goodbye","d":{"goodbye_message":"test6"}}"#;

assert!(serde_json::from_str::<Message>(test0).is_err());

assert!(serde_json::from_str::<Hello>(test0).is_ok());
assert!(serde_json::from_str::<Greeting>(test0).is_err());
assert!(serde_json::from_str::<Goodbye>(test0).is_err());

assert!(serde_json::from_str::<Message>(test1).is_ok());
assert!(serde_json::from_str::<Message>(test2).is_ok());
assert!(serde_json::from_str::<Message>(test3).is_ok());

assert!(serde_json::from_str::<Hello>(test1).is_ok());
assert!(serde_json::from_str::<Greeting>(test2).is_ok());
assert!(serde_json::from_str::<Message>(test3).is_ok());

assert_eq!(
serde_json::to_string(&test4).expect("Serialization error"),
test13
);
assert_eq!(
serde_json::to_string(&test5).expect("Serialization error"),
test14
);
assert_eq!(
serde_json::to_string(&test6).expect("Serialization error"),
test15
);

assert_eq!(
serde_json::to_string(&test7).expect("Serialization error"),
test13
);
assert_eq!(
serde_json::to_string(&test8).expect("Serialization error"),
test14
);
assert_eq!(
serde_json::to_string(&test9).expect("Serialization error"),
test15
);

assert_eq!(
serde_json::to_string(&test10).expect("Serialization error"),
test13
);
assert_eq!(
serde_json::to_string(&test11).expect("Serialization error"),
test14
);
assert_eq!(
serde_json::to_string(&test12).expect("Serialization error"),
test15
);
}

#[tokio::test]
async fn tokio_test() {
assert!(true);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ src/header.rs
src/lib.rs
src/models.rs
src/server/mod.rs
src/tests.rs
src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ pub mod types;

#[cfg(feature = "server")]
pub(crate) mod header;

#[cfg(test)]
mod tests;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#[test]
fn std_test() {
assert!(true);
}

#[tokio::test]
async fn tokio_test() {
assert!(true);
}
Loading

0 comments on commit 42b2b4a

Please sign in to comment.