swagger-angular-generator icon indicating copy to clipboard operation
swagger-angular-generator copied to clipboard

ListField with DictField as child (in django) created invalid TypeScript code

Open Schwankenson opened this issue 4 years ago • 2 comments

ListField with DictField as child created invalid TypeScript code

I have this field in my django response serializer fields:

detailpage_elements = serializers.ListField(
    required=False, 
    child=serializers.DictField()
)

in swagger.json it is shown as

"detailpage_elements":{
    "type":"array",
    "items":{
        "type":"object",
        "additionalProperties":{
            "type":"string"
        }
    }
},

When I generate the api from it, I get this TypeScript code in defs/MyModel.ts

detailpage_elements?: [key: string]: string;[];

which is marked as syntax error.

I changed the child to serializer.JSONField() as workaround, which generates

"detailpage_elements":{
    "type":"array",
    "items":{
        "type":"object"
    }
},

and works

Schwankenson avatar Nov 06 '20 11:11 Schwankenson

Not sure if this is a swagger.json or a swagger-angular-generator issue, to I created another issue at the creators of the drf-yasg creators: https://github.com/axnsan12/drf-yasg/issues/671

Schwankenson avatar Nov 06 '20 11:11 Schwankenson

This is most probably a drf-yasg issue.

@Schwankenson see my reply here: https://github.com/axnsan12/drf-yasg/issues/671#issuecomment-730297991

aarighi avatar Nov 19 '20 11:11 aarighi