Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin for schema validation #407

Open
wants to merge 9 commits into
base: beckn-onix-v1.0-develop
Choose a base branch
from

Conversation

AshwiniK-protean
Copy link

Created a plugin that validates a payload against a predefined schema to ensure data integrity. Additionally, I developed a small API that handles POST requests, utilizing this plugin to validate the incoming data before processing it further.

Copy link
Collaborator

@tanyamadaan tanyamadaan left a comment

Choose a reason for hiding this comment

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

Added Comments

parts := strings.Split(relativePath, string(os.PathSeparator))

// Ensure that the file path has at least 3 parts: domain, version, and schema file.
if len(parts) < 3 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add more robust validation to handle edge cases, such as empty paths or incorrect directory structures.

start := time.Now()

var memStatsBefore runtime.MemStats
runtime.ReadMemStats(&memStatsBefore)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider moving this to a debug mode or removing it entirely, not needed in production.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Please review all your test cases, add descriptions, make sure it is clear on what is expected outcome.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Test case for payloads with missing or extra fields?

// indexed by their schema filenames.
func (vp *TekuriValidatorProvider) Initialize(schemaDir string) (map[string]plugins.Validator, error) {
// Initialize the SchemaCache map to store the compiled schemas using a unique key (domain/version/schema).
vp.SchemaCache = make(map[string]*jsonschema.Schema)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Initialize the SchemaCache in the constructor or ensure it is only initialized once.

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.

2 participants