Skip to content

Fix serializer in TypeSerializer to better handle modern scope properties #736

@harshpatel17

Description

@harshpatel17

Here is a temporary bandaid (Bicep repo) to handle 3 failing tests that I couldn't get to pass. Here is what I found so far:

In the ExtensionResourceTypeHelper.cs, we are serializing Resource types but upon serialization the type definitions that are generated have both legacy and modern properties. Even though readableScopes and writableScopes are set to ScopeType.All, this is serialized to JSON that includes both modern properties (readableScopes: 31, writableScopes: 31) AND legacy properties (scopeType: null, readOnlyScopes: null).

The problem is when this gets deserialized, the deserializer prioritizes the legacy null values and converts them to ScopeType.None, completely ignoring the correct modern values. This causes extension resources like request@v1 to be incorrectly flagged as ReadOnly, triggering BCP245 errors: "Resource type 'request@v1' can only be used with the 'existing' keyword" in LocalDeployCommand tests.

Potential solution:
I think we may need to add DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull to

return new JsonSerializerOptions
{
Converters = {
new TypeReferenceConverter(factory),
new CrossFileTypeReferenceConverter(),
},
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
WriteIndented = true,
TypeInfoResolver = TypeJsonContext.Default,
};
(Bicep-types repo)

AFAICT no other consumer of Bicep.Types is using the C# code to serialize types (only to deserialize them).

Things to do once serialization is fixed:

  • Rip off bandaid
  • Ensure all tests specifically the LocalDeployCommand tests pass

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions