Skip to content

Commit a009fc8

Browse files
committed
Add explicit JsonPropertyNameAttribute to models
1 parent 14b1cb7 commit a009fc8

File tree

7 files changed

+47
-2
lines changed

7 files changed

+47
-2
lines changed

src/Microsoft.ComponentDetection.Contracts/BcdeModels/ContainerDetails.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ namespace Microsoft.ComponentDetection.Contracts.BcdeModels;
33

44
using System;
55
using System.Collections.Generic;
6+
using System.Text.Json.Serialization;
67
using Newtonsoft.Json;
78
using Newtonsoft.Json.Serialization;
89

@@ -13,33 +14,41 @@ public class ContainerDetails
1314
{
1415
// Summary:
1516
// ImageId for the docker container.
17+
[JsonPropertyName("imageId")]
1618
public string ImageId { get; set; }
1719

1820
// Summary:
1921
// Unique id for the container.
22+
[JsonPropertyName("id")]
2023
public int Id { get; set; }
2124

2225
// Summary:
2326
// Digests for the container
27+
[JsonPropertyName("digests")]
2428
public IEnumerable<string> Digests { get; set; }
2529

2630
// Summary:
2731
// The Repository:Tag for the base image of the docker container
2832
// ex: alpine:latest || alpine:v3.1 || mcr.microsoft.com/dotnet/sdk:5.0
33+
[JsonPropertyName("baseImageRef")]
2934
public string BaseImageRef { get; set; }
3035

3136
// Summary:
3237
// The digest of the exact image used as the base image
3338
// This is to avoid errors if there are ref updates between build time and scan time
39+
[JsonPropertyName("baseImageDigest")]
3440
public string BaseImageDigest { get; set; }
3541

3642
// Summary:
3743
// The time the container was created
44+
[JsonPropertyName("createdAt")]
3845
public DateTime CreatedAt { get; set; }
3946

4047
// Summary:
4148
// Tags for the container
49+
[JsonPropertyName("tags")]
4250
public IEnumerable<string> Tags { get; set; }
4351

52+
[JsonPropertyName("layers")]
4453
public IEnumerable<DockerLayer> Layers { get; set; }
4554
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
#nullable disable
22
namespace Microsoft.ComponentDetection.Contracts.BcdeModels;
33

4+
using System.Text.Json.Serialization;
45
using Newtonsoft.Json;
56
using Newtonsoft.Json.Serialization;
67

78
[JsonObject(MemberSerialization.OptOut, NamingStrategyType = typeof(CamelCaseNamingStrategy))]
89
public class DefaultGraphScanResult : ScanResult
910
{
11+
[JsonPropertyName("dependencyGraphs")]
1012
public DependencyGraphCollection DependencyGraphs { get; set; }
1113
}

src/Microsoft.ComponentDetection.Contracts/BcdeModels/DependencyGraphWithMetadata.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,22 @@
22
namespace Microsoft.ComponentDetection.Contracts.BcdeModels;
33

44
using System.Collections.Generic;
5+
using System.Text.Json.Serialization;
56
using Newtonsoft.Json;
67
using Newtonsoft.Json.Serialization;
78

89
[JsonObject(MemberSerialization.OptOut, NamingStrategyType = typeof(CamelCaseNamingStrategy))]
910
public class DependencyGraphWithMetadata
1011
{
12+
[JsonPropertyName("graph")]
1113
public DependencyGraph Graph { get; set; }
1214

15+
[JsonPropertyName("explicitlyReferencedComponentIds")]
1316
public HashSet<string> ExplicitlyReferencedComponentIds { get; set; }
1417

18+
[JsonPropertyName("developmentDependencies")]
1519
public HashSet<string> DevelopmentDependencies { get; set; }
1620

21+
[JsonPropertyName("dependencies")]
1722
public HashSet<string> Dependencies { get; set; }
1823
}

src/Microsoft.ComponentDetection.Contracts/BcdeModels/Detector.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
namespace Microsoft.ComponentDetection.Contracts.BcdeModels;
33

44
using System.Collections.Generic;
5+
using System.Text.Json.Serialization;
56
using Microsoft.ComponentDetection.Contracts.TypedComponent;
67
using Newtonsoft.Json;
78
using Newtonsoft.Json.Converters;
@@ -10,12 +11,16 @@ namespace Microsoft.ComponentDetection.Contracts.BcdeModels;
1011
[JsonObject(MemberSerialization.OptOut, NamingStrategyType = typeof(CamelCaseNamingStrategy))]
1112
public class Detector
1213
{
14+
[JsonPropertyName("detectorId")]
1315
public string DetectorId { get; set; }
1416

17+
[JsonPropertyName("isExperimental")]
1518
public bool IsExperimental { get; set; }
1619

20+
[JsonPropertyName("version")]
1721
public int Version { get; set; }
1822

1923
[JsonProperty(ItemConverterType = typeof(StringEnumConverter))]
24+
[JsonPropertyName("supportedComponentTypes")]
2025
public IEnumerable<ComponentType> SupportedComponentTypes { get; set; }
2126
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
11
#nullable disable
22
namespace Microsoft.ComponentDetection.Contracts.BcdeModels;
33

4+
using System.Text.Json.Serialization;
5+
46
public class DockerLayer
57
{
68
// Summary:
79
// the command/script that was executed in order to create the layer.
10+
[JsonPropertyName("createdBy")]
811
public string CreatedBy { get; set; }
912

1013
// Summary:
1114
// The Layer hash (docker inspect) that represents the changes between this layer and the previous layer
15+
[JsonPropertyName("diffId")]
1216
public string DiffId { get; set; }
1317

1418
// Summary:
1519
// Whether or not this layer was found in the base image of the container
20+
[JsonPropertyName("isBaseImage")]
1621
public bool IsBaseImage { get; set; }
1722

1823
// Summary:
1924
// 0-indexed monotonically increasing ID for the order of the layer in the container.
2025
// Note: only includes non-empty layers
26+
[JsonPropertyName("layerIndex")]
2127
public int LayerIndex { get; set; }
2228
}

src/Microsoft.ComponentDetection.Contracts/BcdeModels/ScanResult.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,30 @@
22
namespace Microsoft.ComponentDetection.Contracts.BcdeModels;
33

44
using System.Collections.Generic;
5+
using System.Text.Json.Serialization;
56
using Newtonsoft.Json;
67
using Newtonsoft.Json.Converters;
78
using Newtonsoft.Json.Serialization;
89

910
[JsonObject(MemberSerialization.OptOut, NamingStrategyType = typeof(CamelCaseNamingStrategy))]
1011
public class ScanResult
1112
{
13+
[JsonPropertyName("componentsFound")]
1214
public IEnumerable<ScannedComponent> ComponentsFound { get; set; }
1315

16+
[JsonPropertyName("detectorsInScan")]
1417
public IEnumerable<Detector> DetectorsInScan { get; set; }
1518

19+
[JsonPropertyName("detectorsNotInScan")]
1620
public IEnumerable<Detector> DetectorsNotInScan { get; set; }
1721

22+
[JsonPropertyName("containerDetailsMap")]
1823
public Dictionary<int, ContainerDetails> ContainerDetailsMap { get; set; }
1924

20-
[JsonConverter(typeof(StringEnumConverter))]
25+
[Newtonsoft.Json.JsonConverter(typeof(StringEnumConverter))]
26+
[JsonPropertyName("resultCode")]
2127
public ProcessingResultCode ResultCode { get; set; }
2228

29+
[JsonPropertyName("sourceDirectory")]
2330
public string SourceDirectory { get; set; }
2431
}

src/Microsoft.ComponentDetection.Contracts/BcdeModels/ScannedComponent.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,42 @@
22
namespace Microsoft.ComponentDetection.Contracts.BcdeModels;
33

44
using System.Collections.Generic;
5+
using System.Text.Json.Serialization;
56
using Newtonsoft.Json;
67
using Newtonsoft.Json.Converters;
78
using Newtonsoft.Json.Serialization;
89

910
[JsonObject(MemberSerialization.OptOut, NamingStrategyType = typeof(CamelCaseNamingStrategy))]
1011
public class ScannedComponent
1112
{
13+
[JsonPropertyName("locationsFoundAt")]
1214
public IEnumerable<string> LocationsFoundAt { get; set; }
1315

16+
[JsonPropertyName("component")]
1417
public TypedComponent.TypedComponent Component { get; set; }
1518

19+
[JsonPropertyName("detectorId")]
1620
public string DetectorId { get; set; }
1721

22+
[JsonPropertyName("isDevelopmentDependency")]
1823
public bool? IsDevelopmentDependency { get; set; }
1924

20-
[JsonConverter(typeof(StringEnumConverter))]
25+
[Newtonsoft.Json.JsonConverter(typeof(StringEnumConverter))]
26+
[JsonPropertyName("dependencyScope")]
2127
public DependencyScope? DependencyScope { get; set; }
2228

29+
[JsonPropertyName("topLevelReferrers")]
2330
public IEnumerable<TypedComponent.TypedComponent> TopLevelReferrers { get; set; }
2431

32+
[JsonPropertyName("ancestralReferrers")]
2533
public IEnumerable<TypedComponent.TypedComponent> AncestralReferrers { get; set; }
2634

35+
[JsonPropertyName("containerDetailIds")]
2736
public IEnumerable<int> ContainerDetailIds { get; set; }
2837

38+
[JsonPropertyName("containerLayerIds")]
2939
public IDictionary<int, IEnumerable<int>> ContainerLayerIds { get; set; }
3040

41+
[JsonPropertyName("targetFrameworks")]
3142
public ISet<string> TargetFrameworks { get; set; }
3243
}

0 commit comments

Comments
 (0)