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

Switch to AJV for validating JSON Schema #9191

Merged
merged 9 commits into from
Feb 29, 2024
Merged

Conversation

somebody1234
Copy link
Contributor

@somebody1234 somebody1234 commented Feb 26, 2024

Pull Request Description

As requested suggested by @radeusgd

Important Notes

None

Checklist

Please ensure that the following checklist has been satisfied before submitting the PR:

  • The documentation has been updated, if necessary.
  • Screenshots/screencasts have been attached, if there are any visual changes. For interactive or animated visual changes, a screencast is preferred.
  • All code follows the
    Scala,
    Java,
    and
    Rust
    style guides. In case you are using a language not listed above, follow the Rust style guide.
  • All code has been tested:
    • Unit tests have been written where possible.
    • If GUI codebase was changed, the GUI was tested when built using ./run ide build.

@somebody1234 somebody1234 added CI: No changelog needed Do not require a changelog entry for this PR. g-dashboard x-refactor Changes that should not be visible to the end-user labels Feb 26, 2024
@radeusgd
Copy link
Member

As requested

Well I thought it was just a suggestion 😅 but thanks for implementing this, I think that will indeed be right approach!

@@ -148,7 +156,9 @@ export default function DataLinkInput(props: DataLinkInputProps) {
value={typeof value === 'string' ? value : ''}
size={1}
className={`rounded-full w-40 px-2 bg-transparent border leading-170 h-6 py-px disabled:opacity-50 read-only:opacity-75 read-only:cursor-not-allowed ${
jsonSchema.isMatch(DEFS, schema, value) ? 'border-black/10' : 'border-red-700/60'
error.assert<ajv.ValidateFunction>(() => AJV.getSchema(path))(value)
Copy link
Member

Choose a reason for hiding this comment

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

I think I'd refactor this error.assert<...>(() => AJV.getSchema(path)) pattern into some helper function, as it is used all over the place.

e.g. function getKnownSchema

@enso-bot enso-bot bot mentioned this pull request Feb 27, 2024
7 tasks
Comment on lines 40 to 60
/** Return a human-readable name representing a schema. */
function getSchemaNameHelper(schema: object): string {
if ('title' in schema) {
return String(schema.title)
} else if ('type' in schema) {
return String(schema.type)
} else if ('$ref' in schema) {
const referencedSchema = jsonSchema.lookupDef(DEFS, schema)
return referencedSchema == null ? '(unknown)' : getSchemaName(referencedSchema)
} else if ('anyOf' in schema) {
const members = Array.isArray(schema.anyOf) ? schema.anyOf : []
return (
members.flatMap(object.singletonObjectOrNull).map(getSchemaName).join(' | ') || '(unknown)'
)
} else if ('allOf' in schema) {
const members = Array.isArray(schema.allOf) ? schema.allOf : []
return members.flatMap(object.singletonObjectOrNull).join(' & ') || '(unknown)'
} else {
return '(unknown)'
}
}
Copy link
Member

Choose a reason for hiding this comment

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

This function seems copy-pasted, can we get it just in one place?

@PabloBuchu
Copy link
Contributor

  1. Something is broken when I try to set Authentication with key and secret
Screen.Recording.2024-02-28.at.12.20.39.mov
Screenshot 2024-02-28 at 12 21 04

@somebody1234
Copy link
Contributor Author

wow that is funky. i'll have to look into it

@somebody1234
Copy link
Contributor Author

somebody1234 commented Feb 28, 2024

@PabloBuchu weird, i can't repro

@@ -193,7 +197,7 @@ export default function AssetSearchBar(props: AssetSearchBarProps) {
document.removeEventListener('keydown', onKeyDown)
document.removeEventListener('keyup', onKeyUp)
}
}, [setQuery])
}, [setQuery, /* should never change */ modalRef])
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure if I understand this comment, but it may be just because I'm not familiar enough with the codebase.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah the comment is a little awkward, not sure how useful it is in practice. the array here is a dependency list, so the function is re-run when any of the dependencies change. the comment indicates that it is likely a mistake if th value changes - it is required to be in the dependency list because of our linter setup.

Copy link
Member

@radeusgd radeusgd left a comment

Choose a reason for hiding this comment

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

Looks good to me, but I did not review JSONSchemaInput.tsx very deeply as I'm not familiar enough with the framework to provide constructive review, at least not yet.

@PabloBuchu
Copy link
Contributor

@somebody1234 weird I am also no longer able to reproduce 🤷 qa 🟢

@PabloBuchu PabloBuchu added the CI: Ready to merge This PR is eligible for automatic merge label Feb 29, 2024
@mergify mergify bot merged commit 0a28d91 into develop Feb 29, 2024
27 of 29 checks passed
@mergify mergify bot deleted the wip/sb/use-validator-library branch February 29, 2024 10:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI: No changelog needed Do not require a changelog entry for this PR. CI: Ready to merge This PR is eligible for automatic merge g-dashboard x-refactor Changes that should not be visible to the end-user
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants