2022-08-18 18:58:55 +00:00
|
|
|
// Copyright 2022 Oxide Computer Company
|
2021-10-17 17:40:22 +00:00
|
|
|
|
|
|
|
use std::{fs::File, path::PathBuf};
|
|
|
|
|
2022-07-03 02:09:38 +00:00
|
|
|
use progenitor_impl::{
|
2022-11-14 18:51:05 +00:00
|
|
|
GenerationSettings, Generator, InterfaceStyle, TagStyle, TypePatch,
|
2022-07-03 02:09:38 +00:00
|
|
|
};
|
2021-10-17 17:40:22 +00:00
|
|
|
|
|
|
|
#[track_caller]
|
2022-07-03 02:09:38 +00:00
|
|
|
fn verify_apis(openapi_file: &str) {
|
2021-10-17 17:40:22 +00:00
|
|
|
let mut in_path = PathBuf::from("../sample_openapi");
|
|
|
|
in_path.push(format!("{}.json", openapi_file));
|
|
|
|
|
|
|
|
let file = File::open(in_path).unwrap();
|
|
|
|
let spec = serde_json::from_reader(file).unwrap();
|
2022-07-03 02:09:38 +00:00
|
|
|
|
|
|
|
let mut generator = Generator::default();
|
|
|
|
let output = generator.generate_text_normalize_comments(&spec).unwrap();
|
|
|
|
expectorate::assert_contents(
|
|
|
|
format!("tests/output/{}-positional.out", openapi_file),
|
|
|
|
&output,
|
|
|
|
);
|
|
|
|
|
|
|
|
let mut generator = Generator::new(
|
|
|
|
GenerationSettings::default()
|
|
|
|
.with_interface(InterfaceStyle::Builder)
|
2022-07-03 05:28:06 +00:00
|
|
|
.with_tag(TagStyle::Merged)
|
2022-11-14 18:51:05 +00:00
|
|
|
.with_derive("JsonSchema")
|
|
|
|
.with_patch("Name", TypePatch::default().with_derive("Hash")),
|
2022-07-03 02:09:38 +00:00
|
|
|
);
|
|
|
|
let output = generator.generate_text_normalize_comments(&spec).unwrap();
|
|
|
|
expectorate::assert_contents(
|
|
|
|
format!("tests/output/{}-builder.out", openapi_file),
|
|
|
|
&output,
|
|
|
|
);
|
|
|
|
|
|
|
|
let mut generator = Generator::new(
|
|
|
|
GenerationSettings::default()
|
|
|
|
.with_interface(InterfaceStyle::Builder)
|
|
|
|
.with_tag(TagStyle::Separate),
|
|
|
|
);
|
|
|
|
let output = generator.generate_text_normalize_comments(&spec).unwrap();
|
2021-10-17 17:40:22 +00:00
|
|
|
expectorate::assert_contents(
|
2022-07-03 02:09:38 +00:00
|
|
|
format!("tests/output/{}-builder-tagged.out", openapi_file),
|
2021-10-17 17:40:22 +00:00
|
|
|
&output,
|
2022-07-03 02:09:38 +00:00
|
|
|
);
|
2021-10-17 17:40:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_keeper() {
|
2022-07-03 02:09:38 +00:00
|
|
|
verify_apis("keeper");
|
2021-10-17 17:40:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_buildomat() {
|
2022-07-03 02:09:38 +00:00
|
|
|
verify_apis("buildomat");
|
2021-10-17 17:40:22 +00:00
|
|
|
}
|
|
|
|
|
2021-12-10 02:15:24 +00:00
|
|
|
#[test]
|
|
|
|
fn test_nexus() {
|
2022-07-03 02:09:38 +00:00
|
|
|
verify_apis("nexus");
|
2021-12-10 02:15:24 +00:00
|
|
|
}
|
|
|
|
|
2022-09-28 20:40:07 +00:00
|
|
|
#[test]
|
|
|
|
fn test_propolis_server() {
|
|
|
|
verify_apis("propolis-server");
|
|
|
|
}
|
|
|
|
|
2021-10-17 17:40:22 +00:00
|
|
|
// TODO this file is full of inconsistencies and incorrectly specified types.
|
|
|
|
// It's an interesting test to consider whether we try to do our best to
|
|
|
|
// interpret the intent or just fail.
|
|
|
|
#[ignore]
|
|
|
|
#[test]
|
|
|
|
fn test_github() {
|
2022-07-03 02:09:38 +00:00
|
|
|
verify_apis("api.github.com");
|
2021-10-17 17:40:22 +00:00
|
|
|
}
|