Skip to content

[AVM CI Environment Issue]: UDT/RDT test shows incorrect warning for discrimnated types #7168

Description

@AlexanderSehr

Check for previous/existing GitHub issues

  • I have checked for previous/existing GitHub issues

Issue Type?

Bug

Description

With the current version of Bicep, the JSON template is rendered a bit differently and the check for UDTs/RDTs does not account for said way.

Image

You can see the result here. The parameter does have a type and should now show up as incorrect.

The reason for the warnings that the check in the corresponding test

$hasProperties = $parameter.keys -contains 'properties'
$hasRdtDefintion = $parameter.metadata.Keys -contains '__bicep_resource_derived_type!'
$hasUdtDefinition = $parameter.keys -contains '$ref'

Assumes that the parameter has a key $ref for UDTs (which is the way it used to be). However, at least in the latest version of bicep, the parameter (when debugging the right after the aforementioned lines shows the parameter as

{
  "type": "object",
  "discriminator": {
    "propertyName": "kind",
    "mapping": {
      "Automatic": {
        "$ref": "#/definitions/resourcePredictionsProfileAutomaticType"
      },
      "Manual": {
        "$ref": "#/definitions/resourcePredictionsProfileManualType"
      }
    }
  },
  "nullable": true,
  "metadata": {
    "description": "Optional. Determines how the stand-by scheme should be provided."
  },
  "name": "resourcePredictionsProfile"
}

So now, there's a discriminator key with a mapping in it per each case. Each of those then must have a $ref or have a metadata key with the value __bicep_resource_derived_type!.

To test the last point, I expanded the type resourcePredictionsProfile like this to debug how it would look like for a resourceInput value.

resourcePredictionsProfile: (
  | resourcePredictionsProfileAutomaticType
  | resourcePredictionsProfileManualType
  | resourceInput<'Microsoft.DevOpsInfrastructure/pools@2025-09-20'>.properties.agentProfile)?

Again, using the debugger, the previous JSON now looks like

{
  "type": "object",
  "discriminator": {
    "propertyName": "kind",
    "mapping": {
      "Automatic": {
        "$ref": "#/definitions/resourcePredictionsProfileAutomaticType"
      },
      "Manual": {
        "$ref": "#/definitions/resourcePredictionsProfileManualType"
      },
      "Stateful": {
        "type": "object",
        "metadata": {
          "__bicep_resource_derived_type!": "System.Management.Automation.OrderedHashtable"
        }
      },
      "Stateless": {
        "type": "object",
        "metadata": {
          "__bicep_resource_derived_type!": "System.Management.Automation.OrderedHashtable"
        }
      }
    }
  },
  "nullable": true,
  "metadata": {
    "description": "Optional. Determines how the stand-by scheme should be provided."
  },
  "name": "resourcePredictionsProfile"
}

So the test must be updated accordingly. The above should be enough information to do so.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    Needs: Triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions