代码拉取完成,页面将自动刷新
A TypeScript code generator for Django Rest Framework, which saved your hand-working and guaranteed consistency between Python codes and modern frontend codes written in TypeScript.
It generates TypeScript codes from following Python types.
Serializer
, ModelSerializer
derived from Django ORM models, DataclassSerializer
via djangorestframework-dataclasses.dataclasses.dataclass
.enum.Enum
.It also supports nested types and composite types.
Install using pip
.
$ pip install django_rest_tsg
Put a tsgconfig.py
file with build tasks into your django project's root.
from django.conf import settings
from django_rest_tsg.build import build
BUILD_DIR = settings.BASE_DIR / "app/src/core"
BUILD_TASKS = [
build(Foo),
build(BarSerializer, {"alias": "Foobar"}),
]
Add django_rest_tsg
to your INSTALLED_APPS
.
INSTALLED_APPS = [
...
"django_rest_tsg"
]
Run buildtypescript
command on manage.py
.
$ python manage.py buildtypescript
Or you can switch to another place.
$ python manage.py buildtypescript --build-dir /somewhere/you/cannot/explain
Input: Serializer
class PathSerializer(serializers.Serializer):
name = serializers.CharField()
suffix = serializers.CharField()
suffixes = serializers.ListField(child=serializers.CharField())
stem = serializers.CharField()
is_directory = serializers.BooleanField(source="is_dir")
size = serializers.IntegerField(source="stat.st_size")
Output: Interface
export interface Path {
name: string;
suffix: string;
suffixes: string[];
stem: string;
isDirectory: boolean;
size: number;
}
There are more examples in test cases.
All options are listed in the table below.
Name | Context | Value |
---|---|---|
alias | All | str |
build_dir | All |
str | Path
|
enforce_uppercase | Enum |
bool (False) |
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。