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

feat: enhance generation of kcl schema from json schema #135

Merged
merged 4 commits into from
Aug 14, 2023

Conversation

jakezhu9
Copy link
Contributor

1. Does this PR affect any open issues?(Y/N) and add issue references

  • N
  • Y

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):

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Other

In this PR, I make the following changes:

  • fix a bug related to enum and const with type.
"category": {
    "type": "string",
    "enum": [
        "A",
        "B"
    ]
}
------
// Before, we will get the following result, which accept all string.
category?: str | "A" | "B"
------
// Now, we will ignore the type for enum and const to get the correct result
category?: "A" | "B"
  • improve the naming logic. For the root schema, it may has $id keyword, or title keyword, or neither as they are not required. So now we prefer $id, then title keyword, then name in parameter(for root schema it will be the filename). If neither exists, we will use "MyType" as default.
  • handle name conflict. For the keywords in kcl, if it is used as a identifier, we will add $ before it to avoid name conflict.
  • Optimize output for unsupported keywords. Previously, unsupported keywords could result in weird results and syntax errors. Now, we will convert it into "any" type to make it still work, although with some loss of information.

4. Are there any breaking changes?(Y/N) and describe the breaking changes(e.g. more details, motivations or doc link):

  • N
  • Y

5. Are there test cases for these changes?(Y/N) select and add more details, references or doc links:

  • Unit test
  • Integration test
  • Benchmark (add benchmark stats below)
  • Manual test (add detailed scripts or steps below)
  • Other

@Peefy Peefy added the tool label Aug 14, 2023
Copy link
Contributor

@Peefy Peefy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good Job! 🐮 👍 LGTM!

@Peefy Peefy merged commit 10fe7b1 into kcl-lang:main Aug 14, 2023
6 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Aug 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants