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

Short DDO validation & remove hardcoded validation #256

Closed
jamiehewitt15 opened this issue Feb 6, 2024 · 2 comments
Closed

Short DDO validation & remove hardcoded validation #256

jamiehewitt15 opened this issue Feb 6, 2024 · 2 comments
Assignees
Labels
Milestone

Comments

@jamiehewitt15
Copy link
Member

jamiehewitt15 commented Feb 6, 2024

We are using the validateObject function to validate DDOs. However, it is currently doing this validation without checking what fields are required by the schema. So for example, the short DDO is unable to pass the validation as there are hardcoded checks for @context and metadata. The validation should only check for fields that are required by the schema. This could also cause problems for other DDO formats from other organisations, or ones added by us in the future.

export async function validateObject(
  obj: Record<string, any>,
  chainId: number,
  nftAddress: string
): Promise<[boolean, Record<string, string>]> {
  CORE_LOGGER.logMessage(`Validating object: ` + JSON.stringify(obj), true)
  const extraErrors: Record<string, string> = {}
  if (!('@context' in obj)) {
    extraErrors['@context'] = 'Context is missing.'
  }
  if ('@context' in obj && !Array.isArray(obj['@context'])) {
    extraErrors['@context'] = 'Context is not an array.'
  }
  if (!('metadata' in obj)) {
    extraErrors.metadata = 'Metadata is missing or invalid.'
  }
  ;['created', 'updated'].forEach((attr) => {
    if ('metadata' in obj && attr in obj.metadata && !isIsoFormat(obj.metadata[attr])) {
      extraErrors.metadata = `${attr} is not in ISO format.`
    }
  })

  if (!chainId) {
    extraErrors.chainId = 'chainId is missing or invalid.'
  }

...
@mariacarmina
Copy link
Member

Also remove the metadata checks, there are handled by shacl schemas

@mariacarmina mariacarmina changed the title DDO validation should be based on the schema Short DDO validation & remove hardcoded validation Feb 16, 2024
@mihaisc
Copy link
Contributor

mihaisc commented Jun 10, 2024

@mihaisc figure out if we need SHACL or we can replace it with some other validation schema

@alexcos20 alexcos20 added this to the alfa release milestone Jul 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants