aws / jsii

jsii allows code in any language to naturally interact with JavaScript classes. It is the technology that enables the AWS Cloud Development Kit to deliver polyglot libraries from a single codebase!
https://aws.github.io/jsii
Apache License 2.0
2.63k stars 244 forks source link

Inconsistency between examples and what really works #1641

Closed marcosdiez closed 5 months ago

marcosdiez commented 4 years ago

:bug: Bug Report

Affected Languages

General Information

What is the problem?

On the CDK 1.38.0 documentation, the example seems to be right (in snake_case), but what really works is in camelCase.

Here is an example:

https://docs.aws.amazon.com/cdk/api/latest/python/aws_cdk.aws_cloudfront.README.html

the example says:

# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
source_bucket = Bucket(self, "Bucket")

distribution = CloudFrontWebDistribution(self, "MyDistribution",
    origin_configs=[{
        "s3_origin_source": {
            "s3_bucket_source": source_bucket
        },
        "behaviors": [{"is_default_behavior": True}]
    }
    ]
)

but what really works is:

        source_bucket = Bucket(self, "Bucket")
        distribution = cloudfront.CloudFrontWebDistribution(self, name,
            origin_configs=[{
                "s3OriginSource": {
                    "s3BucketSource": source_bucket,
                },
                "behaviors": [{"isDefaultBehavior": True}]
            }
            ]
        )

Since CDK tries to follow pep8 and parameters and methods snake_case, the example is right but the classes themselves are not. Hence I did not fill the bug on https://github.com/aws/jsii/issues/826

Another Example:

source: https://docs.aws.amazon.com/cdk/api/latest/python/aws_cdk.aws_cloudfront/CloudFrontWebDistribution.html

price_class (Optional[PriceClass]) – The price class for the distribution (this impacts how many locations CloudFront uses for your distribution, and billing). Default: PriceClass.PriceClass100 the cheapest option for CloudFront is picked by default.

The valid name is actually PriceClass.PRICE_CLASS_100

RomainMuller commented 4 years ago

Hey!

The problem on CloudFrontWebDistribution's priceClass property actually is in the source documentation. I have submitted aws/aws-cdk#7926 to address that.

The other problems are probably a bug in how the jsii runtime performs case adjustments in this particular case. I'd suppose because the configuration object/dict is nested within an array - possibly this causes the struct transformation not to happen.

So in any case, thank you for reporting this!

github-actions[bot] commented 1 year ago

This issue has not received any attention in 2 years. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

marcosdiez commented 1 year ago

This issue is important

otaviomacedo commented 5 months ago

The documentation is now correct, showing the "structified" Python version, rather than the bare JSON (which is sent unmodified over the wire):

source_bucket = s3.Bucket(self, "Bucket")

distribution = cloudfront.CloudFrontWebDistribution(self, "MyDistribution",
    origin_configs=[cloudfront.SourceConfiguration(
        s3_origin_source=cloudfront.S3OriginConfig(
            s3_bucket_source=source_bucket
        ),
        behaviors=[cloudfront.Behavior(is_default_behavior=True)]
    )
    ]
)
github-actions[bot] commented 5 months ago

This issue is now closed. Comments on closed issues are hard for our team to see. If you need more assistance, please open a new issue that references this one.