apple / pkl-pantry

Shared Pkl packages
Apache License 2.0
229 stars 31 forks source link

[OpenAPI v3] SchemaGenerator does not work with ModuleOutput #26

Closed Avarei closed 4 months ago

Avarei commented 4 months ago

While trying to turn a Kubernetes CRD into a Pkl Module and then turning it back into a OpenAPIv3Spec I noticed that K8sObjects from pkl-k8s can not be converted.

Resulting in the following Error:

Unsure how to cast this type: new UnknownType {}

This seems to be due to the ModuleOutput present in k8sObject.

I was able to Fix this by adding another filter for prop.name != "output" to: https://github.com/apple/pkl-pantry/blob/8685ad681b4fa54bdb7355ef9b665f61bad84959/packages/org.openapis.v3/SchemaGenerator.pkl#L293-L295

As I am quite new to Pkl I am not sure if there is a better way to check if a property is a ModuleOutput. I am also not sure if the output could be used with backticks as a regular property.

If you are interested I'm happy to create a PR.

Avarei commented 4 months ago

Steps to reproduce:

Create k8sObjectGen.pkl

import "package://pkg.pkl-lang.org/pkl-k8s/k8s@1.0.1#/K8sObject.pkl"
import "package://pkg.pkl-lang.org/pkl-pantry/org.openapis.v3@1.0.0#/SchemaGenerator.pkl"

example = SchemaGenerator.generate(K8sObject)

Run it

pkl eval k8sObjectGen.pkl -f yaml
bioball commented 4 months ago

Thanks for reporting! Fixed in #30