Repository navigation
cfn generate references incorrect class name #96
Copy link
Copy link
Closed
Description
If I have the following resource specification
{
"typeName": "Richard::Cloud9::Environment",
"description": "An example resource schema demonstrating some basic constructs and validation rules.",
"sourceUrl": "https://github.com/aws-cloudformation/aws-cloudformation-rpdk.git",
"definitions": {
"String": { "type": "string" },
"PolicyStatement": {
"type": "object",
"properties": {
"Effect": {"type": "string"},
"Action": {"type": "array", "items": {"type": "string" }},
"Resource": {"type": "array", "items": {"type": "string" }}
}
},
"PolicyDocument": {
"type": "object",
"properties": {
"Version": {"type": "string"},
"Statement": {
"type": "array",
"items": { "$ref": "#/definitions/PolicyStatement" }
}
}
},
"Cloud9InstancePolicy": {
"$comment": "Policy to apply to Cloud9 Instance",
"type": "object",
"properties": {
"PolicyName": {"type": "string"},
"PolicyDocument": { "$ref": "#/definitions/PolicyDocument" }
}
}
},
"properties": {
"InstanceId": {
"description": "EC2 Instance Id used by the underlying EC2 instance.",
"type": "string",
"pattern": "^i-[a-z0-9]{17}$"
},
"Cloud9InstancePolicy": {
"description": "Inline Policy to provide fine-grained IAM access control to the Cloud9 instance",
"$ref": "#/definitions/Cloud9InstancePolicy"
}
},
"additionalProperties": false,
"required": [],
"readOnlyProperties": [
"/properties/InstanceId"
],
"primaryIdentifier": [
"/properties/InstanceId"
],
"handlers": { ... }
}cfn generate generates the following models.py
...
# work around possible type aliasing issues when variable has same name as a model
_Cloud9InstancePolicy = Cloud9InstancePolicy
@dataclass
class PolicyDocument(BaseModel):
Version: Optional[str]
Statement: Optional[Sequence["_PolicyStatement"]]
@classmethod
def _deserialize(
cls: Type["_PolicyDocument"],
json_data: Optional[Mapping[str, Any]],
) -> Optional["_PolicyDocument"]:
if not json_data:
return None
return cls(
Version=json_data.get("Version"),
##################################################
Statement=deserialize_list(json_data.get("Statement"), Statement), ##### This should be PolicyStatement
##################################################
)
# work around possible type aliasing issues when variable has same name as a model
_PolicyDocument = PolicyDocument
@dataclass
class PolicyStatement(BaseModel):
Effect: Optional[str]
Action: Optional[Sequence[str]]
Resource: Optional[Sequence[str]]
@classmethod
def _deserialize(
cls: Type["_PolicyStatement"],
json_data: Optional[Mapping[str, Any]],
) -> Optional["_PolicyStatement"]:
if not json_data:
return None
return cls(
Effect=json_data.get("Effect"),
Action=json_data.get("Action"),
Resource=json_data.get("Resource"),
)
# work around possible type aliasing issues when variable has same name as a model
_PolicyStatement = PolicyStatement
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Activity