carvel-dev / ytt

YAML templating tool that works on YAML structure instead of text
https://carvel.dev/ytt
Apache License 2.0
1.62k stars 136 forks source link

Add support for jsonschema export similar to openapi-v3 #898

Open peschmae opened 3 months ago

peschmae commented 3 months ago

Describe the problem/challenge you have Most text editors use json schema, to autocomplete and validate YAML files. To make it easier to the users, to write YAML files based on a YTT schema, it would be great to have a way to create the json schema from a YTT file, similar to the openapi schema that is currently implemented.

Describe the solution you'd like Support for json schema as a output option for ytt -f schema.yaml --data-values-schema-inspect --output

Anything else you would like to add: During kubecon 2024, the talk Developers demand UX for K8s highlighted that YAML validation & auto-completion seems to be one of the main struggles developers face when working with Kubernetes.

Using YTT and it's schemas, could help alleviate that issue.


Vote on this request

This is an invitation to the community to vote on issues, to help us prioritize our backlog. Use the "smiley face" up to the right of this comment to vote.

👍 "I would like to see this addressed as soon as possible" 👎 "There are other more important things to focus on right now"

We are also happy to receive and review Pull Requests if you want to help working on this issue.

peschmae commented 3 months ago

After diggin in to the openapi schema generation for #897 I think this shouldn't be too hard to implement, as the property attributes are mostly identical, and a lot of the code could be reused.

From a quick glance at https://swagger.io/docs/specification/data-models/keywords/ the biggest difference is that type is a list, and nullable isn't an attribute, but needs to be added to the type list.

@prembhaskal Let me know if I should draft a pull request for this.

peschmae commented 3 months ago

I found some time today, and threw a quick and dirty approach together in a feature branch: https://github.com/peschmae/ytt/tree/feat/jsonschema

It would still need a refactoring, to reduce duplicate code shared with the openschema export, but it already converts into a valid schema that is properly interpreted by vscode.

prembhaskal commented 3 months ago

@peschmae I am bit stuck with other stuff, but I can review it over weekend. but you can go ahead and put up a PR if you want some early eyes on it.

@100mik @sethiyash PTAL when you get time.

prembhaskal commented 3 months ago

I am unable to check it still, so removed assignee.

renuy commented 2 months ago

@cppforlife @100mik Please take a look at this