ytt icon indicating copy to clipboard operation
ytt copied to clipboard

Add support for jsonschema export similar to openapi-v3

Open peschmae opened this issue 1 year ago • 5 comments

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 avatar Mar 25 '24 09:03 peschmae

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 avatar Mar 26 '24 07:03 peschmae

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.

peschmae avatar Mar 26 '24 15:03 peschmae

@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 avatar Mar 27 '24 15:03 prembhaskal

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

prembhaskal avatar Apr 06 '24 15:04 prembhaskal

@cppforlife @100mik Please take a look at this

renuy avatar Apr 19 '24 05:04 renuy