-
Notifications
You must be signed in to change notification settings - Fork 262
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix union types #1435
fix union types #1435
Conversation
- create the base type without the discriminator - adds the description to the union type
services/mgmt/alertsmanagement/src/package_preview_2021_08/models.rs
Outdated
Show resolved
Hide resolved
I'm digging into this and found at least one issue that I don't think is right. In From looking at the spec, these should be used in |
Thanks for digging in. The generated code for that example looks fine to me. Here is the Union generated from #[doc = "CredentialTypeEnum."]
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(tag = "kind")]
pub enum AuthCredentialsUnion {
ApiKeyAuthCredentials(ApiKeyAuthCredentials),
OAuthClientCredentials(OAuthClientCredentials),
}
#[doc = "Api Key Auth Credentials class for API Key based Auth."]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct ApiKeyAuthCredentials {
#[doc = "Properties of the key vault."]
#[serde(rename = "apiKey", default, skip_serializing_if = "Option::is_none")]
pub api_key: Option<KeyVaultProperties>,
}
#[doc = "OAuthClientCredentials for clientId clientSecret auth."]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct OAuthClientCredentials {
#[doc = "ClientId associated with the provider."]
#[serde(rename = "clientId", default, skip_serializing_if = "Option::is_none")]
pub client_id: Option<String>,
#[doc = "Properties of the key vault."]
#[serde(rename = "clientSecret", default, skip_serializing_if = "Option::is_none")]
pub client_secret: Option<KeyVaultProperties>,
} It is strange that that definition is not referenced anywhere else in the spec. Most specs then define the string enumeration inline, but the spec as defined it externally "AuthCredentials": {
"description": "AuthCredentials abstract base class for Auth Purpose.",
"required": [
"kind"
],
"type": "object",
"properties": {
"kind": {
"$ref": "#/definitions/AuthCredentialsKind"
}
},
"discriminator": "kind"
},
"AuthCredentialsKind": {
"description": "CredentialTypeEnum.",
"enum": [
"OAuthClientCredentials",
"ApiKeyAuthCredentials"
],
"type": "string",
"x-ms-enum": {
"name": "AuthCredentialsKind",
"modelAsString": true
}
}, Which is why there is a enum generated: #[doc = "CredentialTypeEnum."]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(remote = "AuthCredentialsKind")]
pub enum AuthCredentialsKind {
OAuthClientCredentials,
ApiKeyAuthCredentials,
#[serde(skip_deserializing)]
UnknownValue(String),
} It is not used anywhere else in the spec, but it is not wrong to also generate it. Usually, you are going to reference it elsewhere. |
This fixes a bug from #1414 which causes deserialization to fail.