apple / pkl-pantry

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

[K8s Contrib CRD] CRD generation failed when a field uses `{}` as default value. #32

Closed inoc603 closed 7 months ago

inoc603 commented 7 months ago

CRD generation will fail when a field uses {} as default value.

–– Pkl Error ––
Expected value of type `Boolean|Number|Null|String|Dynamic|Typed|Listing`, but got type `Mapping`.
Value: new Mapping {}

39 | typealias JsonSchemaValue = Boolean|Number|Null|String|Dynamic|Typed|Listing
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
at org.json_schema.JsonSchema#default (projectpackage://pkg.pkl-lang.org/pkl-pantry/org.json_schema@1.0.0#/JsonSchema.pkl)

101 | default = raw.getOrNull("default")
                ^^^^^^^^^^^^^^^^^^^^^^^^
at org.json_schema.Parser#toJsonSchema.default (projectpackage://pkg.pkl-lang.org/pkl-pantry/org.json_schema@1.0.0#/Parser.pkl)

......

A minimal CRD to reproduce the problem:

apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: example
spec:
  scope: Namespaced
  group: example
  names:
    kind: Example
  versions:
    - name: v1
      served: true
      storage: true
      schema:
        openAPIV3Schema:
          properties:
            some_map:
              additionalProperties:
                type: string
              default: {}
              type: object
          type: object
bioball commented 7 months ago

Thanks! Fixed in package://pkg.pkl-lang.org/pkl-pantry/k8s.contrib.crd@1.0.2