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

Idea/Feature Request: JSON schema generation from CRDs #115

Closed
markussiebert opened this issue Oct 11, 2024 · 10 comments · Fixed by #119
Closed

Idea/Feature Request: JSON schema generation from CRDs #115

markussiebert opened this issue Oct 11, 2024 · 10 comments · Fixed by #119
Assignees
Labels
enhancement New feature or request

Comments

@markussiebert
Copy link

markussiebert commented Oct 11, 2024

Problem Statement

Currently, the tool is highly useful for generating example YAML files from Kubernetes Custom Resource Definitions (CRDs). However, many users also require JSON schemas for better integration with development environments. JSON schemas enable powerful features like auto-completion and validation in various IDEs through YAML plugins.

Generating these schemas manually using tools like yq is possible, but it can be cumbersome and non-intuitive, especially for new users. Integrating JSON schema generation directly into the tool would streamline this process and provide significant value.

Proposed Solution

Enhance the current tool to include functionality that:

  1. Automatically generates JSON schemas from CRDs.

Benefits

  • Enhanced IDE Support: Users can take advantage of auto-completion and schema validation, improving their overall development experience.
  • Time-Efficiency: Simplifies and reduces the time needed to generate and utilize JSON schemas, especially for new users.
  • Consistency: Ensures that the JSON schemas are always accurately derived from the CRDs, reducing the risk of errors.

Conclusion

By adding JSONSchema generation to the tool, we can greatly enhance its functionality and provide users with a more powerful and intuitive development process. This feature would bridge the gap between CRD definitions and practical IDE integration, making the tool even more valuable.

What du you think @Skarlso

@markussiebert markussiebert changed the title Idea/Feature Request: JSONSchema Generation from CRDs Idea/Feature Request: JSON schema Generation from CRDs Oct 11, 2024
@markussiebert markussiebert changed the title Idea/Feature Request: JSON schema Generation from CRDs Idea/Feature Request: JSON schema generation from CRDs Oct 11, 2024
@Skarlso
Copy link
Owner

Skarlso commented Oct 11, 2024

Hello!

Thanks for the writeup. :) I'm not opposed to it. CRD's OpenAPIV3Schema is already very close to a JSON Schema. I'm not a 100% sure it's a 1:1 convert... But let's see what we can do there. :)

@Skarlso Skarlso added the enhancement New feature or request label Oct 11, 2024
@Skarlso Skarlso self-assigned this Oct 11, 2024
@dariozachow
Copy link

OpenApi v3.1 is 100% compatible with json-schema

@Skarlso
Copy link
Owner

Skarlso commented Oct 11, 2024

For sure, but some fields have to be adjusted and the whole thing needs to be turned into JSON. :)

@Skarlso
Copy link
Owner

Skarlso commented Oct 11, 2024

Well, this was easier than expected... :D
Image

@markussiebert
Copy link
Author

Great!

@Skarlso
Copy link
Owner

Skarlso commented Oct 12, 2024

Would this be okay, or did you imagine something else? #119

Basically a command that will generate the JSON Schema out of the CRD into a file. Nothing fancy really.

@markussiebert
Copy link
Author

Just tried your code - the generated json schema worked! For me right now, sufficient :D

Things I found out:

  • without specifying output, nothing happend (return code 0 - no error - but no file json schema generated)
  • Global Options like format and minimal won't work I think, but are still present (of course they are global XD) - just somehow irritating...

@Skarlso
Copy link
Owner

Skarlso commented Oct 13, 2024

Thanks for the feedback! 😊

@Skarlso
Copy link
Owner

Skarlso commented Oct 13, 2024

Yeah I didn't implement any of the other flags

@Skarlso
Copy link
Owner

Skarlso commented Oct 13, 2024

ok, v0.12.0 should contain the necessary command and flag fixes. :) Please feel free to open new issues with improvement ideas. :) Thank you for using cty! :))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants