Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
26 changes: 26 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ members = [
"progenitor-client",
"progenitor-impl",
"progenitor-macro",
"test-progenitor-compilation"
]

resolver = "2"
Expand Down
9 changes: 9 additions & 0 deletions progenitor-impl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,23 @@ typify = { workspace = true }
unicode-ident = { workspace = true }

[dev-dependencies]
anyhow = { workspace = true }
base64 = { workspace = true }
clap = { workspace = true, features = ["string"] }
chrono = { workspace = true }
dropshot = { workspace = true }
expectorate = { workspace = true }
futures = { workspace = true }
http = { workspace = true }
hyper = { workspace = true }
progenitor-client = { workspace = true }
rand = { workspace = true }
regress = { workspace = true }
reqwest = { workspace = true }
rustfmt-wrapper = { workspace = true }
schemars = { workspace = true }
semver = { workspace = true }
serde_yaml = { workspace = true }
test-progenitor-compilation = { path = "../test-progenitor-compilation" }
tokio = { workspace = true }
uuid = { workspace = true }
46 changes: 46 additions & 0 deletions progenitor-impl/tests/test_compilation.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright 2022 Oxide Computer Company

use test_progenitor_compilation::cli_tokens;

#[test]
fn test_keeper_compilation() {
cli_tokens!("keeper.json");
}

#[test]
fn test_buildomat_compilation() {
cli_tokens!("buildomat.json");
}

#[test]
fn test_nexus_compilation() {
cli_tokens!("nexus.json");
}

#[test]
fn test_propolis_server_compilation() {
cli_tokens!("propolis-server.json");
}

#[test]
fn test_param_override_compilation() {
cli_tokens!("param-overrides.json");
}

#[test]
fn test_yaml_compilation() {
cli_tokens!("param-overrides.yaml");
}

#[test]
fn test_param_collision_compilation() {
cli_tokens!("param-collision.json");
}

// 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.
// #[test]
// fn test_github() {
// cli_tokens!("api.github.com.json");
// }
24 changes: 24 additions & 0 deletions test-progenitor-compilation/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[package]
name = "test-progenitor-compilation"
version = "0.1.0"
edition = "2021"
license = "MPL-2.0"
description = "An OpenAPI client generator - compilation test macro"
repository = "https://github.com/oxidecomputer/progenitor.git"

[lib]
proc-macro = true

[dependencies]
dropshot = { workspace = true }
expectorate = { workspace = true }
http = { workspace = true }
hyper = { workspace = true }
openapiv3 = { workspace = true }
proc-macro2 = { workspace = true }
progenitor-impl = { workspace = true }
quote = { workspace = true }
schemars = { workspace = true }
serde_yaml = { workspace = true }
serde_json = { workspace = true }
syn = { workspace = true }
58 changes: 58 additions & 0 deletions test-progenitor-compilation/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright 2022 Oxide Computer Company

extern crate proc_macro;

use openapiv3::OpenAPI;
use proc_macro::TokenStream;
use progenitor_impl::{GenerationSettings, Generator, InterfaceStyle, TagStyle};
use quote::quote;
use std::{
fs::File,
path::{Path, PathBuf},
};

#[proc_macro]
pub fn cli_tokens(item: TokenStream) -> TokenStream {
let arg = item.to_string().replace("\"", "");
let mut in_path = PathBuf::from("sample_openapi");
in_path.push(arg);

let spec = load_api(in_path);

let mut generator = Generator::new(
GenerationSettings::default()
.with_interface(InterfaceStyle::Builder)
.with_tag(TagStyle::Merged)
.with_derive("schemars::JsonSchema"),
);

// Builder generation with tags.
let sdk = generator.generate_tokens(&spec).unwrap();

// CLI generation.
let cli = generator.cli(&spec, "sdk").unwrap();

quote! {
pub mod sdk {
#sdk
}
use sdk::*;

#cli
}
.into()
}

fn load_api<P>(p: P) -> OpenAPI
where
P: AsRef<Path> + std::clone::Clone + std::fmt::Debug,
{
let mut f = File::open(p.clone()).unwrap();
match serde_json::from_reader(f) {
Ok(json_value) => json_value,
_ => {
f = File::open(p).unwrap();
serde_yaml::from_reader(f).unwrap()
}
}
}
Loading