From b809a3674eead1e28de8325aa2ec73a47440f76d Mon Sep 17 00:00:00 2001 From: John Vandenberg Date: Fri, 8 Dec 2023 08:55:59 +0800 Subject: [PATCH] Allow API to reside at submodule of crate --- progenitor-impl/src/cli.rs | 13 +++++++++---- progenitor-impl/src/httpmock.rs | 7 +++++-- progenitor-impl/tests/output/buildomat-cli.out | 7 ++++--- progenitor-impl/tests/output/keeper-cli.out | 7 ++++--- progenitor-impl/tests/output/nexus-cli.out | 7 ++++--- .../tests/output/param-collision-cli.out | 7 ++++--- .../tests/output/param-overrides-cli.out | 7 ++++--- .../tests/output/propolis-server-cli.out | 7 ++++--- 8 files changed, 38 insertions(+), 24 deletions(-) diff --git a/progenitor-impl/src/cli.rs b/progenitor-impl/src/cli.rs index e03067b2..7b936c5b 100644 --- a/progenitor-impl/src/cli.rs +++ b/progenitor-impl/src/cli.rs @@ -100,15 +100,20 @@ impl Generator { }) .collect::>(); - let crate_ident = format_ident!("{}", crate_name); + let crate_path = syn::TypePath { + qself: None, + path: syn::parse_str(&crate_name).unwrap(), + }; let code = quote! { + use #crate_path::*; + pub struct Cli { - client: #crate_ident::Client, + client: Client, over: T, } impl Cli { - pub fn new(client: #crate_ident::Client) -> Self { + pub fn new(client: Client) -> Self { Self { client, over: () } } @@ -125,7 +130,7 @@ impl Generator { impl Cli { pub fn new_with_override( - client: #crate_ident::Client, + client: Client, over: T, ) -> Self { Self { client, over } diff --git a/progenitor-impl/src/httpmock.rs b/progenitor-impl/src/httpmock.rs index 1689590e..ee2f561e 100644 --- a/progenitor-impl/src/httpmock.rs +++ b/progenitor-impl/src/httpmock.rs @@ -79,7 +79,10 @@ impl Generator { let then_impl = methods.iter().map(|op| &op.then_impl).collect::>(); - let crate_ident = format_ident!("{}", crate_name); + let crate_path = syn::TypePath { + qself: None, + path: syn::parse_str(&crate_name).unwrap(), + }; let code = quote! { pub mod operations { @@ -89,7 +92,7 @@ impl Generator { //! its inner type with a call to `into_inner()`. This can //! be used to explicitly deviate from permitted values. - use #crate_ident::*; + use #crate_path::*; #( pub struct #when(httpmock::When); diff --git a/progenitor-impl/tests/output/buildomat-cli.out b/progenitor-impl/tests/output/buildomat-cli.out index 1292e679..3c61994a 100644 --- a/progenitor-impl/tests/output/buildomat-cli.out +++ b/progenitor-impl/tests/output/buildomat-cli.out @@ -1,10 +1,11 @@ +use sdk::*; pub struct Cli { - client: sdk::Client, + client: Client, over: T, } impl Cli { - pub fn new(client: sdk::Client) -> Self { + pub fn new(client: Client) -> Self { Self { client, over: () } } @@ -317,7 +318,7 @@ impl Cli { } impl Cli { - pub fn new_with_override(client: sdk::Client, over: T) -> Self { + pub fn new_with_override(client: Client, over: T) -> Self { Self { client, over } } diff --git a/progenitor-impl/tests/output/keeper-cli.out b/progenitor-impl/tests/output/keeper-cli.out index 69a5f07b..eb12f210 100644 --- a/progenitor-impl/tests/output/keeper-cli.out +++ b/progenitor-impl/tests/output/keeper-cli.out @@ -1,10 +1,11 @@ +use sdk::*; pub struct Cli { - client: sdk::Client, + client: Client, over: T, } impl Cli { - pub fn new(client: sdk::Client) -> Self { + pub fn new(client: Client) -> Self { Self { client, over: () } } @@ -183,7 +184,7 @@ impl Cli { } impl Cli { - pub fn new_with_override(client: sdk::Client, over: T) -> Self { + pub fn new_with_override(client: Client, over: T) -> Self { Self { client, over } } diff --git a/progenitor-impl/tests/output/nexus-cli.out b/progenitor-impl/tests/output/nexus-cli.out index 6eacbc90..ee41b2be 100644 --- a/progenitor-impl/tests/output/nexus-cli.out +++ b/progenitor-impl/tests/output/nexus-cli.out @@ -1,10 +1,11 @@ +use sdk::*; pub struct Cli { - client: sdk::Client, + client: Client, over: T, } impl Cli { - pub fn new(client: sdk::Client) -> Self { + pub fn new(client: Client) -> Self { Self { client, over: () } } @@ -5608,7 +5609,7 @@ impl Cli { } impl Cli { - pub fn new_with_override(client: sdk::Client, over: T) -> Self { + pub fn new_with_override(client: Client, over: T) -> Self { Self { client, over } } diff --git a/progenitor-impl/tests/output/param-collision-cli.out b/progenitor-impl/tests/output/param-collision-cli.out index aa70f086..8a1f61ca 100644 --- a/progenitor-impl/tests/output/param-collision-cli.out +++ b/progenitor-impl/tests/output/param-collision-cli.out @@ -1,10 +1,11 @@ +use sdk::*; pub struct Cli { - client: sdk::Client, + client: Client, over: T, } impl Cli { - pub fn new(client: sdk::Client) -> Self { + pub fn new(client: Client) -> Self { Self { client, over: () } } @@ -63,7 +64,7 @@ impl Cli { } impl Cli { - pub fn new_with_override(client: sdk::Client, over: T) -> Self { + pub fn new_with_override(client: Client, over: T) -> Self { Self { client, over } } diff --git a/progenitor-impl/tests/output/param-overrides-cli.out b/progenitor-impl/tests/output/param-overrides-cli.out index 813e3a3e..cac9f283 100644 --- a/progenitor-impl/tests/output/param-overrides-cli.out +++ b/progenitor-impl/tests/output/param-overrides-cli.out @@ -1,10 +1,11 @@ +use sdk::*; pub struct Cli { - client: sdk::Client, + client: Client, over: T, } impl Cli { - pub fn new(client: sdk::Client) -> Self { + pub fn new(client: Client) -> Self { Self { client, over: () } } @@ -35,7 +36,7 @@ impl Cli { } impl Cli { - pub fn new_with_override(client: sdk::Client, over: T) -> Self { + pub fn new_with_override(client: Client, over: T) -> Self { Self { client, over } } diff --git a/progenitor-impl/tests/output/propolis-server-cli.out b/progenitor-impl/tests/output/propolis-server-cli.out index 7d44ec6e..e92bc5eb 100644 --- a/progenitor-impl/tests/output/propolis-server-cli.out +++ b/progenitor-impl/tests/output/propolis-server-cli.out @@ -1,10 +1,11 @@ +use sdk::*; pub struct Cli { - client: sdk::Client, + client: Client, over: T, } impl Cli { - pub fn new(client: sdk::Client) -> Self { + pub fn new(client: Client) -> Self { Self { client, over: () } } @@ -139,7 +140,7 @@ impl Cli { } impl Cli { - pub fn new_with_override(client: sdk::Client, over: T) -> Self { + pub fn new_with_override(client: Client, over: T) -> Self { Self { client, over } }