swagger-angular-generator
swagger-angular-generator copied to clipboard
ListField with DictField as child (in django) created invalid TypeScript code
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
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
This is most probably a drf-yasg
issue.
@Schwankenson see my reply here: https://github.com/axnsan12/drf-yasg/issues/671#issuecomment-730297991