Skip to content
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

fix: inferred structs from a namespace should be taken from namespace #223

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

DanielMSchmidt
Copy link

@DanielMSchmidt DanielMSchmidt commented Aug 8, 2023

WIP

TODOs

  • Test Case for star import / inference with namespaces
  • Test Case for adding imports for inferred structs
  • See if the problems are correlated, sacrifice the star import one if needed
  • Might need to have a side-effect in the traversal that informs things to import as well as the ones present in TS

Problem

We have generated typescript code that looks either like this

import { Construct } from "constructs";
import * as aws from "./.gen/providers/aws/";

class MyConvertedCode extends Construct {
  constructor(scope: Construct, name: string) {
    super(scope, name);
    new aws.s3_bucket.S3Bucket(this, "bucket", {
      logging:  {
          target_bucket: "target",
        },
    });
  }
}

or like this (in newer cdktf versions)

import { Construct } from "constructs";
import { S3Bucket } from "./.gen/providers/aws/s3-bucket";

class MyConvertedCode extends Construct {
  constructor(scope: Construct, name: string) {
    super(scope, name);
    new S3Bucket(this, "bucket", {
      logging:  {
          target_bucket: "target",
        },
    });
  }
}

The resulting rosetta converted code leads to this e.g. in Python:

from imports.aws.s3_bucket import S3Bucket
class MyConvertedCode(Construct):
    def __init__(self, scope, name):
        super().__init__(scope, name)

        S3Bucket(self, "bucket",
            logging=S3BucketLogging(
                target_bucket="target"
            )
        )

The correct code would be

from imports.aws.s3_bucket import S3Bucket, S3BucketLogging
class MyConvertedCode(Construct):
    def __init__(self, scope, name):
        super().__init__(scope, name)

        S3Bucket(self, "bucket",
            logging=S3BucketLogging(
                target_bucket="target"
            )
        )

or for the star imported version

import imports.aws as aws
class MyConvertedCode(Construct):
    def __init__(self, scope, name):
        super().__init__(scope, name)

        aws.s3_bucket.S3Bucket(self, "bucket",
            logging=aws.s3_bucket.S3BucketLogging(
                target_bucket="target"
            )
        )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant