apple / pkl

A configuration as code language with rich validation and tooling.
https://pkl-lang.org
Apache License 2.0
10.11k stars 265 forks source link

Pkl Error: Cannot render value of type `Listing` as Properties. #275

Open linux-china opened 6 months ago

linux-china commented 6 months ago

I have the schema as following:

server: Server

class Server {
  endpoints: Listing<Endpoint>
}

class Endpoint {
  name: String
  port: UInt16(isBetween(1024, 65535))
}

and configuration:

server {
  endpoints {
    new {
      name = "localhost"
      port = 8080
    }
    new {
      name = "demo"
      port = 8080
    }
  }
}

when run pkl eval -f properties application.pkl and got the stackstrace:

– Pkl Error ––
Cannot render value of type `Listing` as Properties.
Value: new Listing { ?; ? }

I think pkl properties render could adopt list style.

foo.bar[0]="a"
foo.bar[1]="b"
foo.demo[0].host="localhost"
foo.bar[0].port=8080
stackoverflow commented 6 months ago

It's not clear how one would want a List/Listing rendered to properties. A foo = List(1, 2, 3) could as well be rendered as foo=1, 2, 3. That's why you should use a converter to decide how you want these classes to be handled.