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

Use CUE to define schema for files #391

Closed
wants to merge 13 commits into from

Conversation

jsoriano
Copy link
Member

@jsoriano jsoriano commented Aug 15, 2022

What does this PR do?

Uses CUE to define the schema for files instead of JSON schema (only integration manifest and changelog by now).

It includes #384 for semantic rules versioning.

Thoughts on using CUE for schema validation

TLDR; I am not convinced that it provides general advantages.

Pros:

  • Expressive and compact syntax.
  • Conditional code.
  • Nice features like checking backwards compatibility.

Cons:

  • No first-level support for descriptions, examples and so on, we would need to work on something else for documentation.
  • Only approach for reusability of definitions is the use of packages, but packages loading don't support fs.FS (cue/load: support loading from io/fs.FS cue-lang/cue#607). Hacks needed.
  • Syntax behaves a bit unexpectedly sometimes. Examples:
    • Data injection with tags is quite tricky, and doesn't always work.
    • Additional contents are only checked for named definitions, they are not checked when validating against the spec in the root of a file. This forces us to work with definitions, not such a big issue.
  • Internals are hidden in internal libraries. No custom Go logic or types can be added, we'd need to fork or continue with semantic validation. Same limitations in that sense than jsonschema at the end.
  • Validation of relative paths and data stream names would need to be done with semantic validation (current approach of using custom "formats" in JSON schema is tricky in any case).
  • Errors are sometimes quite cryptic, at least in the context of schema validation. Transformations needed.
  • Not 1.0 yet, Go APIs may change.

Why is it important?

To support multiple versions of the spec with the same files.

Checklist

Related issues

@jsoriano jsoriano added the discuss Issue needs discussion label Aug 15, 2022
@jsoriano jsoriano self-assigned this Aug 15, 2022
@elasticmachine
Copy link

elasticmachine commented Aug 15, 2022

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2022-08-15T19:55:47.403+0000

  • Duration: 8 min 47 sec

Test stats 🧪

Test Results
Failed 0
Passed 365
Skipped 0
Total 365

🤖 GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

@elasticmachine
Copy link

🌐 Coverage report

Name Metrics % (covered/total) Diff
Packages 100.0% (7/7) 💚
Files 66.667% (16/24)
Classes 72.222% (26/36)
Methods 57.282% (59/103)
Lines 42.13% (530/1258)
Conditionals 100.0% (0/0) 💚

@jsoriano
Copy link
Member Author

Closing in favor of #384.

@jsoriano jsoriano closed this Aug 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discuss Issue needs discussion
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Introduce new package spec version
2 participants