-
Notifications
You must be signed in to change notification settings - Fork 28
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
refactor(jsonschema): relocate schema generator #1219
Open
wass3r
wants to merge
6
commits into
main
Choose a base branch
from
refactor/jsonschema
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1219 +/- ##
==========================================
- Coverage 56.87% 56.62% -0.26%
==========================================
Files 599 600 +1
Lines 32869 33092 +223
==========================================
+ Hits 18695 18738 +43
- Misses 13538 13715 +177
- Partials 636 639 +3
|
wass3r
changed the title
refactor(jsonschema): move jsonschema generator from types to here
refactor(jsonschema): move schema generator from types to here
Oct 30, 2024
wass3r
changed the title
refactor(jsonschema): move schema generator from types to here
refactor(jsonschema): relocate schema generator
Nov 1, 2024
plyr4
approved these changes
Nov 5, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
go-vela/types has been made obsolete. it was responsible for generating the jsonschema that allows for things like IDE validation feedback on Vela YAML pipelines. it was generated via https://github.com/go-vela/types/tree/main/cmd/schema and utilized
github.com/alecthomas/jsonschema
. schemastore hosts a reference to the published artifact.github.com/alecthomas/jsonschema
has been archived in favor ofgithub.com/invopop/jsonschema
, so we're taking the opportunity to upgrade. in the process we're moving from jsonschema draft 4 (2013) to jsonschema 2020-12 (2022) as that is the spec supported by the new library. there are no substantial differences in the generated schema.the struct tags do most of the heavy lifting for determining the final schema, but there are some necessary customziations due to custom types/unmarshaling we utilize. the library provides some means of doing so by adding certain methods to structs to hook into the generation process. overall, it seems a bit cleaner.
summary of changes
github.com/invopop/jsonschema
schema
package for generating the schema on the fly and to potentially leverage in other places like the CLI for pipeline validationsome notes
jsonschema package
i took the opportunity to look around for alternatives to see what was out there. i think i would have liked to explore using https://github.com/swaggest/jsonschema-go although it doesn't support 2020-12 yet. most notably, it drops the need for separate
jsonschema
struct tag, instead relying onjson
and other "direct" tags - theinvopop/jsonschema
maintainers even reference that as something they wish to move toward.jsonschema validation
i was thinking about adding in validation. the most notable package for this is https://github.com/santhosh-tekuri/jsonschema (and we're using their provided CLI for the tests that are ran via shell), however it can currently only read in actual files. you provide it with a filename reference which can be a remote URL or local file and tries to resolve it.
i found https://github.com/kaptinlin/jsonschema which seems to address that aspect, but it looks almost too new. however, i did try to use it but ran into some issues where it would claim some valid pipelines were invalid.
i decided to not pursue built-in validation at this time, but it might be worth considering in the future. especially when it comes to validating pipelines using the schema in the Vela CLI. there, we could use the previous library by writing a temp file of the schema (or loading the remote, published schema) and loading the pipeline YAML to validate. generating schema in memory and passing that to the validator seems a bit nicer than utilizing file system or pulling it in remotely 🤷🏼
schemastore
once merged and new schema is published we need to provide a PR to https://github.com/SchemaStore/schemastore to provide the new link. we could fast track a little by generating and uploading schema to the last release manually for now since we just reference the latest release for the schema.json artifact 🤔