Skip to content

Conversation

@JamieMagee
Copy link
Member

This pull request adds the JSON schema for cgmanifest.json.

FAQ

Why?

A JSON schema helps you to ensure that your cgmanifest.json file is valid.
JSON schema validation is a build-in feature in most modern IDEs like Visual Studio and Visual Studio Code.
Most modern IDEs also provide code-completion for JSON schemas.

How can I validate my cgmanifest.json file?

Most modern IDEs like Visual Studio and Visual Studio Code have a built-in feature to validate JSON files.
You can also use this small script to validate your cgmanifest.json file.

Why does it suggest camel case for the properties?

Component Detection is able to read camel case and pascal case properties.
However, the JSON schema doesn't have a case-insensitive mode.
We therefore suggest camel case as it's the most common format for JSON.

Why is the diff so large?

To deserialize the cgmanifest.json file, we use JSON.parse().
However, to serialize the JSON again we use prettier.
We found that, in general, it gave smaller diffs than the default JSON.stringify() function.

@moljac
Copy link
Contributor

moljac commented Sep 1, 2022

Please, request review when PR is ready. Thanks.

jonpryor added a commit to jonpryor/xamarin-android that referenced this pull request Sep 6, 2022
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
jonpryor added a commit to jonpryor/xamarin-android that referenced this pull request Sep 6, 2022
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
jonpryor pushed a commit to dotnet/java-interop that referenced this pull request Sep 6, 2022
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 `tools/java-source-utils/CGManifest.json` so that it 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, `CGManifest.json` reports no errors when using
<https://www.jsonschemavalidator.net>.

Co-authored-by: Jamie Magee <[email protected]>

[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
jonpryor added a commit to dotnet/android that referenced this pull request Sep 6, 2022
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
@jonpryor
Copy link
Contributor

jonpryor commented Sep 7, 2022

As with the similar dotnet/java-interop#1035, the contents of this PR don't match the description: the description says:

We therefore suggest camel case as it's the most common format for JSON.

which strongly implies that properties should be camelCase, yet the contents of the PR retain PascalCase naming. Consequently, certain validation tools such as https://www.jsonschemavalidator.net/ will flag ~everything as bad, plus the schema requires a version property which likewise isn't present in this PR.

@JamieMagee
Copy link
Member Author

@jonpryor Yeah, I see how the instructions can be a bit ambiguous. What I intended to convey was that you may use camel case or pascal case for the cgmanifest.json object properties. However, JSON schema forces us to choose one, and we chose to suggest camel case.

We currently don't strictly validate cgmanifest.json using the schema. We're using it to allow users to self-validate their own cgmanifest.json files. We may send out followup PRs in the future to convert pascal case properties to camel case, but there are no plans right now.

Thanks for your help in reviewing the PRs and thank you for editing your automation that generates your cgmanifest.json

@moljac
Copy link
Contributor

moljac commented Sep 21, 2022

Automatically generated cgmanifest.json is fixed

  • schema was added
  • property names use camelCase

https://github.com/xamarin/AndroidX/blob/main/cgmanifest.json

closing this one without merging.

Thanks

@moljac moljac closed this Sep 21, 2022
@JamieMagee JamieMagee deleted the cgmanifest-schema branch October 11, 2022 19:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants