-
Notifications
You must be signed in to change notification settings - Fork 15
Description
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
bicep-types/src/Bicep.Types/Serialization/TypeSerializer.cs
Lines 18 to 27 in fc9ae27
| return new JsonSerializerOptions | |
| { | |
| Converters = { | |
| new TypeReferenceConverter(factory), | |
| new CrossFileTypeReferenceConverter(), | |
| }, | |
| PropertyNamingPolicy = JsonNamingPolicy.CamelCase, | |
| WriteIndented = true, | |
| TypeInfoResolver = TypeJsonContext.Default, | |
| }; |
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