Skip to content

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

@Schwankenson

Description

@Schwankenson

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions