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

API().get_schema_type_mapping(args) is missing information about a possible index signature in a schema #187

Open
diefans opened this issue Feb 14, 2025 · 1 comment
Labels
enhancement New feature or request

Comments

@diefans
Copy link

diefans commented Feb 14, 2025

Bug Report

I want to programmatically inspect and deal with KCL schema information und stumbled upon the inability to know anything about the index signature of a schema.

1. Minimal reproduce step (Required)

create a file: test.k

schema Foo:

schema IndexSchema:
    [foo: str]: Foo

schema Test:
    attr: str
    index: IndexSchema
from google.protobuf.json_format import MessageToJson
from kcl_lib import api

exec_args = api.ExecProgram_Args(k_filename_list=["test.k"])
args = api.GetSchemaTypeMapping_Args(exec_args=exec_args)
result = api.API().get_schema_type_mapping(args)

print(MessageToJson(result))

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

Some field indicating the name and type of the index signature [<index_attr_name>: <index_attr_type>]: <index_type> and also if it is open to contain yet unknown attributes using [...<index_attr_type>]: <index_type> where index_attr_name == "...".

3. What did you see instead (Required)

{
  "schemaTypeMapping": {
    "Foo": {
      "type": "schema",
      "schemaName": "Foo",
      "filename": "./test.k",
      "pkgPath": "__main__"
    },
    "IndexSchema": {
      "type": "schema",
      "schemaName": "IndexSchema",
      "properties": {
        "bar": {
          "type": "schema",
          "schemaName": "Foo",
          "line": 1,
          "filename": "./test.k",
          "pkgPath": "__main__"
        }
      },
      "required": [
        "bar"
      ],
      "filename": "./test.k",
      "pkgPath": "__main__"
    },
    "Test": {
      "type": "schema",
      "schemaName": "Test",
      "properties": {
        "index": {
          "type": "schema",
          "schemaName": "IndexSchema",
          "properties": {
            "bar": {
              "type": "schema",
              "schemaName": "Foo",
              "line": 1,
              "filename": "./test.k",
              "pkgPath": "__main__"
            }
          },
          "required": [
            "bar"
          ],
          "line": 2,
          "filename": "./test.k",
          "pkgPath": "__main__"
        },
        "attr": {
          "type": "str",
          "line": 1
        }
      },
      "required": [
        "attr",
        "index"
      ],
      "filename": "./test.k",
      "pkgPath": "__main__"
    }
  }
}

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

0.11.0-linux-amd64

@Peefy
Copy link
Contributor

Peefy commented Feb 15, 2025

Related issue: kcl-lang/kcl-go#411 cc @He1pa @zong-zhe

@Peefy Peefy added bug Something isn't working enhancement New feature or request and removed bug Something isn't working labels Feb 15, 2025
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

No branches or pull requests

2 participants