Skip to content

genschema.go shouldn't import multiple jsonschema libraries #3510

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

Open
AkihiroSuda opened this issue May 8, 2025 · 8 comments · Fixed by #3515
Open

genschema.go shouldn't import multiple jsonschema libraries #3510

AkihiroSuda opened this issue May 8, 2025 · 8 comments · Fixed by #3515

Comments

@AkihiroSuda
Copy link
Member

"github.com/invopop/jsonschema"
"github.com/lima-vm/lima/pkg/limayaml"
jsonschema2 "github.com/santhosh-tekuri/jsonschema/v6"

Shouldn't need both "github.com/invopop/jsonschema" and "github.com/santhosh-tekuri/jsonschema/v6

@AkihiroSuda AkihiroSuda added the kind/refactoring Refactoring label May 8, 2025
@afbjorklund
Copy link
Member

afbjorklund commented May 8, 2025

There is one library (called "jsonschema") to generate the jsonschema from the comments in the Go code.
There is another library (called "jsonschema") to validate that the default.yaml follows the generated schema.

We could perhaps move the validation into a separate util directory? That would make the separation clearer.
Also the jsonschema validation does not understand the new base directory, and doesn't embed documents:

@afbjorklund
Copy link
Member

afbjorklund commented May 10, 2025

Should we remove the validation code from Lima, or how do you want to handle not using the santhosh-tekuri/jsonschema library?

commit 157f7a4

We can call the jv CLI instead, as an external program (or check-jsonschema, even though it is written in python)

jv schema-limayaml.json templates/default.yaml default-template.yaml
check-jsonschema --schemafile schema-limayaml.json templates/default.yaml default-template.yaml

@jandubois
Copy link
Member

I don't understand what the desired action is for this issue.

Given that the 2 jsonschema libraries perform different functions, it sounds like they are both needed (or can both be removed).

I have not checked; do they add significantly to the size of limactl? If they do, then I could see the need for moving the functionality into a separate utility.

I think the json schema should be an artifact that is included in the release, like the man pages. That way a user could install it in their IDE to validate lima.yaml files.

I don't see any need why a user would ever need to generate the schema themselves.

The same argument can be made for the man pages.

So maybe both the gendoc and genschema commands should be moved to a helper program that is only used during build time? Could be a "Good First Issue".

@AkihiroSuda
Copy link
Member Author

I wished there might be a single jsonschema library that covers both validation and generation, but not a high priority issue.

@AkihiroSuda
Copy link
Member Author

@afbjorklund
Copy link
Member

afbjorklund commented May 13, 2025

I think the json schema should be an artifact that is included in the release, like the man pages. That way a user could install it in their IDE to validate lima.yaml files.

It is supposed to be published on a website, and then the URL made available to include in the JSON Schema "store"...

https://www.schemastore.org/json/

But you can work around that, by rendering a local file or using the git browser directly or something similar - like so:

https://raw.githubusercontent.com/canonical/cloud-init/main/cloudinit/config/schemas/versions.schema.cloud-config.json

I don't see any need why a user would ever need to generate the schema themselves.

That is why the commands are hidden, and only used by make rules for producing artifacts.

But the schema is more intended for a web site, and the manpages better included with binaries

@jandubois
Copy link
Member

Related:

I see.

As I wrote in that issue, "I have no problem with removing the dependency from our code base as much as reasonably possible", but I don't think we need to go out of our way to remove dependencies that in turn rely on easyjson.

From a legal perspective we are covered by the decision of CNCF that no action is necessary. From a supply chain perspective I think there are enough eyes on this particular module now that it seems unlikely it will be exploited in the future (especially since it doesn't have a lot of activity anymore anyways).

So I think the "reasonably possible" part comes into play here: how much effort would it take, and what does it actually gain us.

To me it is still not clear what the next action should be on this issue.

@jandubois
Copy link
Member

I have not checked; do they add significantly to the size of limactl?

I've checked now, and removing the gendoc and genschema commands reduces the size of limactl by 1MB from 28MB to 27MB, which I would consider immaterial; I think that is not a reason to move them to a separate built-time utility.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants