Skip to content

[meshkit] Broaden schema validator coverage#942

Open
leecalcote wants to merge 2 commits intomasterfrom
followup/dynamic-schema-types
Open

[meshkit] Broaden schema validator coverage#942
leecalcote wants to merge 2 commits intomasterfrom
followup/dynamic-schema-types

Conversation

@leecalcote
Copy link
Member

Summary

  • remove the fixed exported schema-type aliases and rely on dynamic document type discovery
  • add runtime DocumentTypes() enumeration for all schema assets discovered from github.com/meshery/schemas
  • tighten template-based schemaVersion extraction for sibling schemas like connection/connection_page
  • add connection validation coverage and forward-looking credential validation coverage

Testing

  • go test ./schema -count=1
  • golangci-lint run ./schema/...
  • make tidy
  • make check
  • make test (fails only on pre-existing unrelated generators/github and registry issues)

Remove the fixed exported schema-type aliases, expose runtime document type discovery, tighten template-based schemaVersion detection, and add coverage for connection validation plus forward credential support.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: marblom007 <158522975+marblom007@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 12, 2026 22:39
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the schema validation capabilities by moving from fixed schema type aliases to a more dynamic discovery mechanism. It introduces runtime enumeration of all available schema document types, ensuring that the validator can adapt to new and existing schema assets from the meshery/schemas module. Furthermore, it refines the schema version extraction logic for complex cases and adds comprehensive validation tests for connection and credential documents, improving the robustness and future-proofing of the schema system.

Highlights

  • Dynamic Document Type Discovery: Removed fixed schema-type aliases, transitioning to dynamic document type discovery for greater flexibility and extensibility.
  • Runtime Document Type Enumeration: Introduced runtime DocumentTypes() enumeration for all schema assets discovered from github.com/meshery/schemas, allowing for programmatic access to available types.
  • Improved Schema Version Extraction: Tightened template-based schema version extraction to correctly handle sibling schemas, preventing unintended inheritance of schema versions.
  • Expanded Validation Coverage: Added comprehensive validation coverage for connection and credential document types, including scenarios for auto-detection and explicit type validation.
Changelog
  • schema/compiler_test.go
    • Removed the TestKeywordFromLocation function.
  • schema/constructs_test.go
    • Added new test file to provide extensive validation coverage for connection and credential schemas, including scenarios for auto-detection, explicit type validation, and handling of missing schemaVersion properties.
  • schema/doc.go
    • Updated package documentation to describe the new dynamic schema discovery and DocumentTypes() enumeration.
  • schema/registry.go
    • Modified schemaVersionFromTemplates to ensure that schema versions are correctly extracted from templates, specifically addressing cases with sibling schemas by using a precise template prefix.
  • schema/registry_test.go
    • Updated existing tests to utilize the new DocumentType("...") syntax instead of deprecated fixed aliases.
    • Added new tests to verify the functionality of DocumentTypes(), ensuring it includes built-in and dynamically discovered types, maintains sorting, and correctly reflects custom registrations.
  • schema/validator.go
    • Removed the fixed DocumentType aliases (e.g., TypeComponent, TypeConnection).
    • Introduced a new DocumentTypes() method on the Validator struct and a package-level DocumentTypes() function to provide a sorted list of all registered document types at runtime.
    • Added sort package import.
  • schema/validator_test.go
    • Updated various tests to use the new DocumentType("...") syntax, aligning with the removal of fixed aliases.
Activity
  • No specific activity (comments, reviews, progress) has been recorded for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the schema validation by removing hardcoded schema type aliases and introducing dynamic discovery of document types. It also adds a DocumentTypes() function to enumerate all registered schema types and enhances the test coverage for connection and credential validation. The changes look solid and improve the flexibility and maintainability of the schema validation logic. I have one suggestion to improve the robustness of a new test case.

