OkieOth/yacg

Dictionary of "anonymous struct" is handled incorrectly

Closed this issue · 3 comments

Hi,

I think this schema is not handled correctly:

{
	"$schema": "http://json-schema.org/draft-07/schema#",
	"title": "Demo dict type 4",
	"definitions": {
		"SomeType": {
			"type": "object",
			"properties": {
				"prop_1": {
					"type": "object",
					"additionalProperties": {
						"type": "object",
						"properties": {
							"prop_a": {
								"type": "integer"
							},
							"prop_b": {
								"type": "string"
							}
						}
					}
				}
			}
		}
	}
}

This should generate a class SomeType with one member prop_1, which should be a dictionary. The values of the dict should be "structures" with two members (prop_a and prop_b). But in the generated code there is no structure with members prop_a or prop_b. I've tried this with the pythonBeans, protobuf and plantUml generators.

I think the problem is that in this case modelTypes[1].name is "SomeTypeProp_1", but modelTypes[1].valueType.name is "SomeTypeProp_1" as well.

If I change in _extractComplexType() the innerTypeName creation to innerTypeName = toUpperCamelCase(newTypeName + ' ' + propName + "_inner"), a different type name is generated (SomeTypeProp_1_inner_inner), which then has the prop_a and prop_b members. I don't know if that's a good solution though. At least it breaks some tests which don't expect this ..._inner suffix.

Thank you for the information. It seems that complex inner types for dictionaries are not proper handled. I am going to fix this.

This issue should be fixed with version 6.0.5. @oliver Your investigation was right. Since the error started in the function that extracted the value type of the dictionary, I decided to go with a 'Value' suffix. Thank you for reporting this bug :)

oliver commented

Thanks for the quick solution – the fix works fine!