cdk8s-team / cdk8s-cli

Apache License 2.0
38 stars 23 forks source link

Unable to import crossplane provider-gcp in Typescript #971

Open alex-dixon opened 1 year ago

alex-dixon commented 1 year ago

Description of the bug:

Error when importing github:crossplane-contrib/provider-gcp:

Importing resources, this may take a few moments...
cache.gcp.crossplane.io
  cache.gcp.crossplane.io/cloudmemorystoreinstance
compute.gcp.crossplane.io
  compute.gcp.crossplane.io/address
  compute.gcp.crossplane.io/firewall
  compute.gcp.crossplane.io/globaladdress
  compute.gcp.crossplane.io/network
  compute.gcp.crossplane.io/router
Error: only enums with string or number values are supported
    at TypeGenerator.emitTypeInternal (/project/gcp/infra/node_modules/json2jsii/lib/type-generator.js:157:23)
    at TypeGenerator.typeForProperty (/project/gcp/infra/node_modules/json2jsii/lib/type-generator.js:385:21)
    at TypeGenerator.emitProperty (/project/gcp/infra/node_modules/json2jsii/lib/type-generator.js:324:35)
    at /project/gcp/infra/node_modules/json2jsii/lib/type-generator.js:304:22
    at typesToEmit.<computed> (/project/gcp/infra/node_modules/json2jsii/lib/type-generator.js:204:28)
    at TypeGenerator.renderToCode (/project/gcp/infra/node_modules/json2jsii/lib/type-generator.js:238:33)
    at TypeGenerator.render (/project/gcp/infra/node_modules/json2jsii/lib/type-generator.js:226:14)
    at CustomResourceDefinition.generateTypeScript (/project/gcp/infra/node_modules/cdk8s-cli/lib/import/crd.js:87:29)
    at ImportCustomResourceDefinition.generateTypeScript (/project/gcp/infra/node_modules/cdk8s-cli/lib/import/crd.js:130:23)
    at async ImportCustomResourceDefinition.import (/project/gcp/infra/node_modules/cdk8s-cli/lib/import/base.js:71:13)

Object that appears to be causing.the error:

{
  "description": "AdvertisedGroups: User-specified list of prefix groups to advertise in custom mode. This field can only be populated if advertise_mode is CUSTOM and is advertised to all peers of the router. These groups will be advertised in addition to any specified prefixes. Leave this field blank to advertise no custom groups. \n Possible values: \"ALL_SUBNETS\"",
  "enum": [
    "ALL_SUBNETS"
  ],
  "items": {
    "type": "string"
  },
  "type": "array"
}

Reproduction Steps:

npx cdk8s-cli@2.2.37 init typescript-app
cdk8s import github:crossplane-contrib/provider-gcp@0.22.0

Error Log:

see above

Environment:

Other:


This is :bug: Bug Report

iliapolo commented 1 year ago

@alex-dixon Yeah looks like this is the offending property. I haven't seen this schema variation for defining an array of enums, I would expect this:

{
    "type": "array",
    "items": {
        "type": "string",
        "enum": ["ALL_SUBNETS"]
    }
}

How sure are we its valid schema? can't seem to find examples like this.

github-actions[bot] commented 1 year ago

This issue has not received a response in a while and will be closed soon. If you want to keep it open, please leave a comment below @mentioning a maintainer.

alex-dixon commented 1 year ago

Good point... Maybe the intent was this?

  "type": "array",
  "items": {
    "type": "string",
    "enum": [
     "ALL_SUBNETS"
    ], 
  }

https://www.jsonschemavalidator.net/s/pun2z8DS

The original seems valid yet unsatisfiable? https://www.jsonschemavalidator.net/s/ugWye2zU

iliapolo commented 3 months ago

Keeping this open and marking p2. We need to investigate if that enum declaration is indeed a valid JSON schema - if so we will fix it. If not - not.