Skip to content

Generic golang interface{} serialization gives an empty object for structs #1326

@yuriy-yarosh

Description

@yuriy-yarosh

Description of the bug:

I'm facing something similar to #1291 with Crossplane.

Crossplane CompositeResourceDefinition (XRD) CRD defines openAPIV3Schema as a type: object, which results in an empty object synthesis and plain interface{} generation.

So, for a crossplane XRD, this

Versions: &([]*xrd.CompositeResourceDefinitionSpecVersions{{
	Name:                     jsii.String("v1alpha1"),
	Referenceable:            jsii.Bool(true),
	Served:                   jsii.Bool(true),
	Schema: &xrd.CompositeResourceDefinitionSpecVersionsSchema{
		OpenApiv3Schema: &k8s.JsonSchemaProps{
			Type: jsii.String("Object"),
		},
	},
}}),

CRD codegen gives an interface{} for a type: object schema

properties:
  openAPIV3Schema:
    description: OpenAPIV3Schema is the OpenAPI v3 schema to use for validation and pruning.
    type: object
    x-kubernetes-preserve-unknown-fields: true
type CompositeResourceDefinitionSpecVersionsSchema struct {
	// OpenAPIV3Schema is the OpenAPI v3 schema to use for validation and pruning.
	OpenApiv3Schema interface{} `field:"optional" json:"openApiv3Schema" yaml:"openApiv3Schema"`
}

it synthesizes just an empty object {}, disregarding the contents

  versions:
    - name: v1alpha1
      referenceable: true
      schema:
        openAPIV3Schema: {}
      served: true

It should be possible to cast existing struct to interface{}, or at least convert it to mapstructure as map[string]interface{} using the respective yaml reflection tags out of the existing k8s JsonSchemaProps, to overcome this. But I'd like a bit more concise solution, or at least an exception During Synthesis, instead of an empty output.

Reproduction Steps:

  1. Import a CRD schema with type: object which would generate interface{}
  2. Pass a struct{} with something there
  3. Get empty output during synthesis

Environment:

  • github.com/cdk8s-team/cdk8s-core-go/cdk8s/v2 v2.7.59
  • github.com/aws/jsii-runtime-go v1.81.0
  • github.com/aws/constructs-go/constructs/v10 v10.2.20

This is 🐛 Bug Report

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingclosed-for-stalenessIssue/PR was closed due to stalenesseffort/small1 day topspriority/p1Should be on near term plans

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions