jnwltr / swagger-angular-generator

Generator of API layer in TypeScript for Angular 2+ apps
MIT License
91 stars 46 forks source link

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

Open Schwankenson opened 3 years ago

Schwankenson commented 3 years ago

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 commented 3 years ago

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

aarighi commented 3 years ago

This is most probably a drf-yasg issue.

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