-
Notifications
You must be signed in to change notification settings - Fork 26
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
feat: generate kcl schema from json schema #127
Conversation
Good Job! I will carefully review it later, and before that, there are some reminders:
|
Thanks for your careful review! Your feedback really helped improve my code.
Certainly! It also remind me that as a package we should not make our internal type and functions public. I think we should only expose the structures and functions related to generating code, making it easier to use the package.
You are right! Small PRs are easier to understand and review. However, in this PR, most of the changes are in the jsonschema package, and it only implements basic conversion. So, I don't think it needs to be split further. But, I'll definitely consider making smaller PRs in the future.
Good idea! I will try to record this process and share it later For the kcl type in my code, I designed a typeInterface to support different types, reducing unnecessary fields in each type and making it simpler and clearer. I'm also working on making it more generic so that it can support more features in the future, even though it might seem a bit duplicative with the existing "pb.KclType." As for the CI error, it's caused by a lower version of Go. If you run it locally with a version above 1.18, it should pass. Your suggestions have been really inspiring, and if you have any more ideas, please feel free to share them with me! |
Good Job! U can rebase the main branch to upgrade the KCL type API and go 1.19+ in CI. |
Pull Request Test Coverage Report for Build 5736081236
💛 - Coveralls |
1. Does this PR affect any open issues?(Y/N) and add issue references (e.g. "fix #123", "re #123".):
part of kcl-lang/kcl#526
2. What is the scope of this PR (e.g. component or file name):
pkg/tools/gen
3. Provide a description of the PR(e.g. more details, effects, motivations or doc link):
In this pull request, I add the capability to convert from JSON schema to KCL schema. Here are the details:
Expanded the GenKcl function to support various file types and automatic detection of file types.
Integrated the jsonschema package for parsing JSON schemas. I made some adjustments to meet our needs, like making some fields public and using ordered maps in the "properties" keyword to preserve the order.
Added new types, such as Schema, Property, along with the necessary conversion code. I initially considered using the existing
pb.KclType
, but it lacked some fields like validation. So, I opted to create a new type.Added template-related functions to generate KCL schema code. I have also added the test code, you can view the results from it.
Please note that some JSON schema keywords are not currently supported, but I plan to add them in the near future. Additionally, I'll be working on documentation and validation sections.
4. Are there any breaking changes?(Y/N) and describe the breaking changes(e.g. more details, motivations or doc link):
5. Are there test cases for these changes?(Y/N) select and add more details, references or doc links: