Skip to content

kopium do not generate struct with nesting additionalProperties #202

@chenyuanrun

Description

@chenyuanrun

This problem could be reproduced with crd cephclusters.ceph.rook.io: https://github.com/rook/rook/blob/v1.13.5/deploy/examples/crds.yaml#L894-L912

kopium generate something like:

#[derive(CustomResource, Serialize, Deserialize, Clone, Debug, JsonSchema)]
#[kube(group = "ceph.rook.io", version = "v1", kind = "CephCluster", plural = "cephclusters")]
#[kube(namespaced)]
#[kube(status = "CephClusterStatus")]
pub struct CephClusterSpec {
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub annotations: Option<BTreeMap<String, CephClusterAnnotations>>,
    #[serde(default, skip_serializing_if = "Option::is_none", rename = "cephConfig")]
    pub ceph_config: Option<BTreeMap<String, CephClusterCephConfig>>,
    #[serde(default, skip_serializing_if = "Option::is_none", rename = "cephVersion")]
    pub ceph_version: Option<CephClusterCephVersion>,
    #[serde(default, skip_serializing_if = "Option::is_none", rename = "cleanupPolicy")]
    pub cleanup_policy: Option<CephClusterCleanupPolicy>,
    #[serde(default, skip_serializing_if = "Option::is_none", rename = "continueUpgradeAfterChecksEvenIfNotHealthy")]
    pub continue_upgrade_after_checks_even_if_not_healthy: Option<bool>,
    #[serde(default, skip_serializing_if = "Option::is_none", rename = "crashCollector")]
    pub crash_collector: Option<CephClusterCrashCollector>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub csi: Option<CephClusterCsi>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub dashboard: Option<CephClusterDashboard>,
    #[serde(default, skip_serializing_if = "Option::is_none", rename = "dataDirHostPath")]
    pub data_dir_host_path: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none", rename = "disruptionManagement")]
    pub disruption_management: Option<CephClusterDisruptionManagement>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub external: Option<CephClusterExternal>,
    #[serde(default, skip_serializing_if = "Option::is_none", rename = "healthCheck")]
    pub health_check: Option<CephClusterHealthCheck>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub labels: Option<BTreeMap<String, CephClusterLabels>>,
    #[serde(default, skip_serializing_if = "Option::is_none", rename = "logCollector")]
    pub log_collector: Option<CephClusterLogCollector>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub mgr: Option<CephClusterMgr>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub mon: Option<CephClusterMon>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub monitoring: Option<CephClusterMonitoring>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub network: Option<CephClusterNetwork>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub placement: Option<BTreeMap<String, CephClusterPlacement>>,
    #[serde(default, skip_serializing_if = "Option::is_none", rename = "priorityClassNames")]
    pub priority_class_names: Option<BTreeMap<String, String>>,
    #[serde(default, skip_serializing_if = "Option::is_none", rename = "removeOSDsIfOutAndSafeToRemove")]
    pub remove_os_ds_if_out_and_safe_to_remove: Option<bool>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub resources: Option<BTreeMap<String, CephClusterResources>>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub security: Option<CephClusterSecurity>,
    #[serde(default, skip_serializing_if = "Option::is_none", rename = "skipUpgradeChecks")]
    pub skip_upgrade_checks: Option<bool>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub storage: Option<CephClusterStorage>,
    #[serde(default, skip_serializing_if = "Option::is_none", rename = "waitTimeoutForHealthyOSDInMinutes")]
    pub wait_timeout_for_healthy_osd_in_minutes: Option<i64>,
}

and failed to compile:

error[E0412]: cannot find type `CephClusterAnnotations` in this scope
   --> src/crds/cephclusters_ceph_rook_io.rs:17:46
    |
17  |     pub annotations: Option<BTreeMap<String, CephClusterAnnotations>>,
    |                                              ^^^^^^^^^^^^^^^^^^^^^^
...
846 | pub struct CephClusterMonitoring {
    | -------------------------------- similarly named struct `CephClusterMonitoring` defined here
    |
help: a struct with a similar name exists
    |
17  |     pub annotations: Option<BTreeMap<String, CephClusterMonitoring>>,
    |                                              ~~~~~~~~~~~~~~~~~~~~~
help: you might be missing a type parameter
    |
15  | pub struct CephClusterSpec<CephClusterAnnotations> {
    |                           ++++++++++++++++++++++++

error[E0412]: cannot find type `CephClusterCephConfig` in this scope
  --> src/crds/cephclusters_ceph_rook_io.rs:19:46
   |
19 |     pub ceph_config: Option<BTreeMap<String, CephClusterCephConfig>>,
   |                                              ^^^^^^^^^^^^^^^^^^^^^
...
71 | pub struct CephClusterCephVersion {
   | --------------------------------- similarly named struct `CephClusterCephVersion` defined here
   |
help: a struct with a similar name exists
   |
19 |     pub ceph_config: Option<BTreeMap<String, CephClusterCephVersion>>,
   |                                              ~~~~~~~~~~~~~~~~~~~~~~
help: you might be missing a type parameter
   |
15 | pub struct CephClusterSpec<CephClusterCephConfig> {
   |                           +++++++++++++++++++++++

error[E0412]: cannot find type `CephClusterLabels` in this scope
  --> src/crds/cephclusters_ceph_rook_io.rs:41:41
   |
41 |     pub labels: Option<BTreeMap<String, CephClusterLabels>>,
   |                                         ^^^^^^^^^^^^^^^^^ not found in this scope
   |
help: you might be missing a type parameter
   |
15 | pub struct CephClusterSpec<CephClusterLabels> {
   |                           +++++++++++++++++++

error[E0412]: cannot find type `CephClusterAnnotations` in this scope
   --> src/crds/cephclusters_ceph_rook_io.rs:17:46
    |
17  |     pub annotations: Option<BTreeMap<String, CephClusterAnnotations>>,
    |                                              ^^^^^^^^^^^^^^^^^^^^^^ help: a struct with a similar name exists: `CephClusterMonitoring`
...
846 | pub struct CephClusterMonitoring {
    | -------------------------------- similarly named struct `CephClusterMonitoring` defined here

error[E0412]: cannot find type `CephClusterCephConfig` in this scope
  --> src/crds/cephclusters_ceph_rook_io.rs:19:46
   |
19 |     pub ceph_config: Option<BTreeMap<String, CephClusterCephConfig>>,
   |                                              ^^^^^^^^^^^^^^^^^^^^^ help: a struct with a similar name exists: `CephClusterCephVersion`
...
71 | pub struct CephClusterCephVersion {
   | --------------------------------- similarly named struct `CephClusterCephVersion` defined here

error[E0412]: cannot find type `CephClusterLabels` in this scope
  --> src/crds/cephclusters_ceph_rook_io.rs:41:41
   |
41 |     pub labels: Option<BTreeMap<String, CephClusterLabels>>,
   |                                         ^^^^^^^^^^^^^^^^^ not found in this scope

For more information about this error, try `rustc --explain E0412`.
error: could not compile `operator` (bin "operator") due to 6 previous errors

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions