diff --git a/epp-client/src/epp/request/domain/create.rs b/epp-client/src/epp/request/domain/create.rs index 7a4bee1..696f9fa 100644 --- a/epp-client/src/epp/request/domain/create.rs +++ b/epp-client/src/epp/request/domain/create.rs @@ -74,14 +74,20 @@ use serde::{Deserialize, Serialize}; /// println!("{:?}", response); /// } /// ``` -pub type EppDomainCreate = EppObject>>; -/// Type that represents the <epp> request for domain <create> command -/// with <hostAttr> elements in the request for <ns> list -pub type EppDomainCreateWithHostAttr = EppObject>>; +pub type EppDomainCreate = EppObject>; + +/// Enum that can accept one type which corresponds to either the <hostObj> or <hostAttr> +/// list of tags +#[derive(Serialize, Deserialize, Debug)] +#[serde(untagged)] +pub enum HostList { + HostObjList(HostObjList), + HostAttrList(HostAttrList), +} /// Type for elements under the domain <create> tag #[derive(Serialize, Deserialize, Debug)] -pub struct DomainCreateData { +pub struct DomainCreateData { /// XML namespace for domain commands xmlns: String, /// The domain name @@ -90,7 +96,7 @@ pub struct DomainCreateData { period: Period, /// The list of nameserver hosts /// either of type `HostObjList` or `HostAttrList` - ns: Option, + ns: Option, /// The domain registrant registrant: Option, /// The list of contacts for the domain @@ -104,12 +110,12 @@ pub struct DomainCreateData { #[derive(Serialize, Deserialize, Debug, ElementName)] #[element_name(name = "create")] /// Type for EPP XML <create> command for domains -pub struct DomainCreate { +pub struct DomainCreate { /// The data for the domain to be created with /// T being the type of nameserver list (`HostObjList` or `HostAttrList`) /// to be supplied #[serde(rename = "create")] - domain: DomainCreateData, + domain: DomainCreateData, } impl EppDomainCreate { @@ -134,17 +140,14 @@ impl EppDomainCreate { xmlns: EPP_DOMAIN_XMLNS.to_string(), name: name.to_string_value(), period: Period::new(period), - ns: Some(HostObjList { hosts: ns_list }), + ns: Some(HostList::HostObjList(HostObjList { hosts: ns_list })), registrant: Some(registrant_id.to_string_value()), auth_info: AuthInfo::new(auth_password), contacts: Some(contacts), }, }; - EppObject::build(Command::>::new( - domain_create, - client_tr_id, - )) + EppObject::build(Command::::new(domain_create, client_tr_id)) } /// Creates a new EppObject for domain create corresponding to the <epp> tag in EPP XML @@ -168,10 +171,7 @@ impl EppDomainCreate { contacts: Some(contacts), }, }; - EppObject::build(Command::>::new( - domain_create, - client_tr_id, - )) + EppObject::build(Command::::new(domain_create, client_tr_id)) } /// Creates a new EppObject for domain create corresponding to the <epp> tag in EPP XML @@ -194,10 +194,7 @@ impl EppDomainCreate { }, }; - EppObject::build(Command::>::new( - domain_create, - client_tr_id, - )) + EppObject::build(Command::::new(domain_create, client_tr_id)) } /// Creates a new EppObject for domain create corresponding to the <epp> tag in EPP XML @@ -210,21 +207,18 @@ impl EppDomainCreate { auth_password: &str, contacts: Vec, client_tr_id: &str, - ) -> EppDomainCreateWithHostAttr { + ) -> EppDomainCreate { let domain_create = DomainCreate { domain: DomainCreateData { xmlns: EPP_DOMAIN_XMLNS.to_string(), name: name.to_string_value(), period: Period::new(period), - ns: Some(HostAttrList { hosts: ns }), + ns: Some(HostList::HostAttrList(HostAttrList { hosts: ns })), registrant: Some(registrant_id.to_string_value()), auth_info: AuthInfo::new(auth_password), contacts: Some(contacts), }, }; - EppObject::build(Command::>::new( - domain_create, - client_tr_id, - )) + EppObject::build(Command::::new(domain_create, client_tr_id)) } }