Skip to content

feat: validate grafanaDep with semver#515

Open
s4kh wants to merge 4 commits intomainfrom
feat-validate-semver
Open

feat: validate grafanaDep with semver#515
s4kh wants to merge 4 commits intomainfrom
feat-validate-semver

Conversation

@s4kh
Copy link
Contributor

@s4kh s4kh commented Feb 16, 2026

Validate plugin.json -> dependencies.grafanaDependency using SemVer constraint.
Ignores schema validation for dependencies.grafanaDependency.

break
}

pluginJsonBytes, _ := os.ReadFile(metadataPath)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this stage, we know plugin.json file exists so no need to check for that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the file fails to open or to be read? I'd still keep the error check just in case

for _, desc := range result.Errors() {
// we validate grafanaDependency at line 91-100,
// so we ignore the error from schema validation
if strings.Contains(desc.Field(), "grafanaDependency") {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried removing from the schema, but we have to read the schema and iterate through and find the grafanaDependency object and remove. Ignoring the returned error seemed simple so went with it.

@s4kh s4kh self-assigned this Feb 16, 2026
@s4kh s4kh requested a review from academo February 16, 2026 15:32
if err := json.Unmarshal(pluginJsonBytes, &data); err == nil {
fmt.Println(data.Dependencies.GrafanaDependency)
_, err = version.NewConstraint(data.Dependencies.GrafanaDependency)
fmt.Println(err)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this

if pluginJsonBytes != nil {
var data metadata.Metadata
if err := json.Unmarshal(pluginJsonBytes, &data); err == nil {
fmt.Println(data.Dependencies.GrafanaDependency)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove print

_, err := Analyzer.Run(pass)
require.NoError(t, err)
require.Len(t, interceptor.Diagnostics, 2)
require.Equal(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: validate that the schema is not reporting grafanaDependency as it used to be.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now the new error message is checked in the main_test.go

)
require.Equal(
t,
"plugin.json: (root): Additional property invalid is not allowed",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we really need this validation here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is to check combination of schema and grafanaDependency.

"name": "Clock",
"id": "grafana-clock-panel",
"skipDataQuery": true,
"invalid": "invalid",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can remove this, we want to test the grafanaDependency, there are tests already for invalid schema fields.

@grafana-plugins-platform-bot grafana-plugins-platform-bot bot moved this from 📬 Triage to 🔬 In review in Grafana Catalog Team Feb 16, 2026
@s4kh s4kh force-pushed the feat-validate-semver branch from a3f0e0a to 4734a26 Compare February 16, 2026 16:20
Copy link
Member

@xnyo xnyo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some small comments but the rest LGTM to me. I don't think this will conflict with #513 as they currently do two different things, but since the analyzer in #513 is called grafanaDependency we can maybe move this check over there instead once merged? (before cutting a release because the analyzer name will change if we move a check from one analyzer to another)

break
}

pluginJsonBytes, _ := os.ReadFile(metadataPath)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the file fails to open or to be read? I'd still keep the error check just in case

if pluginJsonBytes != nil {
var data metadata.Metadata
if err := json.Unmarshal(pluginJsonBytes, &data); err == nil {
_, err = version.NewConstraint(data.Dependencies.GrafanaDependency)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to confirm: with this change we will validate both that the GrafanaDependency is valid according to the regex in the schema + actual semver library used by Grafana's backend?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will use hashicorp/semver to validate the constraint. Schema validation for grafanaDependency will be ignored.

@s4kh s4kh force-pushed the feat-validate-semver branch from 4734a26 to ca6cf1b Compare February 16, 2026 16:36
@s4kh s4kh requested review from academo and xnyo February 16, 2026 17:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 🔬 In review

Development

Successfully merging this pull request may close these issues.

3 participants