Comment on lines +104 to +117
instancePaths := make([]string, 0, len(details.Violations))
for _, v := range details.Violations {
instancePaths = append(instancePaths, v.InstancePath)
}
foundMissing := false
for _, missing := range []string{"/sub_type", "/kind", "/status"} {
for _, p := range instancePaths {
if p == missing {
foundMissing = true
}
}
}
assert.True(t, foundMissing,
"expected at least one of /sub_type, /kind, /status in violation paths, got: %v", instancePaths)
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The check for missing fields is a bit weak as it only ensures at least one missing field is reported. A more robust test would verify that all expected missing fields are reported as violations. Additionally, the implementation can be made more concise and readable by using a map for lookups instead of nested loops.

instancePathSet := make(map[string]struct{})
	for _, v := range details.Violations {
		instancePathSet[v.InstancePath] = struct{}{}
	}

	for _, missingField := range []string{"/sub_type", "/kind", "/status"} {
		assert.Contains(t, instancePathSet, missingField, "expected violation for missing required field %q", missingField)
	}

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR broadens Meshery schema validator coverage by removing fixed exported document-type aliases, relying on runtime discovery of schema assets, and adding enumeration + additional test coverage around schema discovery and validation.

Changes:

  • Remove exported Type* schema-type constants in favor of using DocumentType("...").
  • Add DocumentTypes() APIs (package-level + Validator method) to enumerate registered document types.
  • Tighten template-based schemaVersion extraction to avoid cross-contamination between sibling schemas, and expand tests for connection + forward-looking credential validation.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
schema/validator.go Removes exported type aliases and adds DocumentTypes() enumeration (sorted snapshot).
schema/validator_test.go Updates tests to use DocumentType("...") instead of removed constants.
schema/registry.go Narrows template matching for schemaVersion extraction to the schema’s exact template name.
schema/registry_test.go Updates existing tests for dynamic DocumentType usage and adds coverage for DocumentTypes() behavior.
schema/doc.go Documents dynamic discovery and the new document-type enumeration API.
schema/constructs_test.go Adds end-to-end validation tests for connection and synthetic credential schema scenarios.
schema/compiler_test.go Removes an obsolete test for a now-nonexistent helper.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

schema/doc.go Outdated
Comment on lines +16 to +24
// fmt.Println(dt)
// }
//
// Callers that need a specific type should construct it directly with
// [DocumentType], for example:
//
// ref := schema.Ref{
// SchemaVersion: "relationships.meshery.io/v1alpha3",
// Type: schema.DocumentType("relationship"),
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

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

In Go package docs, preformatted code blocks require every line in the block to be tab-indented. Only the first line here is tab-indented; the following lines use spaces, so godoc will render them as normal text rather than a code block. Consider switching these lines to tab indentation to keep the example formatted correctly.

Suggested change
// fmt.Println(dt)
// }
//
// Callers that need a specific type should construct it directly with
// [DocumentType], for example:
//
// ref := schema.Ref{
// SchemaVersion: "relationships.meshery.io/v1alpha3",
// Type: schema.DocumentType("relationship"),
// fmt.Println(dt)
// }
//
// Callers that need a specific type should construct it directly with
// [DocumentType], for example:
//
// ref := schema.Ref{
// SchemaVersion: "relationships.meshery.io/v1alpha3",
// Type: schema.DocumentType("relationship"),

Copilot uses AI. Check for mistakes.
Comment on lines +344 to +359
// "connection_page.yaml"). We only read templates whose name begins with
// that exact name so that sibling schemas sharing a templates/ directory
// (such as connection.yaml and connection_page.yaml) cannot inherit each
// other's schemaVersion.
schemaBase := strings.TrimSuffix(path.Base(assetPath), path.Ext(assetPath))
templatePrefix := schemaBase + "_template"

values := map[string]struct{}{}
for _, entry := range entries {
if entry.IsDir() || !isDiscoverableSchemaAsset(entry.Name()) {
continue
}

entryBase := strings.TrimSuffix(entry.Name(), path.Ext(entry.Name()))
if entryBase != templatePrefix {
continue
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

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

The comment says templates are read when their name "begins with" the derived prefix, but the implementation requires an exact match on the basename (no extra suffixes). If exact match is intended per the documented convention {schema_base}_template.{ext}, consider updating the wording to avoid implying prefix matching.

Copilot uses AI. Check for mistakes.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Lee Calcote <leecalcote@gmail.com>
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