Azure / Azure/typespec-rust

Compilation error: emitter omitted generating a model

Open
#922 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
7
Forks
11
Avg merge
2d 5h
Merged PRs (30d)
5

Description

This affects `specification/management/resource-manager/Microsoft.Management/ManagementGroups`:

```tsp
/**
* The generic properties of a management group used during creation.
*/
model CreateManagementGroupProperties {
/**
* The AAD Tenant ID associated with the management group. For example, 00000000-0000-0000-0000-000000000000
*/
@visibility(Lifecycle.Read)
tenantId?: string;

/**
* The friendly name of the management group. If no value is passed then this field will be set to the groupId.
*/
#suppress "@azure-tools/typespec-azure-core/no-nullable" "For backward compatibility"
displayName?: string | null;

/**
* The details of a management group used during creation.
*/
details?: CreateManagementGroupDetails;

/**
* The list of children.
*/
#suppress "@azure-tools/typespec-azure-core/no-nullable" "For backward compatibility"
@visibility(Lifecycle.Read)
children?: CreateManagementGroupChildInfo[] | null;
}

...
/**
* The child information of a management group used during creation.
*/
model CreateManagementGroupChildInfo {
/**
* The fully qualified resource type which includes provider namespace (e.g. Microsoft.Management/managementGroups)
*/
@visibility(Lifecycle.Read)
type?: ManagementGroupChildType;

/**
* The fully qualified ID for the child resource (management group or subscription). For example, /providers/Microsoft.Management/managementGroups/0000000-0000-0000-0000-000000000000
*/
@visibility(Lifecycle.Read)
id?: string;

/**
* The name of the child entity.
*/
@visibility(Lifecycle.Read)
name?: string;

/**
* The friendly name of the child resource.
*/
@visibility(Lifecycle.Read)
displayName?: string;

/**
* The list of children.
*/
@visibility(Lifecycle.Read)
children?: CreateManagementGroupChildInfo[];
}
```

it generates the following (correctly)

```rs
/// The generic properties of a management group used during creation.
#[derive(Clone, Default, Deserialize, SafeDebug, Serialize)]
pub struct CreateManagementGroupProperties {
/// The list of children.
///
/// Operational visibility: Read
#[serde(skip_serializing_if = "Option::is_none")]
pub children: Option>, // <-- CreateManagementGroupChildInfo is nowhere to be found

/// The details of a management group used during creation.
#[serde(skip_serializing_if = "Option::is_none")]
pub details: Option,

/// The friendly name of the management group. If no value is passed then this field will be set to the groupId.
#[serde(rename = "displayName", skip_serializing_if = "Option::is_none")]
pub display_name: Option,

/// The AAD Tenant ID associated with the management group. For example, 00000000-0000-0000-0000-000000000000
///
/// Operational visibility: Read
#[serde(rename = "tenantId", skip_serializing_if = "Option::is_none")]
pub tenant_id: Option,
}
```

But the problem is that `CreateManagementGroupChildInfo` is not in the `models.rs` file:
```
error[E0412]: cannot find type `CreateManagementGroupChildInfo` in this scope
--> spec\rmMgmtGroups\src\generated\models\models.rs:96:30
|
96 | pub children: Option>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
567 | pub struct ManagementGroupChildInfo {
| ----------------------------------- similarly named struct `ManagementGroupChildInfo` defined here
|
help: a struct with a similar name exists
|
96 - pub children: Option>,
96 + pub children: Option>,
|
help: you might be missing a type parameter
|
91 | pub struct CreateManagementGroupProperties {
| ++++++++++++++++++++++++++++++++
```

Note: `ManagementGroupChildInfo` is a different type, described the same way:
```tsp
/**
* The child information of a management group.
*/
model ManagementGroupChildInfo {
/**
* The fully qualified resource type which includes provider namespace (e.g. Microsoft.Management/managementGroups)
*/
type?: ManagementGroupChildType;

/**
* The fully qualified ID for the child resource (management group or subscription). For example, /providers/Microsoft.Management/managementGroups/0000000-0000-0000-0000-000000000000
*/
id?: string;

/**
* The name of the child entity.
*/
name?: string;

/**
* The friendly name of the child resource.
*/
displayName?: string;

/**
* The list of children.
*/
children?: ManagementGroupChildInfo[];
}
```
And that one does get generated:
```rs
/// The child information of a management group.
#[derive(Clone, Default, Deserialize, SafeDebug, Serialize)]
#[non_exhaustive]
pub struct ManagementGroupChildInfo {
/// The list of children.
#[serde(skip_serializing_if = "Option::is_none")]
pub children: Option>,

/// The friendly name of the child resource.
#[serde(rename = "displayName", skip_serializing_if = "Option::is_none")]
pub display_name: Option,

/// The fully qualified ID for the child resource (management group or subscription). For example, /providers/Microsoft.Management/managementGroups/0000000-0000-0000-0000-000000000000
#[serde(skip_serializing_if = "Option::is_none")]
pub id: Option,

/// The name of the child entity.
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option,

/// The fully qualified resource type which includes provider namespace (e.g. Microsoft.Management/managementGroups)
#[serde(rename = "type", skip_serializing_if = "Option::is_none")]
pub type_prop: Option,
}
```

I was thinking that's because `CreateManagementGroupChildInfo` has an array of `CreateManagementGroupChildInfo[]` inside itself, but no - you can see that `ManagementGroupChildInfo` got the same, and that one does get generated.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.