Skip to content

Commit 034f911

Browse files
committed
[xaprepare] CGManifest.json conforms to JSON schema
Context: https://www.jsonschemavalidator.net/ Context: https://github.com/JamieMagee/verify-cgmanifest Context: https://json.schemastore.org/component-detection-manifest.json Context: dotnet/android-libraries#608 There is a [JSON Schema][0] for `CGManifest.json`. Update `xaprepare` so that `CGManifest.json` conforms to the JSON schema. This involves three sets of changes: * Add a `$schema` property. * Add a `version` property; I can't find any actual documentation for this schema, but the [sample manifest][1] uses `"version": 1`, so use the same version. * "camelCase" all the JSON property names. From the [JamieMagee/verify-cgmanifest README.md][2] > Component Detection will accept object properties in PascalCase, > but JSON schema does not have a case-insensitive mode. > Camel case is the most common way to write object properties in > JSON. With these changes, our generated `bin/Build$(Configuration)/CGManifest.json` reports no errors when using <https://www.jsonschemavalidator.net>. [0]: https://json.schemastore.org/component-detection-manifest.json [1]: https://github.com/JamieMagee/verify-cgmanifest/blob/2adfb450cd1f2170c3df120036f4a531285167ef/cgmanifest.sample.json [2]: https://github.com/JamieMagee/verify-cgmanifest/blob/2adfb450cd1f2170c3df120036f4a531285167ef/README.md
1 parent 863cfc5 commit 034f911

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

build-tools/xaprepare/xaprepare/Steps/Step_GenerateCGManifest.cs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ protected override async Task<bool> Execute (Context context)
6767
using var json = File.CreateText (jsonPath);
6868

6969
json.WriteLine ("{");
70-
json.WriteLine (" \"Registrations\": [");
70+
json.WriteLine (" \"$schema\": \"https://json.schemastore.org/component-detection-manifest.json\",");
71+
json.WriteLine (" \"version\": 1,");
72+
json.WriteLine (" \"registrations\": [");
7173

7274
var properties = new Dictionary<string, string> ();
7375

@@ -100,8 +102,8 @@ void WriteComponent (TextWriter json, CGManifestEntry entry, Dictionary<string,
100102
entry.FillComponentProperties (properties);
101103

102104
json.WriteLine ($" {{");
103-
json.WriteLine ($" \"Component\": {{");
104-
json.WriteLine ($" \"Type\": \"{entry.Type.ToLowerInvariant ()}\",");
105+
json.WriteLine ($" \"component\": {{");
106+
json.WriteLine ($" \"type\": \"{entry.Type.ToLowerInvariant ()}\",");
105107
json.WriteLine ($" \"{entry.Type}\": {{");
106108
bool firstProp = true;
107109
foreach (var key in properties.Keys.OrderBy (p => p, StringComparer.OrdinalIgnoreCase)) {
@@ -116,7 +118,7 @@ void WriteComponent (TextWriter json, CGManifestEntry entry, Dictionary<string,
116118
json.WriteLine ();
117119
json.WriteLine ($" }}");
118120
json.WriteLine ($" }},");
119-
json.WriteLine ($" \"DevelopmentDependency\":{dev}");
121+
json.WriteLine ($" \"developmentDependency\":{dev}");
120122
json.Write ($" }}");
121123
}
122124
}
@@ -145,7 +147,7 @@ public override string Name {
145147
}
146148
}
147149

148-
public override string Type => "Git";
150+
public override string Type => "git";
149151

150152
public string RepositoryUrl {get; private set;} = String.Empty;
151153
public string CommitHash {get; private set;} = String.Empty;
@@ -157,8 +159,8 @@ public override string Name {
157159

158160
public override void FillComponentProperties (Dictionary<string, string> properties)
159161
{
160-
properties ["RepositoryUrl"] = RepositoryUrl;
161-
properties ["CommitHash"] = CommitHash;
162+
properties ["repositoryUrl"] = RepositoryUrl;
163+
properties ["commitHash"] = CommitHash;
162164
}
163165

164166
const string Submodule = "submodule.external/";
@@ -256,7 +258,7 @@ sealed class MSBuildPackageReferenceInfo : CGManifestEntry {
256258
string name;
257259

258260
public override string Name => name;
259-
public override string Type => "Nuget";
261+
public override string Type => "nuget";
260262

261263
public string Version {get; private set;}
262264

@@ -268,8 +270,8 @@ sealed class MSBuildPackageReferenceInfo : CGManifestEntry {
268270

269271
public override void FillComponentProperties (Dictionary<string, string> properties)
270272
{
271-
properties ["Name"] = Name;
272-
properties ["Version"] = Version;
273+
properties ["name"] = Name;
274+
properties ["version"] = Version;
273275
}
274276

275277
static readonly XNamespace MSBuildXmlns = XNamespace.Get ("http://schemas.microsoft.com/developer/msbuild/2003");

0 commit comments

Comments
 (0)