-
Notifications
You must be signed in to change notification settings - Fork 33
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
[K8s Contrib CRD] Duplicate class definitions in generated module #40
Comments
Hi! This happens to me as well. Would it be possible to prefix the class names with the parent(s) to avoid name collisions? E.g.
would become
|
I don't know the problem space well enough. Are you sure these are always separate classes? Can they be the same class, but with fields that can be omitted? A more Pkly thing could be to have separate modules for |
did this fix it? |
I ran into this issue today with trying to convert Elastic Cloud on Kubernetes (ECK) CRDs to PKL.
Converting the pkl file back to
|
I have the same problem: $ pkl eval "package://pkg.pkl-lang.org/pkl-pantry/[email protected]#/generate.pkl" -m . -p source="https://raw.githubusercontent.com/crossplane/crossplane/master/cluster/crds/apiextensions.crossplane.io_compositions.yaml"
$ pkl eval Composition.pkl
–– Pkl Error ––
Duplicate definition of member `String`.
370 | class String {
^^^^^^^^^^^^
also the generated class name "String" is not ideal |
I believe this would be a great solution. Though I think the decision on when and where to create a seperate module should not be made automatically. Maybe similarly to converters we could decide for which paths a seperate module should be created? createModules {
["foos.v1.example.com"] {
new List("first")
new List("second")
}
} or a more complex Example the Kubernetes Deployment if it were a CRD: createModules {
["deployments.apps.api.k8s"] {
[new List("selector")] = "LabelSelector"
[new List("spec", "template")] = "PodTemplateSpec"
[new List("spec", "template", "spec")] = "PodSpec"
[new List("spec", "template", "spec", "imagePullSecrets")] = "LocalObjectReference"
[new List("spec", "template", "spec", "securityContext", "seLinuxOptions")] = "SELinuxOptions"
// and so on.
}
} So a CRD of a Deployment would contain these Modules:
|
In case it helps someone else: I replaced
With let (typeName = determineTypeName(path, path.fold(List(), (res: List<String>, el: String) -> res.add(el.capitalize())).join(""), accumulator.values.toSet(), 0)) which generates beatiful class names like |
@Avarei, have you considered submitting a PR with that ^ fix? |
…ng properties (objects, list). This change will result in: "spec.foo.bar": - current: classes ["Spec", "Foo", "Bar"] - change: classes ["Spec", "SpecFoo", "SpecFooBar" This change is suggested by https://github.com/Avarei in apple#40 (comment)
The example CRD below secifies
.first.some_class
and.second.some_class
. The CRD generator successfully generates a module. However, the module defines the classSomeClass
twice which leads to an error upon evaluation.The CRD
Resulting PKL
The text was updated successfully, but these errors were encountered: