kcl-lang / kcl

KCL Programming Language (CNCF Sandbox Project). https://kcl-lang.io
https://kcl-lang.io
Apache License 2.0
1.61k stars 112 forks source link

[Bug] Import JsonSchema: all props converted to snake case #1294

Closed borgius closed 4 months ago

borgius commented 4 months ago

kcl import --force -m jsonschema test.json

I'm not sure why it converted to snake case without any condition. Maybe we could add an additional option like --snake | --camel if we want to change the case and if no option is provided, the case of properties should not be changed.

Source: https://github.com/kcl-lang/kcl-go/blob/945ea9cc4ce681c4242c575df80f1b098b2ffbd4/pkg/tools/gen/genkcl_jsonschema.go#L422

1. Minimal reproduce step (Required)

Json Schema test.json ```json { "$id": "https://example.com/person.schema.json", "$schema": "https://json-schema.org/draft/2020-12/schema", "title": "Person", "type": "object", "properties": { "firstName": { "type": "string", "description": "The person's first name." }, "lastName": { "type": "string", "description": "The person's last name." }, "age": { "description": "Age in years which must be equal to or greater than zero.", "type": "integer", "minimum": 0 } } } ``` `kcl import --force -m jsonschema test.json`

2. What did you expect to see? (Required)

Correct KCL Schema ```KCL """ This file was generated by the KCL auto-gen tool. DO NOT EDIT. Editing this file might prove futile when you re-run the KCL auto-gen generate command. """ schema PersonSchema: r""" PersonSchema Attributes ---------- firstName : str, optional The person's first name. lastName : str, optional The person's last name. age : int, optional Age in years which must be equal to or greater than zero. """ firstName?: str lastName?: str age?: int check: age >= 0 ```

3. What did you see instead (Required)

Snaked KCL Schema ```KCL """ This file was generated by the KCL auto-gen tool. DO NOT EDIT. Editing this file might prove futile when you re-run the KCL auto-gen generate command. """ schema PersonSchema: r""" PersonSchema Attributes ---------- first_name : str, optional The person's first name. last_name : str, optional The person's last name. age : int, optional Age in years which must be equal to or greater than zero. """ first_name?: str last_name?: str age?: int check: age >= 0 ```

4. What is your KCL components version? (Required)

0.8.7-darwin-arm64

shruti2522 commented 4 months ago

Hey @Peefy, I will take this up.